Skip to content

Commit

Permalink
[SLP]Better sorting of cmp instructions by comparing type sizes.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
alexey-bataev authored Aug 6, 2024
1 parent cee594c commit 3c3ea7e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
6 changes: 6 additions & 0 deletions llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18546,6 +18546,12 @@ static bool compareCmp(Value *V, Value *V2, TargetLibraryInfo &TLI,
if (CI1->getOperand(0)->getType()->getTypeID() >
CI2->getOperand(0)->getType()->getTypeID())
return false;
if (CI1->getOperand(0)->getType()->getScalarSizeInBits() <
CI2->getOperand(0)->getType()->getScalarSizeInBits())
return !IsCompatibility;
if (CI1->getOperand(0)->getType()->getScalarSizeInBits() >
CI2->getOperand(0)->getType()->getScalarSizeInBits())
return false;
CmpInst::Predicate Pred1 = CI1->getPredicate();
CmpInst::Predicate Pred2 = CI2->getPredicate();
CmpInst::Predicate SwapPred1 = CmpInst::getSwappedPredicate(Pred1);
Expand Down
11 changes: 3 additions & 8 deletions llvm/test/Transforms/SLPVectorizer/X86/cmp-diff-sized.ll
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,13 @@
define void @test(ptr noalias %a, ptr %b) {
; CHECK-LABEL: @test(
; CHECK-NEXT: [[PA1:%.*]] = getelementptr inbounds i64, ptr [[A:%.*]], i32 64
; CHECK-NEXT: [[PA2:%.*]] = getelementptr inbounds i32, ptr [[A]], i32 1
; CHECK-NEXT: [[A0:%.*]] = load i32, ptr [[A]], align 4
; CHECK-NEXT: [[A1:%.*]] = load i64, ptr [[PA1]], align 8
; CHECK-NEXT: [[A2:%.*]] = load i32, ptr [[PA2]], align 4
; CHECK-NEXT: [[PB1:%.*]] = getelementptr inbounds i64, ptr [[B:%.*]], i32 64
; CHECK-NEXT: [[PB2:%.*]] = getelementptr inbounds i32, ptr [[B]], i32 1
; CHECK-NEXT: [[B0:%.*]] = load i32, ptr [[B]], align 4
; CHECK-NEXT: [[B1:%.*]] = load i64, ptr [[PB1]], align 8
; CHECK-NEXT: [[B2:%.*]] = load i32, ptr [[PB2]], align 4
; CHECK-NEXT: [[C0:%.*]] = icmp eq i32 [[A0]], [[B0]]
; CHECK-NEXT: [[TMP1:%.*]] = load <2 x i32>, ptr [[A]], align 4
; CHECK-NEXT: [[TMP2:%.*]] = load <2 x i32>, ptr [[B]], align 4
; CHECK-NEXT: [[C1:%.*]] = icmp eq i64 [[B1]], [[A1]]
; CHECK-NEXT: [[C2:%.*]] = icmp eq i32 [[B2]], [[A2]]
; CHECK-NEXT: [[TMP3:%.*]] = icmp eq <2 x i32> [[TMP1]], [[TMP2]]
; CHECK-NEXT: ret void
;
%pa1 = getelementptr inbounds i64, ptr %a, i32 64
Expand Down

0 comments on commit 3c3ea7e

Please sign in to comment.