Skip to content

Commit 7a140f4

Browse files
rotaterighttstellar
authored andcommitted
Merging r372886:
------------------------------------------------------------------------ r372886 | spatel | 2019-09-25 08:08:33 -0700 (Wed, 25 Sep 2019) | 7 lines [DAGCombiner] add one-use restriction to vector transform with cheap extract We might be able to do better on the example in the test, but in general, we should not scalarize a splatted vector binop if there are other uses of the binop. Otherwise, we can end up with code as we had - a scalar op that is redundant with a vector op. ------------------------------------------------------------------------
1 parent 07c1422 commit 7a140f4

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18878,7 +18878,7 @@ SDValue DAGCombiner::visitVECTOR_SHUFFLE(SDNode *N) {
1887818878
// build_vector.
1887918879
if (SVN->isSplat() && SVN->getSplatIndex() < (int)NumElts) {
1888018880
int SplatIndex = SVN->getSplatIndex();
18881-
if (TLI.isExtractVecEltCheap(VT, SplatIndex) &&
18881+
if (N0.hasOneUse() && TLI.isExtractVecEltCheap(VT, SplatIndex) &&
1888218882
TLI.isBinOp(N0.getOpcode()) && N0.getNode()->getNumValues() == 1) {
1888318883
// splat (vector_bo L, R), Index -->
1888418884
// splat (scalar_bo (extelt L, Index), (extelt R, Index))

llvm/test/CodeGen/X86/scalarize-fp.ll

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -777,21 +777,18 @@ define <8 x float> @splat0_fdiv_const_op0_v8f32(<8 x float> %vx) {
777777
define <4 x float> @multi_use_binop(<4 x float> %x, <4 x float> %y) {
778778
; SSE-LABEL: multi_use_binop:
779779
; SSE: # %bb.0:
780-
; SSE-NEXT: movaps %xmm0, %xmm2
781-
; SSE-NEXT: mulps %xmm1, %xmm2
782-
; SSE-NEXT: mulss %xmm1, %xmm0
783-
; SSE-NEXT: shufps {{.*#+}} xmm0 = xmm0[0,0,0,0]
784-
; SSE-NEXT: movlhps {{.*#+}} xmm1 = xmm1[0],xmm2[0]
780+
; SSE-NEXT: mulps %xmm1, %xmm0
781+
; SSE-NEXT: movlhps {{.*#+}} xmm1 = xmm1[0],xmm0[0]
782+
; SSE-NEXT: shufps {{.*#+}} xmm0 = xmm0[0,1,2,0]
785783
; SSE-NEXT: addps %xmm1, %xmm0
786784
; SSE-NEXT: retq
787785
;
788786
; AVX-LABEL: multi_use_binop:
789787
; AVX: # %bb.0:
790-
; AVX-NEXT: vmulps %xmm1, %xmm0, %xmm2
791-
; AVX-NEXT: vmulss %xmm1, %xmm0, %xmm0
792-
; AVX-NEXT: vpermilps {{.*#+}} xmm0 = xmm0[0,0,0,0]
793-
; AVX-NEXT: vmovddup {{.*#+}} xmm1 = xmm2[0,0]
794-
; AVX-NEXT: vaddps %xmm1, %xmm0, %xmm0
788+
; AVX-NEXT: vmulps %xmm1, %xmm0, %xmm0
789+
; AVX-NEXT: vpermilps {{.*#+}} xmm1 = xmm0[0,1,2,0]
790+
; AVX-NEXT: vmovddup {{.*#+}} xmm0 = xmm0[0,0]
791+
; AVX-NEXT: vaddps %xmm0, %xmm1, %xmm0
795792
; AVX-NEXT: retq
796793
%mul = fmul <4 x float> %x, %y
797794
%mul0 = shufflevector <4 x float> %mul, <4 x float> undef, <4 x i32> <i32 undef, i32 undef, i32 undef, i32 0>

0 commit comments

Comments
 (0)