diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 3bfea38932f30..d401e7fb657b9 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -19769,8 +19769,10 @@ SDValue DAGCombiner::XformToShuffleWithZero(SDNode *N) { int EltIdx = i / Split; int SubIdx = i % Split; SDValue Elt = RHS.getOperand(EltIdx); + // X & undef --> 0 (not undef). So this lane must be converted to choose + // from the zero constant vector (same as if the element had all 0-bits). if (Elt.isUndef()) { - Indices.push_back(-1); + Indices.push_back(i + NumSubElts); continue; } diff --git a/llvm/test/CodeGen/X86/combine-and.ll b/llvm/test/CodeGen/X86/combine-and.ll index c3a3948737591..462374c4862d5 100644 --- a/llvm/test/CodeGen/X86/combine-and.ll +++ b/llvm/test/CodeGen/X86/combine-and.ll @@ -163,13 +163,13 @@ define <4 x i32> @test14(<4 x i32> %A) { ret <4 x i32> %1 } -; FIXME: X & undef must fold to 0. So lane 0 must choose from the zero vector. +; X & undef must fold to 0. So lane 0 must choose from the zero vector. define <4 x i32> @undef_lane(<4 x i32> %x) { ; CHECK-LABEL: undef_lane: ; CHECK: # %bb.0: ; CHECK-NEXT: xorps %xmm1, %xmm1 -; CHECK-NEXT: blendps {{.*#+}} xmm0 = xmm0[0,1],xmm1[2],xmm0[3] +; CHECK-NEXT: blendps {{.*#+}} xmm0 = xmm1[0],xmm0[1],xmm1[2],xmm0[3] ; CHECK-NEXT: retq %r = and <4 x i32> %x, ret <4 x i32> %r