Skip to content

[SLP]Better sorting of cmp instructions by comparing type sizes. #102132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18536,6 +18536,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
Loading