[llvm] ab3ea27 - [X86][AVX] Reuse existing VBROADCAST(x) for SCALAR_TO_VECTOR(x)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 28 03:38:41 PST 2021
Author: Simon Pilgrim
Date: 2021-02-28T11:37:27Z
New Revision: ab3ea27b6fce6e57301c3e6efc96f80b5eb31ac4
URL: https://github.com/llvm/llvm-project/commit/ab3ea27b6fce6e57301c3e6efc96f80b5eb31ac4
DIFF: https://github.com/llvm/llvm-project/commit/ab3ea27b6fce6e57301c3e6efc96f80b5eb31ac4.diff
LOG: [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.
Added:
Modified:
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/test/CodeGen/X86/combine-bitselect.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index c965b7a10544..86052fad5721 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -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
diff erent 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();
}
diff --git a/llvm/test/CodeGen/X86/combine-bitselect.ll b/llvm/test/CodeGen/X86/combine-bitselect.ll
index 97a2ef2cca4e..d57bd877500c 100644
--- a/llvm/test/CodeGen/X86/combine-bitselect.ll
+++ b/llvm/test/CodeGen/X86/combine-bitselect.ll
@@ -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:
More information about the llvm-commits
mailing list