-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[ValueTracking] Handle assume(trunc x to i1) in knownNonZero #135055
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
@llvm/pr-subscribers-llvm-analysis @llvm/pr-subscribers-llvm-transforms Author: Andreas Jonson (andjo403) ChangesSplit out from #118406 proof: https://alive2.llvm.org/ce/z/zAspzb Full diff: https://github.com/llvm/llvm-project/pull/135055.diff 3 Files Affected:
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index d9c55330f8664..900ada0e37cc4 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -646,11 +646,16 @@ static bool isKnownNonZeroFromAssume(const Value *V, const SimplifyQuery &Q) {
// Warning: This loop can end up being somewhat performance sensitive.
// We're running this loop for once for each value queried resulting in a
// runtime of ~O(#assumes * #values).
+ Value *Arg = I->getArgOperand(0);
+ if (match(Arg, m_TruncOrSelf(m_Specific(V))) &&
+ isValidAssumeForContext(I, Q.CxtI, Q.DT)) {
+ return true;
+ }
Value *RHS;
CmpPredicate Pred;
auto m_V = m_CombineOr(m_Specific(V), m_PtrToInt(m_Specific(V)));
- if (!match(I->getArgOperand(0), m_c_ICmp(Pred, m_V, m_Value(RHS))))
+ if (!match(Arg, m_c_ICmp(Pred, m_V, m_Value(RHS))))
continue;
if (cmpExcludesZero(Pred, RHS) && isValidAssumeForContext(I, Q.CxtI, Q.DT))
diff --git a/llvm/test/Transforms/Attributor/lvi-after-jumpthreading.ll b/llvm/test/Transforms/Attributor/lvi-after-jumpthreading.ll
index 2aa95216a6656..fd9d2e4de61ba 100644
--- a/llvm/test/Transforms/Attributor/lvi-after-jumpthreading.ll
+++ b/llvm/test/Transforms/Attributor/lvi-after-jumpthreading.ll
@@ -130,8 +130,6 @@ exit2:
ret i32 30
}
-; FIXME: We should be able to merge cont into do.
-; FIXME: COND should be replaced with false. This will be fixed by improving LVI.
define i32 @test4(i32 %i, i1 %f, i32 %n) {
; CHECK-LABEL: define {{[^@]+}}@test4
; CHECK-SAME: (i32 [[I:%.*]], i1 [[F:%.*]], i32 [[N:%.*]]) {
@@ -148,8 +146,7 @@ define i32 @test4(i32 %i, i1 %f, i32 %n) {
; CHECK-NEXT: call void @dummy(i1 [[F]]) #[[ATTR2]]
; CHECK-NEXT: [[CONSUME:%.*]] = call i32 @exit()
; CHECK-NEXT: call void @llvm.assume(i1 noundef [[F]])
-; CHECK-NEXT: [[COND:%.*]] = icmp eq i1 [[F]], false
-; CHECK-NEXT: br i1 [[COND]], label [[EXIT]], label [[CONT:%.*]]
+; CHECK-NEXT: br label [[CONT:%.*]]
; CHECK: exit2:
; CHECK-NEXT: ret i32 30
;
diff --git a/llvm/test/Transforms/InstSimplify/assume-non-zero.ll b/llvm/test/Transforms/InstSimplify/assume-non-zero.ll
index 22bdf374487da..331c9504f2da6 100644
--- a/llvm/test/Transforms/InstSimplify/assume-non-zero.ll
+++ b/llvm/test/Transforms/InstSimplify/assume-non-zero.ll
@@ -236,8 +236,7 @@ define i1 @nonnull_trunc_true(i8 %x) {
; CHECK-LABEL: @nonnull_trunc_true(
; CHECK-NEXT: [[A:%.*]] = trunc i8 [[X:%.*]] to i1
; CHECK-NEXT: call void @llvm.assume(i1 [[A]])
-; CHECK-NEXT: [[Q:%.*]] = icmp ne i8 [[X]], 0
-; CHECK-NEXT: ret i1 [[Q]]
+; CHECK-NEXT: ret i1 true
;
%a = trunc i8 %x to i1
call void @llvm.assume(i1 %a)
|
@dtcxzyw I do not understand why the test do not fail for you when the code is removed #118406 (comment) |
They failed because they ran InstSimplify/Attributor. I mean InstCombine can optimize these cases without the change to |
No diff: dtcxzyw/llvm-opt-benchmark#2253 |
thanks for the explanation. |
Split out from #118406
proof: https://alive2.llvm.org/ce/z/zAspzb