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
5 changes: 5 additions & 0 deletions llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,11 @@ Instruction *InstCombinerImpl::visitTrunc(TruncInst &Trunc) {
}
}

if (DestWidth == 1 &&
(Trunc.hasNoUnsignedWrap() || Trunc.hasNoSignedWrap()) &&
isKnownNonZero(Src, SQ.getWithInstruction(&Trunc)))
return replaceInstUsesWith(Trunc, ConstantInt::getTrue(DestTy));

bool Changed = false;
if (!Trunc.hasNoSignedWrap() &&
ComputeMaxSignificantBits(Src, /*Depth=*/0, &Trunc) <= DestWidth) {
Expand Down
6 changes: 2 additions & 4 deletions llvm/test/Transforms/InstCombine/trunc.ll
Original file line number Diff line number Diff line change
Expand Up @@ -1129,8 +1129,7 @@ define i1 @trunc_nuw_i1_non_zero(i8 %1) {
; CHECK-LABEL: @trunc_nuw_i1_non_zero(
; CHECK-NEXT: [[TMP2:%.*]] = icmp ne i8 [[TMP0:%.*]], 0
; CHECK-NEXT: tail call void @llvm.assume(i1 [[TMP2]])
; CHECK-NEXT: [[RET:%.*]] = trunc nuw i8 [[TMP0]] to i1
; CHECK-NEXT: ret i1 [[RET]]
; CHECK-NEXT: ret i1 true
;
%3 = icmp ne i8 %1, 0
tail call void @llvm.assume(i1 %3)
Expand Down Expand Up @@ -1177,8 +1176,7 @@ define i1 @trunc_nsw_i1_non_zero(i8 %1) {
; CHECK-LABEL: @trunc_nsw_i1_non_zero(
; CHECK-NEXT: [[TMP2:%.*]] = icmp ne i8 [[TMP0:%.*]], 0
; CHECK-NEXT: tail call void @llvm.assume(i1 [[TMP2]])
; CHECK-NEXT: [[RET:%.*]] = trunc nsw i8 [[TMP0]] to i1
; CHECK-NEXT: ret i1 [[RET]]
; CHECK-NEXT: ret i1 true
;
%3 = icmp ne i8 %1, 0
tail call void @llvm.assume(i1 %3)
Expand Down
Loading