From 1dcbea8cd57df1d632b3ec73fc99880bdf5c2d05 Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Sat, 16 Mar 2019 17:36:26 +0000 Subject: [PATCH] [DAGCombine] combineShuffleOfScalars - handle non-zero SCALAR_TO_VECTOR indices (PR41097) rL356292 reduces the size of scalar_to_vector if we know the upper bits are undef - which means that shuffles may find they are suddenly referencing scalar_to_vector elements other than zero - so make sure we handle this as undef. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356327 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 4 +- test/CodeGen/X86/oddshuffles.ll | 54 ++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index f6363e271a1..98eb1a1bfe7 100644 --- a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -17596,8 +17596,8 @@ static SDValue combineShuffleOfScalars(ShuffleVectorSDNode *SVN, if (S.getOpcode() == ISD::BUILD_VECTOR) { Op = S.getOperand(Idx); } else if (S.getOpcode() == ISD::SCALAR_TO_VECTOR) { - assert(Idx == 0 && "Unexpected SCALAR_TO_VECTOR operand index."); - Op = S.getOperand(0); + SDValue Op0 = S.getOperand(0); + Op = Idx == 0 ? Op0 : DAG.getUNDEF(Op0.getValueType()); } else { // Operand can't be combined - bail out. return SDValue(); diff --git a/test/CodeGen/X86/oddshuffles.ll b/test/CodeGen/X86/oddshuffles.ll index a4b8f58fcc7..50f7a069f02 100644 --- a/test/CodeGen/X86/oddshuffles.ll +++ b/test/CodeGen/X86/oddshuffles.ll @@ -1767,3 +1767,57 @@ define <2 x double> @wrongorder(<4 x double> %A, <8 x double>* %P) #0 { %m4 = shufflevector <8 x double> %m3, <8 x double> undef, <2 x i32> ret <2 x double> %m4 } + +define void @PR41097() { +; SSE2-LABEL: PR41097: +; SSE2: # %bb.0: +; SSE2-NEXT: movss {{.*#+}} xmm0 = mem[0],zero,zero,zero +; SSE2-NEXT: movzwl (%rax), %eax +; SSE2-NEXT: movd %eax, %xmm1 +; SSE2-NEXT: shufps {{.*#+}} xmm1 = xmm1[0,0],xmm0[2,0] +; SSE2-NEXT: pshuflw {{.*#+}} xmm0 = xmm0[0,1,1,3,4,5,6,7] +; SSE2-NEXT: shufps {{.*#+}} xmm0 = xmm0[0,1],xmm1[0,2] +; SSE2-NEXT: pshuflw {{.*#+}} xmm0 = xmm0[0,2,2,3,4,5,6,7] +; SSE2-NEXT: pshufhw {{.*#+}} xmm0 = xmm0[0,1,2,3,4,6,6,7] +; SSE2-NEXT: pshufd {{.*#+}} xmm0 = xmm0[0,2,2,3] +; SSE2-NEXT: punpcklbw {{.*#+}} xmm0 = xmm0[0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7] +; SSE2-NEXT: pshuflw {{.*#+}} xmm0 = xmm0[0,0,2,3,4,5,6,7] +; SSE2-NEXT: psrad $24, %xmm0 +; SSE2-NEXT: xorps %xmm1, %xmm1 +; SSE2-NEXT: punpckldq {{.*#+}} xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1] +; SSE2-NEXT: movdqu %xmm0, (%rax) +; SSE2-NEXT: retq +; +; SSE42-LABEL: PR41097: +; SSE42: # %bb.0: +; SSE42-NEXT: movd {{.*#+}} xmm0 = mem[0],zero,zero,zero +; SSE42-NEXT: pshufb {{.*#+}} xmm0 = xmm0[0,3,u,u,u,u,u,u,u,u,u,u,u,u,u,u] +; SSE42-NEXT: pmovsxbd %xmm0, %xmm0 +; SSE42-NEXT: pmovzxdq {{.*#+}} xmm0 = xmm0[0],zero,xmm0[1],zero +; SSE42-NEXT: movdqu %xmm0, (%rax) +; SSE42-NEXT: retq +; +; AVX-LABEL: PR41097: +; AVX: # %bb.0: +; AVX-NEXT: vmovd {{.*#+}} xmm0 = mem[0],zero,zero,zero +; AVX-NEXT: vpshufb {{.*#+}} xmm0 = xmm0[0,3,u,u,u,u,u,u,u,u,u,u,u,u,u,u] +; AVX-NEXT: vpmovsxbd %xmm0, %xmm0 +; AVX-NEXT: vpmovzxdq {{.*#+}} xmm0 = xmm0[0],zero,xmm0[1],zero +; AVX-NEXT: vmovdqu %xmm0, (%rax) +; AVX-NEXT: retq +; +; XOP-LABEL: PR41097: +; XOP: # %bb.0: +; XOP-NEXT: vmovd {{.*#+}} xmm0 = mem[0],zero,zero,zero +; XOP-NEXT: vpshufb {{.*#+}} xmm0 = xmm0[0,3,u,u,u,u,u,u,u,u,u,u,u,u,u,u] +; XOP-NEXT: vpmovsxbd %xmm0, %xmm0 +; XOP-NEXT: vpmovzxdq {{.*#+}} xmm0 = xmm0[0],zero,xmm0[1],zero +; XOP-NEXT: vmovdqu %xmm0, (%rax) +; XOP-NEXT: retq + %wide.vec = load <6 x i8>, <6 x i8>* undef, align 1 + %strided.vec = shufflevector <6 x i8> %wide.vec, <6 x i8> undef, <2 x i32> + %tmp = sext <2 x i8> %strided.vec to <2 x i32> + %tmp7 = zext <2 x i32> %tmp to <2 x i64> + store <2 x i64> %tmp7, <2 x i64>* undef, align 8 + ret void +} -- 2.50.1