Skip to content
Merged
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
10 changes: 10 additions & 0 deletions llvm/lib/Analysis/ValueTracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,16 @@ void llvm::computeKnownBitsFromContext(const Value *V, KnownBits &Known,
Known.setAllZero();
return;
}
auto *Trunc = dyn_cast<TruncInst>(Arg);
if (Trunc && Trunc->getOperand(0) == V &&
isValidAssumeForContext(I, Q.CxtI, Q.DT)) {
if (Trunc->hasNoUnsignedWrap()) {
Known = KnownBits::makeConstant(APInt(BitWidth, 1));
return;
}
Known.One.setBit(0);
return;
}

// The remaining tests are all recursive, so bail out if we hit the limit.
if (Depth == MaxAnalysisRecursionDepth)
Expand Down
3 changes: 1 addition & 2 deletions llvm/test/Transforms/InstCombine/assume.ll
Original file line number Diff line number Diff line change
Expand Up @@ -1013,8 +1013,7 @@ define i1 @assume_trunc_nuw_eq_one(i8 %x) {
; CHECK-LABEL: @assume_trunc_nuw_eq_one(
; CHECK-NEXT: [[A:%.*]] = trunc nuw i8 [[X:%.*]] to i1
; CHECK-NEXT: call void @llvm.assume(i1 [[A]])
; CHECK-NEXT: [[Q:%.*]] = icmp eq i8 [[X]], 1
; CHECK-NEXT: ret i1 [[Q]]
; CHECK-NEXT: ret i1 true
;
%a = trunc nuw i8 %x to i1
call void @llvm.assume(i1 %a)
Expand Down
3 changes: 1 addition & 2 deletions llvm/test/Transforms/InstSimplify/shr-nop.ll
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,7 @@ define i8 @exact_lshr_lowbit_set_assume_trunc(i8 %x) {
; CHECK-LABEL: @exact_lshr_lowbit_set_assume_trunc(
; CHECK-NEXT: [[COND:%.*]] = trunc i8 [[X:%.*]] to i1
; CHECK-NEXT: call void @llvm.assume(i1 [[COND]])
; CHECK-NEXT: [[SHR:%.*]] = lshr exact i8 [[X]], 1
; CHECK-NEXT: ret i8 [[SHR]]
; CHECK-NEXT: ret i8 [[X]]
;
%cond = trunc i8 %x to i1
call void @llvm.assume(i1 %cond)
Expand Down