Index: lib/Target/X86/X86ISelLowering.cpp =================================================================== --- lib/Target/X86/X86ISelLowering.cpp +++ lib/Target/X86/X86ISelLowering.cpp @@ -27262,9 +27262,18 @@ if (V) { assert(EltBits == 8 || EltBits == 16 || EltBits == 32); - return DAG.getBitcast( - VT, DAG.getNode(ISD::SUB, DL, MaskVT, - DAG.getNode(ISD::XOR, DL, MaskVT, V, Mask), Mask)); + SDValue SubOp1 = DAG.getNode(ISD::XOR, DL, MaskVT, V, Mask); + SDValue SubOp2 = Mask; + + // If the negate was on the false side of the select, then + // the operands of the SUB need to be swapped. PR 27251. + if (V == Y) { + SubOp2 = SubOp1; + SubOp1 = Mask; + } + + return DAG.getBitcast(VT, + DAG.getNode(ISD::SUB, DL, MaskVT, SubOp1, SubOp2)); } } Index: test/CodeGen/X86/vector-blend.ll =================================================================== --- test/CodeGen/X86/vector-blend.ll +++ test/CodeGen/X86/vector-blend.ll @@ -1010,7 +1010,8 @@ ; SSE2-NEXT: pslld $31, %xmm1 ; SSE2-NEXT: psrad $31, %xmm1 ; SSE2-NEXT: pxor %xmm1, %xmm0 -; SSE2-NEXT: psubd %xmm1, %xmm0 +; SSE2-NEXT: psubd %xmm0, %xmm1 +; SSE2-NEXT: movdqa %xmm1, %xmm0 ; SSE2-NEXT: retq ; ; SSSE3-LABEL: blend_neg_logic_v4i32_2: @@ -1019,7 +1020,8 @@ ; SSSE3-NEXT: pslld $31, %xmm1 ; SSSE3-NEXT: psrad $31, %xmm1 ; SSSE3-NEXT: pxor %xmm1, %xmm0 -; SSSE3-NEXT: psubd %xmm1, %xmm0 +; SSSE3-NEXT: psubd %xmm0, %xmm1 +; SSSE3-NEXT: movdqa %xmm1, %xmm0 ; SSSE3-NEXT: retq ; ; SSE41-LABEL: blend_neg_logic_v4i32_2: