[X86][AVX] Reuse existing VBROADCAST(x) for SCALAR_TO_VECTOR(x)

Similar to what we already do for BROADCASTs of different vector sizes - if we're going to broadcast it anyway might as well reuse it.
This commit is contained in:
Simon Pilgrim 2021-02-28 11:37:27 +00:00
parent 0fe64812d8
commit ab3ea27b6f
2 changed files with 17 additions and 21 deletions

View File

@ -49880,6 +49880,14 @@ static SDValue combineScalarToVector(SDNode *N, SelectionDAG &DAG) {
Src.getOperand(0).getValueType() == MVT::x86mmx)
return DAG.getNode(X86ISD::MOVQ2DQ, DL, VT, Src.getOperand(0));
// See if we're broadcasting the scalar value, in which case just reuse that.
// Ensure the same SDValue from the SDNode use is being used.
// TODO: Handle different vector sizes when we have test coverage.
for (SDNode *User : Src->uses())
if (User->getOpcode() == X86ISD::VBROADCAST && Src == User->getOperand(0) &&
User->getValueSizeInBits(0).getFixedSize() == VT.getFixedSizeInBits())
return SDValue(User, 0);
return SDValue();
}

View File

@ -253,29 +253,17 @@ define <2 x i64> @bitselect_v2i64_broadcast_rrm(<2 x i64> %a0, <2 x i64> %a1, i6
;
; XOP-LABEL: bitselect_v2i64_broadcast_rrm:
; XOP: # %bb.0:
; XOP-NEXT: vmovsd {{.*#+}} xmm2 = mem[0],zero
; XOP-NEXT: vpermilps {{.*#+}} xmm2 = xmm2[0,1,0,1]
; XOP-NEXT: vandps %xmm2, %xmm0, %xmm0
; XOP-NEXT: vandnps %xmm1, %xmm2, %xmm1
; XOP-NEXT: vorps %xmm1, %xmm0, %xmm0
; XOP-NEXT: vmovddup {{.*#+}} xmm2 = mem[0,0]
; XOP-NEXT: vpcmov %xmm2, %xmm1, %xmm0, %xmm0
; XOP-NEXT: retq
;
; AVX1-LABEL: bitselect_v2i64_broadcast_rrm:
; AVX1: # %bb.0:
; AVX1-NEXT: vmovsd {{.*#+}} xmm2 = mem[0],zero
; AVX1-NEXT: vpermilps {{.*#+}} xmm2 = xmm2[0,1,0,1]
; AVX1-NEXT: vandps %xmm2, %xmm0, %xmm0
; AVX1-NEXT: vandnps %xmm1, %xmm2, %xmm1
; AVX1-NEXT: vorps %xmm1, %xmm0, %xmm0
; AVX1-NEXT: retq
;
; AVX2-LABEL: bitselect_v2i64_broadcast_rrm:
; AVX2: # %bb.0:
; AVX2-NEXT: vmovddup {{.*#+}} xmm2 = mem[0,0]
; AVX2-NEXT: vandps %xmm2, %xmm0, %xmm0
; AVX2-NEXT: vandnps %xmm1, %xmm2, %xmm1
; AVX2-NEXT: vorps %xmm1, %xmm0, %xmm0
; AVX2-NEXT: retq
; AVX-LABEL: bitselect_v2i64_broadcast_rrm:
; AVX: # %bb.0:
; AVX-NEXT: vmovddup {{.*#+}} xmm2 = mem[0,0]
; AVX-NEXT: vandps %xmm2, %xmm0, %xmm0
; AVX-NEXT: vandnps %xmm1, %xmm2, %xmm1
; AVX-NEXT: vorps %xmm1, %xmm0, %xmm0
; AVX-NEXT: retq
;
; AVX512F-LABEL: bitselect_v2i64_broadcast_rrm:
; AVX512F: # %bb.0: