File tree Expand file tree Collapse file tree 2 files changed +7
-4
lines changed
lib/Transforms/InstCombine
test/Transforms/InstCombine Expand file tree Collapse file tree 2 files changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -934,6 +934,11 @@ Instruction *InstCombinerImpl::visitTrunc(TruncInst &Trunc) {
934934 }
935935 }
936936
937+ if (DestWidth == 1 &&
938+ (Trunc.hasNoUnsignedWrap () || Trunc.hasNoSignedWrap ()) &&
939+ isKnownNonZero (Src, SQ.getWithInstruction (&Trunc)))
940+ return replaceInstUsesWith (Trunc, ConstantInt::getTrue (DestTy));
941+
937942 bool Changed = false ;
938943 if (!Trunc.hasNoSignedWrap () &&
939944 ComputeMaxSignificantBits (Src, /* Depth=*/ 0 , &Trunc) <= DestWidth) {
Original file line number Diff line number Diff line change @@ -1129,8 +1129,7 @@ define i1 @trunc_nuw_i1_non_zero(i8 %1) {
11291129; CHECK-LABEL: @trunc_nuw_i1_non_zero(
11301130; CHECK-NEXT: [[TMP2:%.*]] = icmp ne i8 [[TMP0:%.*]], 0
11311131; CHECK-NEXT: tail call void @llvm.assume(i1 [[TMP2]])
1132- ; CHECK-NEXT: [[RET:%.*]] = trunc nuw i8 [[TMP0]] to i1
1133- ; CHECK-NEXT: ret i1 [[RET]]
1132+ ; CHECK-NEXT: ret i1 true
11341133;
11351134 %3 = icmp ne i8 %1 , 0
11361135 tail call void @llvm.assume (i1 %3 )
@@ -1177,8 +1176,7 @@ define i1 @trunc_nsw_i1_non_zero(i8 %1) {
11771176; CHECK-LABEL: @trunc_nsw_i1_non_zero(
11781177; CHECK-NEXT: [[TMP2:%.*]] = icmp ne i8 [[TMP0:%.*]], 0
11791178; CHECK-NEXT: tail call void @llvm.assume(i1 [[TMP2]])
1180- ; CHECK-NEXT: [[RET:%.*]] = trunc nsw i8 [[TMP0]] to i1
1181- ; CHECK-NEXT: ret i1 [[RET]]
1179+ ; CHECK-NEXT: ret i1 true
11821180;
11831181 %3 = icmp ne i8 %1 , 0
11841182 tail call void @llvm.assume (i1 %3 )
You can’t perform that action at this time.
0 commit comments