Skip to content

Commit 629bf1c

Browse files
committed
[ValueTracking] Handle assume(trunc x to i1) in knownNonZero
1 parent 8e1b5ac commit 629bf1c

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,11 +612,16 @@ static bool isKnownNonZeroFromAssume(const Value *V, const SimplifyQuery &Q) {
612612
// Warning: This loop can end up being somewhat performance sensitive.
613613
// We're running this loop for once for each value queried resulting in a
614614
// runtime of ~O(#assumes * #values).
615+
Value *Arg = I->getArgOperand(0);
616+
if (match(Arg, m_TruncOrSelf(m_Specific(V))) &&
617+
isValidAssumeForContext(I, Q.CxtI, Q.DT)) {
618+
return true;
619+
}
615620

616621
Value *RHS;
617622
CmpInst::Predicate Pred;
618623
auto m_V = m_CombineOr(m_Specific(V), m_PtrToInt(m_Specific(V)));
619-
if (!match(I->getArgOperand(0), m_c_ICmp(Pred, m_V, m_Value(RHS))))
624+
if (!match(Arg, m_c_ICmp(Pred, m_V, m_Value(RHS))))
620625
continue;
621626

622627
if (cmpExcludesZero(Pred, RHS) && isValidAssumeForContext(I, Q.CxtI, Q.DT))

llvm/test/Transforms/Attributor/lvi-after-jumpthreading.ll

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,6 @@ exit2:
130130
ret i32 30
131131
}
132132

133-
; FIXME: We should be able to merge cont into do.
134-
; FIXME: COND should be replaced with false. This will be fixed by improving LVI.
135133
define i32 @test4(i32 %i, i1 %f, i32 %n) {
136134
; CHECK-LABEL: define {{[^@]+}}@test4
137135
; CHECK-SAME: (i32 [[I:%.*]], i1 [[F:%.*]], i32 [[N:%.*]]) {
@@ -148,8 +146,7 @@ define i32 @test4(i32 %i, i1 %f, i32 %n) {
148146
; CHECK-NEXT: call void @dummy(i1 [[F]]) #[[ATTR2]]
149147
; CHECK-NEXT: [[CONSUME:%.*]] = call i32 @exit()
150148
; CHECK-NEXT: call void @llvm.assume(i1 noundef [[F]])
151-
; CHECK-NEXT: [[COND:%.*]] = icmp eq i1 [[F]], false
152-
; CHECK-NEXT: br i1 [[COND]], label [[EXIT]], label [[CONT:%.*]]
149+
; CHECK-NEXT: br label [[CONT:%.*]]
153150
; CHECK: exit2:
154151
; CHECK-NEXT: ret i32 30
155152
;

llvm/test/Transforms/InstSimplify/assume-non-zero.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,7 @@ define i1 @nonnull_trunc_true(i8 %x) {
236236
; CHECK-LABEL: @nonnull_trunc_true(
237237
; CHECK-NEXT: [[A:%.*]] = trunc i8 [[X:%.*]] to i1
238238
; CHECK-NEXT: call void @llvm.assume(i1 [[A]])
239-
; CHECK-NEXT: [[Q:%.*]] = icmp ne i8 [[X]], 0
240-
; CHECK-NEXT: ret i1 [[Q]]
239+
; CHECK-NEXT: ret i1 true
241240
;
242241
%a = trunc i8 %x to i1
243242
call void @llvm.assume(i1 %a)

0 commit comments

Comments
 (0)