Skip to content

Commit 3c3ea7e

Browse files
[SLP]Better sorting of cmp instructions by comparing type sizes.
Currently SLP vectorizer compares cmp instructions by the type id of the compared operands, which may failed in case of different integer types, for example, which have same type id, but different sizes. Patch adds comparison by type sizes to fix this. Reviewers: RKSimon Reviewed By: RKSimon Pull Request: #102132
1 parent cee594c commit 3c3ea7e

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18546,6 +18546,12 @@ static bool compareCmp(Value *V, Value *V2, TargetLibraryInfo &TLI,
1854618546
if (CI1->getOperand(0)->getType()->getTypeID() >
1854718547
CI2->getOperand(0)->getType()->getTypeID())
1854818548
return false;
18549+
if (CI1->getOperand(0)->getType()->getScalarSizeInBits() <
18550+
CI2->getOperand(0)->getType()->getScalarSizeInBits())
18551+
return !IsCompatibility;
18552+
if (CI1->getOperand(0)->getType()->getScalarSizeInBits() >
18553+
CI2->getOperand(0)->getType()->getScalarSizeInBits())
18554+
return false;
1854918555
CmpInst::Predicate Pred1 = CI1->getPredicate();
1855018556
CmpInst::Predicate Pred2 = CI2->getPredicate();
1855118557
CmpInst::Predicate SwapPred1 = CmpInst::getSwappedPredicate(Pred1);

llvm/test/Transforms/SLPVectorizer/X86/cmp-diff-sized.ll

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,13 @@
44
define void @test(ptr noalias %a, ptr %b) {
55
; CHECK-LABEL: @test(
66
; CHECK-NEXT: [[PA1:%.*]] = getelementptr inbounds i64, ptr [[A:%.*]], i32 64
7-
; CHECK-NEXT: [[PA2:%.*]] = getelementptr inbounds i32, ptr [[A]], i32 1
8-
; CHECK-NEXT: [[A0:%.*]] = load i32, ptr [[A]], align 4
97
; CHECK-NEXT: [[A1:%.*]] = load i64, ptr [[PA1]], align 8
10-
; CHECK-NEXT: [[A2:%.*]] = load i32, ptr [[PA2]], align 4
118
; CHECK-NEXT: [[PB1:%.*]] = getelementptr inbounds i64, ptr [[B:%.*]], i32 64
12-
; CHECK-NEXT: [[PB2:%.*]] = getelementptr inbounds i32, ptr [[B]], i32 1
13-
; CHECK-NEXT: [[B0:%.*]] = load i32, ptr [[B]], align 4
149
; CHECK-NEXT: [[B1:%.*]] = load i64, ptr [[PB1]], align 8
15-
; CHECK-NEXT: [[B2:%.*]] = load i32, ptr [[PB2]], align 4
16-
; CHECK-NEXT: [[C0:%.*]] = icmp eq i32 [[A0]], [[B0]]
10+
; CHECK-NEXT: [[TMP1:%.*]] = load <2 x i32>, ptr [[A]], align 4
11+
; CHECK-NEXT: [[TMP2:%.*]] = load <2 x i32>, ptr [[B]], align 4
1712
; CHECK-NEXT: [[C1:%.*]] = icmp eq i64 [[B1]], [[A1]]
18-
; CHECK-NEXT: [[C2:%.*]] = icmp eq i32 [[B2]], [[A2]]
13+
; CHECK-NEXT: [[TMP3:%.*]] = icmp eq <2 x i32> [[TMP1]], [[TMP2]]
1914
; CHECK-NEXT: ret void
2015
;
2116
%pa1 = getelementptr inbounds i64, ptr %a, i32 64

0 commit comments

Comments
 (0)