Skip to content

Commit 383840b

Browse files
committed
[ValueTracking] Handle assume(trunc x to i1) in knownNonZero
1 parent 1657331 commit 383840b

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
@@ -643,11 +643,16 @@ static bool isKnownNonZeroFromAssume(const Value *V, const SimplifyQuery &Q) {
643643
// Warning: This loop can end up being somewhat performance sensitive.
644644
// We're running this loop for once for each value queried resulting in a
645645
// runtime of ~O(#assumes * #values).
646+
Value *Arg = I->getArgOperand(0);
647+
if (match(Arg, m_TruncOrSelf(m_Specific(V))) &&
648+
isValidAssumeForContext(I, Q.CxtI, Q.DT)) {
649+
return true;
650+
}
646651

647652
Value *RHS;
648653
CmpPredicate Pred;
649654
auto m_V = m_CombineOr(m_Specific(V), m_PtrToInt(m_Specific(V)));
650-
if (!match(I->getArgOperand(0), m_c_ICmp(Pred, m_V, m_Value(RHS))))
655+
if (!match(Arg, m_c_ICmp(Pred, m_V, m_Value(RHS))))
651656
continue;
652657

653658
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)