Skip to content

Commit a32a721

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

File tree

3 files changed

+7
-14
lines changed

3 files changed

+7
-14
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -814,8 +814,6 @@ void llvm::computeKnownBitsFromContext(const Value *V, KnownBits &Known,
814814
if (!Q.AC)
815815
return;
816816

817-
unsigned BitWidth = Known.getBitWidth();
818-
819817
// Note that the patterns below need to be kept in sync with the code
820818
// in AssumptionCache::updateAffectedValues.
821819

@@ -849,17 +847,14 @@ void llvm::computeKnownBitsFromContext(const Value *V, KnownBits &Known,
849847

850848
Value *Arg = I->getArgOperand(0);
851849

852-
if (Arg == V && isValidAssumeForContext(I, Q.CxtI, Q.DT)) {
853-
assert(BitWidth == 1 && "assume operand is not i1?");
854-
(void)BitWidth;
855-
Known.setAllOnes();
850+
if (match(Arg, m_TruncOrSelf(m_Specific(V))) &&
851+
isValidAssumeForContext(I, Q.CxtI, Q.DT)) {
852+
Known.One.setBit(0);
856853
return;
857854
}
858-
if (match(Arg, m_Not(m_Specific(V))) &&
855+
if (match(Arg, m_Not(m_TruncOrSelf(m_Specific(V)))) &&
859856
isValidAssumeForContext(I, Q.CxtI, Q.DT)) {
860-
assert(BitWidth == 1 && "assume operand is not i1?");
861-
(void)BitWidth;
862-
Known.setAllZero();
857+
Known.Zero.setBit(0);
863858
return;
864859
}
865860

llvm/test/Transforms/InstSimplify/compare.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3429,8 +3429,7 @@ define i1 @icmp_eq_false_by_trunc(i8 %x) {
34293429
; CHECK-NEXT: [[TRUNC:%.*]] = trunc i8 [[X:%.*]] to i1
34303430
; CHECK-NEXT: [[NOT:%.*]] = xor i1 [[TRUNC]], true
34313431
; CHECK-NEXT: call void @llvm.assume(i1 [[NOT]])
3432-
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[X]], 1
3433-
; CHECK-NEXT: ret i1 [[CMP]]
3432+
; CHECK-NEXT: ret i1 false
34343433
;
34353434
%trunc = trunc i8 %x to i1
34363435
%not = xor i1 %trunc, true

llvm/test/Transforms/InstSimplify/shr-nop.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,7 @@ define i8 @exact_lshr_lowbit_set_assume_trunc(i8 %x) {
385385
; CHECK-LABEL: @exact_lshr_lowbit_set_assume_trunc(
386386
; CHECK-NEXT: [[COND:%.*]] = trunc i8 [[X:%.*]] to i1
387387
; CHECK-NEXT: call void @llvm.assume(i1 [[COND]])
388-
; CHECK-NEXT: [[SHR:%.*]] = lshr exact i8 [[X]], 1
389-
; CHECK-NEXT: ret i8 [[SHR]]
388+
; CHECK-NEXT: ret i8 [[X]]
390389
;
391390
%cond = trunc i8 %x to i1
392391
call void @llvm.assume(i1 %cond)

0 commit comments

Comments
 (0)