Skip to content

[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

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 6 additions & 1 deletion llvm/lib/Analysis/ValueTracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
5 changes: 1 addition & 4 deletions llvm/test/Transforms/Attributor/lvi-after-jumpthreading.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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:%.*]]) {
Expand All @@ -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
;
Expand Down
3 changes: 1 addition & 2 deletions llvm/test/Transforms/InstSimplify/assume-non-zero.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down