Skip to content

Commit 4f0bd8f

Browse files
committed
[SLP]Fix strict weak ordering for Cmp instruction comparator.
Sorting algorithms require strict weak ordering for comparators, final fix for cmp instructions comparator.
1 parent 989ce06 commit 4f0bd8f

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14697,11 +14697,11 @@ static bool compareCmp(Value *V, Value *V2, TargetLibraryInfo &TLI,
1469714697
if (BasePred1 > BasePred2)
1469814698
return false;
1469914699
// Compare operands.
14700-
bool LEPreds = Pred1 <= Pred2;
14701-
bool GEPreds = Pred1 >= Pred2;
14700+
bool CI1Preds = Pred1 == BasePred1;
14701+
bool CI2Preds = Pred2 == BasePred1;
1470214702
for (int I = 0, E = CI1->getNumOperands(); I < E; ++I) {
14703-
auto *Op1 = CI1->getOperand(LEPreds ? I : E - I - 1);
14704-
auto *Op2 = CI2->getOperand(GEPreds ? I : E - I - 1);
14703+
auto *Op1 = CI1->getOperand(CI1Preds ? I : E - I - 1);
14704+
auto *Op2 = CI2->getOperand(CI2Preds ? I : E - I - 1);
1470514705
if (Op1->getValueID() < Op2->getValueID())
1470614706
return !IsCompatibility;
1470714707
if (Op1->getValueID() > Op2->getValueID())

llvm/test/Transforms/SLPVectorizer/X86/alternate-cmp-swapped-pred-parent.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ define void @test() {
88
; CHECK-NEXT: br label [[BB:%.*]]
99
; CHECK: bb:
1010
; CHECK-NEXT: [[CALL:%.*]] = load i16, ptr poison, align 2
11-
; CHECK-NEXT: [[TMP0:%.*]] = insertelement <8 x i16> <i16 0, i16 0, i16 0, i16 poison, i16 poison, i16 0, i16 poison, i16 poison>, i16 [[CALL37]], i32 3
12-
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <8 x i16> [[TMP0]], i16 [[CALL]], i32 7
13-
; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <8 x i16> [[TMP1]], <8 x i16> poison, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 3, i32 5, i32 3, i32 7>
14-
; CHECK-NEXT: [[TMP3:%.*]] = shufflevector <8 x i16> [[TMP1]], <8 x i16> <i16 0, i16 0, i16 0, i16 0, i16 0, i16 poison, i16 poison, i16 0>, <8 x i32> <i32 8, i32 9, i32 10, i32 11, i32 12, i32 3, i32 7, i32 15>
11+
; CHECK-NEXT: [[TMP0:%.*]] = insertelement <8 x i16> <i16 0, i16 0, i16 0, i16 poison, i16 poison, i16 poison, i16 0, i16 poison>, i16 [[CALL37]], i32 3
12+
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <8 x i16> [[TMP0]], i16 [[CALL]], i32 5
13+
; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <8 x i16> [[TMP1]], <8 x i16> poison, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 3, i32 5, i32 6, i32 3>
14+
; CHECK-NEXT: [[TMP3:%.*]] = shufflevector <8 x i16> [[TMP1]], <8 x i16> <i16 0, i16 0, i16 0, i16 0, i16 0, i16 0, i16 poison, i16 poison>, <8 x i32> <i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 3, i32 5>
1515
; CHECK-NEXT: [[TMP4:%.*]] = icmp slt <8 x i16> [[TMP2]], [[TMP3]]
1616
; CHECK-NEXT: ret void
1717
;

0 commit comments

Comments
 (0)