-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[InstCombine] Handle vec values when constant fold comparisons with constant values with range info. #84673
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
Conversation
…onstant values with range info.
@llvm/pr-subscribers-llvm-transforms @llvm/pr-subscribers-llvm-analysis Author: Andreas Jonson (andjo403) Changesfound that this failed with an assertion when vec was used in this optimization while working on #84627 failed with backtrace
Full diff: https://github.com/llvm/llvm-project/pull/84673.diff 2 Files Affected:
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 201472a3f10c2e..8c48174b9f5257 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -3788,10 +3788,10 @@ static Value *simplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,
*LHS_Instr->getMetadata(LLVMContext::MD_range));
if (LHS_CR.icmp(Pred, RHS_CR))
- return ConstantInt::getTrue(RHS->getContext());
+ return ConstantInt::getTrue(ITy);
if (LHS_CR.icmp(CmpInst::getInversePredicate(Pred), RHS_CR))
- return ConstantInt::getFalse(RHS->getContext());
+ return ConstantInt::getFalse(ITy);
}
}
diff --git a/llvm/test/Transforms/InstCombine/icmp-range.ll b/llvm/test/Transforms/InstCombine/icmp-range.ll
index 7af06e03fd4b2a..77bb5fdb6bfd43 100644
--- a/llvm/test/Transforms/InstCombine/icmp-range.ll
+++ b/llvm/test/Transforms/InstCombine/icmp-range.ll
@@ -171,6 +171,42 @@ define i1 @test_two_ranges3(ptr nocapture readonly %arg1, ptr nocapture readonly
ret i1 %rval
}
+; Values' ranges overlap each other, so it can not be simplified.
+define <2 x i1> @test_two_ranges_vec(ptr nocapture readonly %arg1, ptr nocapture readonly %arg2) {
+; CHECK-LABEL: @test_two_ranges_vec(
+; CHECK-NEXT: [[VAL1:%.*]] = load <2 x i32>, ptr [[ARG1:%.*]], align 8, !range [[RNG4]]
+; CHECK-NEXT: [[VAL2:%.*]] = load <2 x i32>, ptr [[ARG2:%.*]], align 8, !range [[RNG5]]
+; CHECK-NEXT: [[RVAL:%.*]] = icmp ult <2 x i32> [[VAL2]], [[VAL1]]
+; CHECK-NEXT: ret <2 x i1> [[RVAL]]
+;
+ %val1 = load <2 x i32>, ptr %arg1, !range !5
+ %val2 = load <2 x i32>, ptr %arg2, !range !6
+ %rval = icmp ult <2 x i32> %val2, %val1
+ ret <2 x i1> %rval
+}
+
+; Values' ranges do not overlap each other, so it can simplified to false.
+define <2 x i1> @test_two_ranges_vec_true(ptr nocapture readonly %arg1, ptr nocapture readonly %arg2) {
+; CHECK-LABEL: @test_two_ranges_vec_true(
+; CHECK-NEXT: ret <2 x i1> zeroinitializer
+;
+ %val1 = load <2 x i32>, ptr %arg1, !range !0
+ %val2 = load <2 x i32>, ptr %arg2, !range !6
+ %rval = icmp ult <2 x i32> %val2, %val1
+ ret <2 x i1> %rval
+}
+
+; Values' ranges do not overlap each other, so it can simplified to false.
+define <2 x i1> @test_two_ranges_vec_false(ptr nocapture readonly %arg1, ptr nocapture readonly %arg2) {
+; CHECK-LABEL: @test_two_ranges_vec_false(
+; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
+;
+ %val1 = load <2 x i32>, ptr %arg1, !range !0
+ %val2 = load <2 x i32>, ptr %arg2, !range !6
+ %rval = icmp ugt <2 x i32> %val2, %val1
+ ret <2 x i1> %rval
+}
+
define i1 @ugt_zext(i1 %b, i8 %x) {
; CHECK-LABEL: @ugt_zext(
; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i8 [[X:%.*]], 0
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
found that this failed with an assertion when vec was used in this optimization while working on #84627
failed with backtrace