[llvm] [CVP] Flip signedness icmp predicate in use level (PR #69948)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 23 10:34:56 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: XChy (XChy)
<details>
<summary>Changes</summary>
Resolve #<!-- -->69928.
[Alive2 Proof](https://alive2.llvm.org/ce/z/zoqaqf).
---
Full diff: https://github.com/llvm/llvm-project/pull/69948.diff
2 Files Affected:
- (modified) llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp (+3-2)
- (modified) llvm/test/Transforms/CorrelatedValuePropagation/icmp.ll (+75)
``````````diff
diff --git a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
index 523196e5e6eab71..9043c434313fedc 100644
--- a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
+++ b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
@@ -294,8 +294,9 @@ static bool processICmp(ICmpInst *Cmp, LazyValueInfo *LVI) {
ICmpInst::Predicate UnsignedPred =
ConstantRange::getEquivalentPredWithFlippedSignedness(
- Cmp->getPredicate(), LVI->getConstantRange(Cmp->getOperand(0), Cmp),
- LVI->getConstantRange(Cmp->getOperand(1), Cmp));
+ Cmp->getPredicate(),
+ LVI->getConstantRangeAtUse(Cmp->getOperandUse(0)),
+ LVI->getConstantRangeAtUse(Cmp->getOperandUse(1)));
if (UnsignedPred == ICmpInst::Predicate::BAD_ICMP_PREDICATE)
return false;
diff --git a/llvm/test/Transforms/CorrelatedValuePropagation/icmp.ll b/llvm/test/Transforms/CorrelatedValuePropagation/icmp.ll
index c4f0ade39942a76..24acd528e6dcde5 100644
--- a/llvm/test/Transforms/CorrelatedValuePropagation/icmp.ll
+++ b/llvm/test/Transforms/CorrelatedValuePropagation/icmp.ll
@@ -1246,3 +1246,78 @@ declare <2 x i8> @llvm.umin.v2i8(<2 x i8>, <2 x i8>)
declare <2 x i8> @llvm.umax.v2i8(<2 x i8>, <2 x i8>)
attributes #4 = { noreturn }
+
+define i64 @test_select_flip(i64 noundef %arg) {
+; CHECK-LABEL: @test_select_flip(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP1:%.*]] = icmp ult i64 [[ARG:%.*]], 1000
+; CHECK-NEXT: [[CMP2:%.*]] = icmp ult i64 [[ARG]], 100
+; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP1]], i1 [[CMP2]], i1 false
+; CHECK-NEXT: br i1 [[SELECT]], label [[GOOD:%.*]], label [[BAD:%.*]]
+; CHECK: bad:
+; CHECK-NEXT: ret i64 1
+; CHECK: good:
+; CHECK-NEXT: ret i64 0
+;
+entry:
+ %cmp1 = icmp ult i64 %arg, 1000
+ %cmp2 = icmp slt i64 %arg, 100
+ %select = select i1 %cmp1, i1 %cmp2, i1 false
+ br i1 %select, label %good, label %bad
+
+bad:
+ ret i64 1
+
+good:
+ ret i64 0
+}
+
+define i64 @test_select_flip_fail1(i64 noundef %arg) {
+; CHECK-LABEL: @test_select_flip_fail1(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i64 [[ARG:%.*]], 1000
+; CHECK-NEXT: [[CMP2:%.*]] = icmp slt i64 [[ARG]], 100
+; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP1]], i1 [[CMP2]], i1 false
+; CHECK-NEXT: br i1 [[SELECT]], label [[GOOD:%.*]], label [[BAD:%.*]]
+; CHECK: bad:
+; CHECK-NEXT: ret i64 1
+; CHECK: good:
+; CHECK-NEXT: ret i64 0
+;
+entry:
+ %cmp1 = icmp slt i64 %arg, 1000
+ %cmp2 = icmp slt i64 %arg, 100
+ %select = select i1 %cmp1, i1 %cmp2, i1 false
+ br i1 %select, label %good, label %bad
+
+bad:
+ ret i64 1
+
+good:
+ ret i64 0
+}
+
+define i64 @test_select_flip_fail2(i64 noundef %arg) {
+; CHECK-LABEL: @test_select_flip_fail2(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP1:%.*]] = icmp ult i64 [[ARG:%.*]], 1000
+; CHECK-NEXT: [[CMP2:%.*]] = icmp slt i64 [[ARG]], 100
+; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP1]], i1 false, i1 [[CMP2]]
+; CHECK-NEXT: br i1 [[SELECT]], label [[GOOD:%.*]], label [[BAD:%.*]]
+; CHECK: bad:
+; CHECK-NEXT: ret i64 1
+; CHECK: good:
+; CHECK-NEXT: ret i64 0
+;
+entry:
+ %cmp1 = icmp ult i64 %arg, 1000
+ %cmp2 = icmp slt i64 %arg, 100
+ %select = select i1 %cmp1, i1 false, i1 %cmp2
+ br i1 %select, label %good, label %bad
+
+bad:
+ ret i64 1
+
+good:
+ ret i64 0
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/69948
More information about the llvm-commits
mailing list