[llvm] 3c3ea7e - [SLP]Better sorting of cmp instructions by comparing type sizes.
via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 6 08:03:40 PDT 2024
Author: Alexey Bataev
Date: 2024-08-06T11:03:36-04:00
New Revision: 3c3ea7e751bc18cc8598955bcd853d3c34ffee2d
URL: https://github.com/llvm/llvm-project/commit/3c3ea7e751bc18cc8598955bcd853d3c34ffee2d
DIFF: https://github.com/llvm/llvm-project/commit/3c3ea7e751bc18cc8598955bcd853d3c34ffee2d.diff
LOG: [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: https://github.com/llvm/llvm-project/pull/102132
Added:
Modified:
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
llvm/test/Transforms/SLPVectorizer/X86/cmp-diff-sized.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 936b074abbd69..9589d306581e6 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -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);
diff --git a/llvm/test/Transforms/SLPVectorizer/X86/cmp-
diff -sized.ll b/llvm/test/Transforms/SLPVectorizer/X86/cmp-
diff -sized.ll
index b8b2aa3ad91be..c8bd106e25ad4 100644
--- a/llvm/test/Transforms/SLPVectorizer/X86/cmp-
diff -sized.ll
+++ b/llvm/test/Transforms/SLPVectorizer/X86/cmp-
diff -sized.ll
@@ -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
More information about the llvm-commits
mailing list