Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit d393432

Browse files
committed
[X86]: Fix for PR27251.
Differential Revision: http://reviews.llvm.org/D18850 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@265690 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 05fbbee commit d393432

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

lib/Target/X86/X86ISelLowering.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27338,9 +27338,24 @@ static SDValue combineLogicBlendIntoPBLENDV(SDNode *N, SelectionDAG &DAG,
2733827338

2733927339
if (V) {
2734027340
assert(EltBits == 8 || EltBits == 16 || EltBits == 32);
27341-
return DAG.getBitcast(
27342-
VT, DAG.getNode(ISD::SUB, DL, MaskVT,
27343-
DAG.getNode(ISD::XOR, DL, MaskVT, V, Mask), Mask));
27341+
SDValue SubOp1 = DAG.getNode(ISD::XOR, DL, MaskVT, V, Mask);
27342+
SDValue SubOp2 = Mask;
27343+
27344+
// If the negate was on the false side of the select, then
27345+
// the operands of the SUB need to be swapped. PR 27251.
27346+
// This is because the pattern being matched above is
27347+
// (vselect M, (sub (0, X), X) -> (sub (xor X, M), M)
27348+
// but if the pattern matched was
27349+
// (vselect M, X, (sub (0, X))), that is really negation of the pattern
27350+
// above, -(vselect M, (sub 0, X), X), and therefore the replacement
27351+
// pattern also needs to be a negation of the replacement pattern above.
27352+
// And -(sub X, Y) is just sub (Y, X), so swapping the operands of the
27353+
// sub accomplishes the negation of the replacement pattern.
27354+
if (V == Y)
27355+
std::swap(SubOp1, SubOp2);
27356+
27357+
return DAG.getBitcast(VT,
27358+
DAG.getNode(ISD::SUB, DL, MaskVT, SubOp1, SubOp2));
2734427359
}
2734527360
}
2734627361

test/CodeGen/X86/vector-blend.ll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,8 @@ define <4 x i32> @blend_neg_logic_v4i32_2(<4 x i32> %v, <4 x i32> %c) {
10101010
; SSE2-NEXT: pslld $31, %xmm1
10111011
; SSE2-NEXT: psrad $31, %xmm1
10121012
; SSE2-NEXT: pxor %xmm1, %xmm0
1013-
; SSE2-NEXT: psubd %xmm1, %xmm0
1013+
; SSE2-NEXT: psubd %xmm0, %xmm1
1014+
; SSE2-NEXT: movdqa %xmm1, %xmm0
10141015
; SSE2-NEXT: retq
10151016
;
10161017
; SSSE3-LABEL: blend_neg_logic_v4i32_2:
@@ -1019,7 +1020,8 @@ define <4 x i32> @blend_neg_logic_v4i32_2(<4 x i32> %v, <4 x i32> %c) {
10191020
; SSSE3-NEXT: pslld $31, %xmm1
10201021
; SSSE3-NEXT: psrad $31, %xmm1
10211022
; SSSE3-NEXT: pxor %xmm1, %xmm0
1022-
; SSSE3-NEXT: psubd %xmm1, %xmm0
1023+
; SSSE3-NEXT: psubd %xmm0, %xmm1
1024+
; SSSE3-NEXT: movdqa %xmm1, %xmm0
10231025
; SSSE3-NEXT: retq
10241026
;
10251027
; SSE41-LABEL: blend_neg_logic_v4i32_2:

0 commit comments

Comments
 (0)