Skip to content

Commit f4c5ea8

Browse files
committed
[InstCombine] Infer nsw/nuw for trunc
1 parent 869797d commit f4c5ea8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+303
-290
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,20 @@ Instruction *InstCombinerImpl::visitTrunc(TruncInst &Trunc) {
897897
}
898898
}
899899

900-
return nullptr;
900+
bool Changed = false;
901+
if (!Trunc.hasNoSignedWrap() &&
902+
ComputeMaxSignificantBits(Src, /*Depth=*/0, &Trunc) <= DestWidth) {
903+
Trunc.setHasNoSignedWrap(true);
904+
Changed = true;
905+
}
906+
if (!Trunc.hasNoUnsignedWrap() &&
907+
MaskedValueIsZero(Src, APInt::getBitsSetFrom(SrcWidth, DestWidth),
908+
/*Depth=*/0, &Trunc)) {
909+
Trunc.setHasNoUnsignedWrap(true);
910+
Changed = true;
911+
}
912+
913+
return Changed ? &Trunc : nullptr;
901914
}
902915

903916
Instruction *InstCombinerImpl::transformZExtICmp(ICmpInst *Cmp,

llvm/test/Transforms/InstCombine/RISCV/riscv-vsetvli-knownbits.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ entry:
4545
define signext i32 @vsetvl_sext() nounwind #0 {
4646
; CHECK-LABEL: @vsetvl_sext(
4747
; CHECK-NEXT: [[A:%.*]] = call i64 @llvm.riscv.vsetvli.i64(i64 1, i64 1, i64 1)
48-
; CHECK-NEXT: [[B:%.*]] = trunc i64 [[A]] to i32
48+
; CHECK-NEXT: [[B:%.*]] = trunc nuw nsw i64 [[A]] to i32
4949
; CHECK-NEXT: ret i32 [[B]]
5050
;
5151
%a = call i64 @llvm.riscv.vsetvli(i64 1, i64 1, i64 1)
@@ -56,7 +56,7 @@ define signext i32 @vsetvl_sext() nounwind #0 {
5656
define zeroext i32 @vsetvl_zext() nounwind #0 {
5757
; CHECK-LABEL: @vsetvl_zext(
5858
; CHECK-NEXT: [[A:%.*]] = call i64 @llvm.riscv.vsetvli.i64(i64 1, i64 1, i64 1)
59-
; CHECK-NEXT: [[B:%.*]] = trunc i64 [[A]] to i32
59+
; CHECK-NEXT: [[B:%.*]] = trunc nuw nsw i64 [[A]] to i32
6060
; CHECK-NEXT: ret i32 [[B]]
6161
;
6262
%a = call i64 @llvm.riscv.vsetvli(i64 1, i64 1, i64 1)

llvm/test/Transforms/InstCombine/RISCV/riscv-vsetvlimax-knownbits.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ entry:
4545
define signext i32 @vsetvlmax_sext() nounwind #0 {
4646
; CHECK-LABEL: @vsetvlmax_sext(
4747
; CHECK-NEXT: [[A:%.*]] = call i64 @llvm.riscv.vsetvlimax.i64(i64 1, i64 1)
48-
; CHECK-NEXT: [[B:%.*]] = trunc i64 [[A]] to i32
48+
; CHECK-NEXT: [[B:%.*]] = trunc nuw nsw i64 [[A]] to i32
4949
; CHECK-NEXT: ret i32 [[B]]
5050
;
5151
%a = call i64 @llvm.riscv.vsetvlimax(i64 1, i64 1)
@@ -56,7 +56,7 @@ define signext i32 @vsetvlmax_sext() nounwind #0 {
5656
define zeroext i32 @vsetvlmax_zext() nounwind #0 {
5757
; CHECK-LABEL: @vsetvlmax_zext(
5858
; CHECK-NEXT: [[A:%.*]] = call i64 @llvm.riscv.vsetvlimax.i64(i64 1, i64 1)
59-
; CHECK-NEXT: [[B:%.*]] = trunc i64 [[A]] to i32
59+
; CHECK-NEXT: [[B:%.*]] = trunc nuw nsw i64 [[A]] to i32
6060
; CHECK-NEXT: ret i32 [[B]]
6161
;
6262
%a = call i64 @llvm.riscv.vsetvlimax(i64 1, i64 1)

llvm/test/Transforms/InstCombine/add.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2375,7 +2375,7 @@ define { i64, i64 } @PR57576(i64 noundef %x, i64 noundef %y, i64 noundef %z, i64
23752375
; CHECK-NEXT: [[SUB:%.*]] = sub i128 [[XY]], [[ZZ]]
23762376
; CHECK-NEXT: [[T:%.*]] = trunc i128 [[SUB]] to i64
23772377
; CHECK-NEXT: [[TMP1:%.*]] = lshr i128 [[SUB]], 64
2378-
; CHECK-NEXT: [[DOTTR:%.*]] = trunc i128 [[TMP1]] to i64
2378+
; CHECK-NEXT: [[DOTTR:%.*]] = trunc nuw i128 [[TMP1]] to i64
23792379
; CHECK-NEXT: [[DOTNARROW:%.*]] = sub i64 [[DOTTR]], [[W:%.*]]
23802380
; CHECK-NEXT: [[R1:%.*]] = insertvalue { i64, i64 } poison, i64 [[T]], 0
23812381
; CHECK-NEXT: [[R2:%.*]] = insertvalue { i64, i64 } [[R1]], i64 [[DOTNARROW]], 1

llvm/test/Transforms/InstCombine/binop-itofp.ll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ define float @test_ui_add_with_signed_constant(i32 %shr.i) {
10101010
define float @missed_nonzero_check_on_constant_for_si_fmul(i1 %c, i1 %.b, ptr %g_2345) {
10111011
; CHECK-LABEL: @missed_nonzero_check_on_constant_for_si_fmul(
10121012
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[C:%.*]], i32 65529, i32 53264
1013-
; CHECK-NEXT: [[CONV_I:%.*]] = trunc i32 [[SEL]] to i16
1013+
; CHECK-NEXT: [[CONV_I:%.*]] = trunc nuw i32 [[SEL]] to i16
10141014
; CHECK-NEXT: [[CONV1_I:%.*]] = sitofp i16 [[CONV_I]] to float
10151015
; CHECK-NEXT: [[MUL3_I_I:%.*]] = call float @llvm.copysign.f32(float 0.000000e+00, float [[CONV1_I]])
10161016
; CHECK-NEXT: store i32 [[SEL]], ptr [[G_2345:%.*]], align 4
@@ -1027,7 +1027,7 @@ define float @missed_nonzero_check_on_constant_for_si_fmul(i1 %c, i1 %.b, ptr %g
10271027
define <2 x float> @missed_nonzero_check_on_constant_for_si_fmul_vec(i1 %c, i1 %.b, ptr %g_2345) {
10281028
; CHECK-LABEL: @missed_nonzero_check_on_constant_for_si_fmul_vec(
10291029
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[C:%.*]], i32 65529, i32 53264
1030-
; CHECK-NEXT: [[CONV_I_S:%.*]] = trunc i32 [[SEL]] to i16
1030+
; CHECK-NEXT: [[CONV_I_S:%.*]] = trunc nuw i32 [[SEL]] to i16
10311031
; CHECK-NEXT: [[CONV_I_V:%.*]] = insertelement <2 x i16> poison, i16 [[CONV_I_S]], i64 0
10321032
; CHECK-NEXT: [[CONV_I:%.*]] = shufflevector <2 x i16> [[CONV_I_V]], <2 x i16> poison, <2 x i32> zeroinitializer
10331033
; CHECK-NEXT: [[CONV1_I:%.*]] = sitofp <2 x i16> [[CONV_I]] to <2 x float>
@@ -1048,7 +1048,7 @@ define <2 x float> @missed_nonzero_check_on_constant_for_si_fmul_vec(i1 %c, i1 %
10481048
define float @negzero_check_on_constant_for_si_fmul(i1 %c, i1 %.b, ptr %g_2345) {
10491049
; CHECK-LABEL: @negzero_check_on_constant_for_si_fmul(
10501050
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[C:%.*]], i32 65529, i32 53264
1051-
; CHECK-NEXT: [[CONV_I:%.*]] = trunc i32 [[SEL]] to i16
1051+
; CHECK-NEXT: [[CONV_I:%.*]] = trunc nuw i32 [[SEL]] to i16
10521052
; CHECK-NEXT: [[CONV1_I:%.*]] = sitofp i16 [[CONV_I]] to float
10531053
; CHECK-NEXT: [[TMP1:%.*]] = fneg float [[CONV1_I]]
10541054
; CHECK-NEXT: [[MUL3_I_I:%.*]] = call float @llvm.copysign.f32(float 0.000000e+00, float [[TMP1]])
@@ -1066,7 +1066,7 @@ define float @negzero_check_on_constant_for_si_fmul(i1 %c, i1 %.b, ptr %g_2345)
10661066
define <2 x float> @nonzero_check_on_constant_for_si_fmul_vec_w_undef(i1 %c, i1 %.b, ptr %g_2345) {
10671067
; CHECK-LABEL: @nonzero_check_on_constant_for_si_fmul_vec_w_undef(
10681068
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[C:%.*]], i32 65529, i32 53264
1069-
; CHECK-NEXT: [[CONV_I_S:%.*]] = trunc i32 [[SEL]] to i16
1069+
; CHECK-NEXT: [[CONV_I_S:%.*]] = trunc nuw i32 [[SEL]] to i16
10701070
; CHECK-NEXT: [[CONV_I_V:%.*]] = insertelement <2 x i16> poison, i16 [[CONV_I_S]], i64 0
10711071
; CHECK-NEXT: [[CONV_I:%.*]] = shufflevector <2 x i16> [[CONV_I_V]], <2 x i16> poison, <2 x i32> zeroinitializer
10721072
; CHECK-NEXT: [[CONV1_I:%.*]] = sitofp <2 x i16> [[CONV_I]] to <2 x float>
@@ -1087,7 +1087,7 @@ define <2 x float> @nonzero_check_on_constant_for_si_fmul_vec_w_undef(i1 %c, i1
10871087
define <2 x float> @nonzero_check_on_constant_for_si_fmul_nz_vec_w_undef(i1 %c, i1 %.b, ptr %g_2345) {
10881088
; CHECK-LABEL: @nonzero_check_on_constant_for_si_fmul_nz_vec_w_undef(
10891089
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[C:%.*]], i32 65529, i32 53264
1090-
; CHECK-NEXT: [[CONV_I_S:%.*]] = trunc i32 [[SEL]] to i16
1090+
; CHECK-NEXT: [[CONV_I_S:%.*]] = trunc nuw i32 [[SEL]] to i16
10911091
; CHECK-NEXT: [[CONV_I_V:%.*]] = insertelement <2 x i16> poison, i16 [[CONV_I_S]], i64 0
10921092
; CHECK-NEXT: [[CONV_I:%.*]] = shufflevector <2 x i16> [[CONV_I_V]], <2 x i16> poison, <2 x i32> zeroinitializer
10931093
; CHECK-NEXT: [[CONV1_I:%.*]] = sitofp <2 x i16> [[CONV_I]] to <2 x float>
@@ -1108,7 +1108,7 @@ define <2 x float> @nonzero_check_on_constant_for_si_fmul_nz_vec_w_undef(i1 %c,
11081108
define <2 x float> @nonzero_check_on_constant_for_si_fmul_negz_vec_w_undef(i1 %c, i1 %.b, ptr %g_2345) {
11091109
; CHECK-LABEL: @nonzero_check_on_constant_for_si_fmul_negz_vec_w_undef(
11101110
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[C:%.*]], i32 65529, i32 53264
1111-
; CHECK-NEXT: [[CONV_I_S:%.*]] = trunc i32 [[SEL]] to i16
1111+
; CHECK-NEXT: [[CONV_I_S:%.*]] = trunc nuw i32 [[SEL]] to i16
11121112
; CHECK-NEXT: [[CONV_I_V:%.*]] = insertelement <2 x i16> poison, i16 [[CONV_I_S]], i64 0
11131113
; CHECK-NEXT: [[CONV_I:%.*]] = shufflevector <2 x i16> [[CONV_I_V]], <2 x i16> poison, <2 x i32> zeroinitializer
11141114
; CHECK-NEXT: [[CONV1_I:%.*]] = sitofp <2 x i16> [[CONV_I]] to <2 x float>

llvm/test/Transforms/InstCombine/bswap-fold.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ define i64 @variable_shl_not_masked_enough_i64(i64 %x, i64 %n) {
211211
define i16 @test7(i32 %A) {
212212
; CHECK-LABEL: @test7(
213213
; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[A:%.*]], 16
214-
; CHECK-NEXT: [[D:%.*]] = trunc i32 [[TMP1]] to i16
214+
; CHECK-NEXT: [[D:%.*]] = trunc nuw i32 [[TMP1]] to i16
215215
; CHECK-NEXT: ret i16 [[D]]
216216
;
217217
%B = tail call i32 @llvm.bswap.i32(i32 %A) nounwind
@@ -223,7 +223,7 @@ define i16 @test7(i32 %A) {
223223
define <2 x i16> @test7_vector(<2 x i32> %A) {
224224
; CHECK-LABEL: @test7_vector(
225225
; CHECK-NEXT: [[TMP1:%.*]] = lshr <2 x i32> [[A:%.*]], <i32 16, i32 16>
226-
; CHECK-NEXT: [[D:%.*]] = trunc <2 x i32> [[TMP1]] to <2 x i16>
226+
; CHECK-NEXT: [[D:%.*]] = trunc nuw <2 x i32> [[TMP1]] to <2 x i16>
227227
; CHECK-NEXT: ret <2 x i16> [[D]]
228228
;
229229
%B = tail call <2 x i32> @llvm.bswap.v2i32(<2 x i32> %A) nounwind
@@ -235,7 +235,7 @@ define <2 x i16> @test7_vector(<2 x i32> %A) {
235235
define i16 @test8(i64 %A) {
236236
; CHECK-LABEL: @test8(
237237
; CHECK-NEXT: [[TMP1:%.*]] = lshr i64 [[A:%.*]], 48
238-
; CHECK-NEXT: [[D:%.*]] = trunc i64 [[TMP1]] to i16
238+
; CHECK-NEXT: [[D:%.*]] = trunc nuw i64 [[TMP1]] to i16
239239
; CHECK-NEXT: ret i16 [[D]]
240240
;
241241
%B = tail call i64 @llvm.bswap.i64(i64 %A) nounwind
@@ -247,7 +247,7 @@ define i16 @test8(i64 %A) {
247247
define <2 x i16> @test8_vector(<2 x i64> %A) {
248248
; CHECK-LABEL: @test8_vector(
249249
; CHECK-NEXT: [[TMP1:%.*]] = lshr <2 x i64> [[A:%.*]], <i64 48, i64 48>
250-
; CHECK-NEXT: [[D:%.*]] = trunc <2 x i64> [[TMP1]] to <2 x i16>
250+
; CHECK-NEXT: [[D:%.*]] = trunc nuw <2 x i64> [[TMP1]] to <2 x i16>
251251
; CHECK-NEXT: ret <2 x i16> [[D]]
252252
;
253253
%B = tail call <2 x i64> @llvm.bswap.v2i64(<2 x i64> %A) nounwind

llvm/test/Transforms/InstCombine/bswap.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ define i16 @test1_trunc(i32 %i) {
4343
; CHECK-NEXT: [[T3:%.*]] = lshr i32 [[I]], 8
4444
; CHECK-NEXT: [[T4:%.*]] = and i32 [[T3]], 65280
4545
; CHECK-NEXT: [[T5:%.*]] = or disjoint i32 [[T1]], [[T4]]
46-
; CHECK-NEXT: [[T13:%.*]] = trunc i32 [[T5]] to i16
46+
; CHECK-NEXT: [[T13:%.*]] = trunc nuw i32 [[T5]] to i16
4747
; CHECK-NEXT: ret i16 [[T13]]
4848
;
4949
%t1 = lshr i32 %i, 24
@@ -61,7 +61,7 @@ define i16 @test1_trunc_extra_use(i32 %i) {
6161
; CHECK-NEXT: [[T4:%.*]] = and i32 [[T3]], 65280
6262
; CHECK-NEXT: [[T5:%.*]] = or disjoint i32 [[T1]], [[T4]]
6363
; CHECK-NEXT: call void @extra_use(i32 [[T5]])
64-
; CHECK-NEXT: [[T13:%.*]] = trunc i32 [[T5]] to i16
64+
; CHECK-NEXT: [[T13:%.*]] = trunc nuw i32 [[T5]] to i16
6565
; CHECK-NEXT: ret i16 [[T13]]
6666
;
6767
%t1 = lshr i32 %i, 24

llvm/test/Transforms/InstCombine/cast.ll

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,7 +1471,7 @@ define i64 @test91(i64 %A) {
14711471
; ALL-LABEL: @test91(
14721472
; ALL-NEXT: [[B:%.*]] = sext i64 [[A:%.*]] to i96
14731473
; ALL-NEXT: [[C:%.*]] = lshr i96 [[B]], 48
1474-
; ALL-NEXT: [[D:%.*]] = trunc i96 [[C]] to i64
1474+
; ALL-NEXT: [[D:%.*]] = trunc nuw nsw i96 [[C]] to i64
14751475
; ALL-NEXT: ret i64 [[D]]
14761476
;
14771477
%B = sext i64 %A to i96
@@ -1676,7 +1676,7 @@ define i8 @trunc_lshr_overshift_sext_uses3(i8 %A) {
16761676
define i8 @trunc_lshr_sext_wide_input(i16 %A) {
16771677
; ALL-LABEL: @trunc_lshr_sext_wide_input(
16781678
; ALL-NEXT: [[TMP1:%.*]] = ashr i16 [[A:%.*]], 9
1679-
; ALL-NEXT: [[D:%.*]] = trunc i16 [[TMP1]] to i8
1679+
; ALL-NEXT: [[D:%.*]] = trunc nsw i16 [[TMP1]] to i8
16801680
; ALL-NEXT: ret i8 [[D]]
16811681
;
16821682
%B = sext i16 %A to i32
@@ -1688,7 +1688,7 @@ define i8 @trunc_lshr_sext_wide_input(i16 %A) {
16881688
define i8 @trunc_lshr_sext_wide_input_exact(i16 %A) {
16891689
; ALL-LABEL: @trunc_lshr_sext_wide_input_exact(
16901690
; ALL-NEXT: [[TMP1:%.*]] = ashr exact i16 [[A:%.*]], 9
1691-
; ALL-NEXT: [[D:%.*]] = trunc i16 [[TMP1]] to i8
1691+
; ALL-NEXT: [[D:%.*]] = trunc nsw i16 [[TMP1]] to i8
16921692
; ALL-NEXT: ret i8 [[D]]
16931693
;
16941694
%B = sext i16 %A to i32
@@ -1702,7 +1702,7 @@ define <2 x i8> @trunc_lshr_sext_wide_input_uses1(<2 x i16> %A) {
17021702
; ALL-NEXT: [[B:%.*]] = sext <2 x i16> [[A:%.*]] to <2 x i32>
17031703
; ALL-NEXT: call void @use_v2i32(<2 x i32> [[B]])
17041704
; ALL-NEXT: [[TMP1:%.*]] = ashr <2 x i16> [[A]], <i16 9, i16 9>
1705-
; ALL-NEXT: [[D:%.*]] = trunc <2 x i16> [[TMP1]] to <2 x i8>
1705+
; ALL-NEXT: [[D:%.*]] = trunc nsw <2 x i16> [[TMP1]] to <2 x i8>
17061706
; ALL-NEXT: ret <2 x i8> [[D]]
17071707
;
17081708
%B = sext <2 x i16> %A to <2 x i32>
@@ -1747,7 +1747,7 @@ define <2 x i8> @trunc_lshr_sext_wide_input_uses3(<2 x i16> %A) {
17471747
define <2 x i8> @trunc_lshr_overshift_wide_input_sext(<2 x i16> %A) {
17481748
; ALL-LABEL: @trunc_lshr_overshift_wide_input_sext(
17491749
; ALL-NEXT: [[TMP1:%.*]] = ashr <2 x i16> [[A:%.*]], <i16 15, i16 15>
1750-
; ALL-NEXT: [[D:%.*]] = trunc <2 x i16> [[TMP1]] to <2 x i8>
1750+
; ALL-NEXT: [[D:%.*]] = trunc nsw <2 x i16> [[TMP1]] to <2 x i8>
17511751
; ALL-NEXT: ret <2 x i8> [[D]]
17521752
;
17531753
%B = sext <2 x i16> %A to <2 x i32>
@@ -1761,7 +1761,7 @@ define i8 @trunc_lshr_overshift_sext_wide_input_uses1(i16 %A) {
17611761
; ALL-NEXT: [[B:%.*]] = sext i16 [[A:%.*]] to i32
17621762
; ALL-NEXT: call void @use_i32(i32 [[B]])
17631763
; ALL-NEXT: [[TMP1:%.*]] = ashr i16 [[A]], 15
1764-
; ALL-NEXT: [[D:%.*]] = trunc i16 [[TMP1]] to i8
1764+
; ALL-NEXT: [[D:%.*]] = trunc nsw i16 [[TMP1]] to i8
17651765
; ALL-NEXT: ret i8 [[D]]
17661766
;
17671767
%B = sext i16 %A to i32
@@ -1776,7 +1776,7 @@ define <2 x i8> @trunc_lshr_overshift_sext_wide_input_uses2(<2 x i16> %A) {
17761776
; ALL-NEXT: [[TMP1:%.*]] = ashr <2 x i16> [[A:%.*]], <i16 15, i16 15>
17771777
; ALL-NEXT: [[C:%.*]] = zext <2 x i16> [[TMP1]] to <2 x i32>
17781778
; ALL-NEXT: call void @use_v2i32(<2 x i32> [[C]])
1779-
; ALL-NEXT: [[D:%.*]] = trunc <2 x i16> [[TMP1]] to <2 x i8>
1779+
; ALL-NEXT: [[D:%.*]] = trunc nsw <2 x i16> [[TMP1]] to <2 x i8>
17801780
; ALL-NEXT: ret <2 x i8> [[D]]
17811781
;
17821782
%B = sext <2 x i16> %A to <2 x i32>
@@ -1925,7 +1925,7 @@ define <2 x i8> @trunc_lshr_overshift2_sext(<2 x i8> %A) {
19251925
; ALL-LABEL: @trunc_lshr_overshift2_sext(
19261926
; ALL-NEXT: [[B:%.*]] = sext <2 x i8> [[A:%.*]] to <2 x i32>
19271927
; ALL-NEXT: [[C:%.*]] = lshr <2 x i32> [[B]], <i32 25, i32 25>
1928-
; ALL-NEXT: [[D:%.*]] = trunc <2 x i32> [[C]] to <2 x i8>
1928+
; ALL-NEXT: [[D:%.*]] = trunc nuw nsw <2 x i32> [[C]] to <2 x i8>
19291929
; ALL-NEXT: ret <2 x i8> [[D]]
19301930
;
19311931
%B = sext <2 x i8> %A to <2 x i32>
@@ -1939,7 +1939,7 @@ define i8 @trunc_lshr_overshift2_sext_uses1(i8 %A) {
19391939
; ALL-NEXT: [[B:%.*]] = sext i8 [[A:%.*]] to i32
19401940
; ALL-NEXT: call void @use_i32(i32 [[B]])
19411941
; ALL-NEXT: [[C:%.*]] = lshr i32 [[B]], 25
1942-
; ALL-NEXT: [[D:%.*]] = trunc i32 [[C]] to i8
1942+
; ALL-NEXT: [[D:%.*]] = trunc nuw nsw i32 [[C]] to i8
19431943
; ALL-NEXT: ret i8 [[D]]
19441944
;
19451945
%B = sext i8 %A to i32
@@ -1954,7 +1954,7 @@ define <2 x i8> @trunc_lshr_overshift2_sext_uses2(<2 x i8> %A) {
19541954
; ALL-NEXT: [[B:%.*]] = sext <2 x i8> [[A:%.*]] to <2 x i32>
19551955
; ALL-NEXT: [[C:%.*]] = lshr <2 x i32> [[B]], <i32 25, i32 25>
19561956
; ALL-NEXT: call void @use_v2i32(<2 x i32> [[C]])
1957-
; ALL-NEXT: [[D:%.*]] = trunc <2 x i32> [[C]] to <2 x i8>
1957+
; ALL-NEXT: [[D:%.*]] = trunc nuw nsw <2 x i32> [[C]] to <2 x i8>
19581958
; ALL-NEXT: ret <2 x i8> [[D]]
19591959
;
19601960
%B = sext <2 x i8> %A to <2 x i32>
@@ -1970,7 +1970,7 @@ define i8 @trunc_lshr_overshift2_sext_uses3(i8 %A) {
19701970
; ALL-NEXT: call void @use_i32(i32 [[B]])
19711971
; ALL-NEXT: [[C:%.*]] = lshr i32 [[B]], 25
19721972
; ALL-NEXT: call void @use_i32(i32 [[C]])
1973-
; ALL-NEXT: [[D:%.*]] = trunc i32 [[C]] to i8
1973+
; ALL-NEXT: [[D:%.*]] = trunc nuw nsw i32 [[C]] to i8
19741974
; ALL-NEXT: ret i8 [[D]]
19751975
;
19761976
%B = sext i8 %A to i32
@@ -2018,7 +2018,7 @@ define <2 x i8> @trunc_lshr_zext_uniform_undef(<2 x i8> %A) {
20182018
; ALL-LABEL: @trunc_lshr_zext_uniform_undef(
20192019
; ALL-NEXT: [[B:%.*]] = zext <2 x i8> [[A:%.*]] to <2 x i32>
20202020
; ALL-NEXT: [[C:%.*]] = lshr <2 x i32> [[B]], <i32 6, i32 undef>
2021-
; ALL-NEXT: [[D:%.*]] = trunc <2 x i32> [[C]] to <2 x i8>
2021+
; ALL-NEXT: [[D:%.*]] = trunc nuw <2 x i32> [[C]] to <2 x i8>
20222022
; ALL-NEXT: ret <2 x i8> [[D]]
20232023
;
20242024
%B = zext <2 x i8> %A to <2 x i32>
@@ -2042,7 +2042,7 @@ define <3 x i8> @trunc_lshr_zext_nonuniform_undef(<3 x i8> %A) {
20422042
; ALL-LABEL: @trunc_lshr_zext_nonuniform_undef(
20432043
; ALL-NEXT: [[B:%.*]] = zext <3 x i8> [[A:%.*]] to <3 x i32>
20442044
; ALL-NEXT: [[C:%.*]] = lshr <3 x i32> [[B]], <i32 6, i32 2, i32 undef>
2045-
; ALL-NEXT: [[D:%.*]] = trunc <3 x i32> [[C]] to <3 x i8>
2045+
; ALL-NEXT: [[D:%.*]] = trunc nuw <3 x i32> [[C]] to <3 x i8>
20462046
; ALL-NEXT: ret <3 x i8> [[D]]
20472047
;
20482048
%B = zext <3 x i8> %A to <3 x i32>
@@ -2095,7 +2095,7 @@ define i4 @pr33078_3(i8 %A) {
20952095
; ALL-LABEL: @pr33078_3(
20962096
; ALL-NEXT: [[B:%.*]] = sext i8 [[A:%.*]] to i16
20972097
; ALL-NEXT: [[C:%.*]] = lshr i16 [[B]], 12
2098-
; ALL-NEXT: [[D:%.*]] = trunc i16 [[C]] to i4
2098+
; ALL-NEXT: [[D:%.*]] = trunc nuw i16 [[C]] to i4
20992099
; ALL-NEXT: ret i4 [[D]]
21002100
;
21012101
%B = sext i8 %A to i16
@@ -2109,7 +2109,7 @@ define i8 @pr33078_4(i3 %x) {
21092109
; ALL-LABEL: @pr33078_4(
21102110
; ALL-NEXT: [[B:%.*]] = sext i3 [[X:%.*]] to i16
21112111
; ALL-NEXT: [[C:%.*]] = lshr i16 [[B]], 13
2112-
; ALL-NEXT: [[D:%.*]] = trunc i16 [[C]] to i8
2112+
; ALL-NEXT: [[D:%.*]] = trunc nuw nsw i16 [[C]] to i8
21132113
; ALL-NEXT: ret i8 [[D]]
21142114
;
21152115
%B = sext i3 %x to i16

llvm/test/Transforms/InstCombine/cmp-intrinsic.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ define i1 @trunc_cttz_false_ult_other_i32_i6(i32 %x) {
618618
define i1 @trunc_cttz_false_ult_other_i32_i6_extra_use(i32 %x) {
619619
; CHECK-LABEL: @trunc_cttz_false_ult_other_i32_i6_extra_use(
620620
; CHECK-NEXT: [[TZ:%.*]] = tail call i32 @llvm.cttz.i32(i32 [[X:%.*]], i1 false), !range [[RNG0]]
621-
; CHECK-NEXT: [[TRUNC:%.*]] = trunc i32 [[TZ]] to i6
621+
; CHECK-NEXT: [[TRUNC:%.*]] = trunc nuw i32 [[TZ]] to i6
622622
; CHECK-NEXT: call void @use6(i6 [[TRUNC]])
623623
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i6 [[TRUNC]], 7
624624
; CHECK-NEXT: ret i1 [[CMP]]
@@ -720,7 +720,7 @@ define i1 @trunc_ctlz_false_ugt_other_i32_i6(i32 %x) {
720720
define i1 @trunc_ctlz_false_ugt_other_i32_i6_extra_use(i32 %x) {
721721
; CHECK-LABEL: @trunc_ctlz_false_ugt_other_i32_i6_extra_use(
722722
; CHECK-NEXT: [[LZ:%.*]] = tail call i32 @llvm.ctlz.i32(i32 [[X:%.*]], i1 false), !range [[RNG0]]
723-
; CHECK-NEXT: [[TRUNC:%.*]] = trunc i32 [[LZ]] to i6
723+
; CHECK-NEXT: [[TRUNC:%.*]] = trunc nuw i32 [[LZ]] to i6
724724
; CHECK-NEXT: call void @use6(i6 [[TRUNC]])
725725
; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i6 [[TRUNC]], 4
726726
; CHECK-NEXT: ret i1 [[CMP]]

llvm/test/Transforms/InstCombine/compare-signs.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ define <2 x i1> @shift_trunc_signbit_test_vec_uses(<2 x i17> %x, ptr %p1, ptr %p
223223
; CHECK-LABEL: @shift_trunc_signbit_test_vec_uses(
224224
; CHECK-NEXT: [[SH:%.*]] = lshr <2 x i17> [[X:%.*]], <i17 4, i17 4>
225225
; CHECK-NEXT: store <2 x i17> [[SH]], ptr [[P1:%.*]], align 8
226-
; CHECK-NEXT: [[TR:%.*]] = trunc <2 x i17> [[SH]] to <2 x i13>
226+
; CHECK-NEXT: [[TR:%.*]] = trunc nuw <2 x i17> [[SH]] to <2 x i13>
227227
; CHECK-NEXT: store <2 x i13> [[TR]], ptr [[P2:%.*]], align 4
228228
; CHECK-NEXT: [[R:%.*]] = icmp sgt <2 x i17> [[X]], <i17 -1, i17 -1>
229229
; CHECK-NEXT: ret <2 x i1> [[R]]
@@ -255,7 +255,7 @@ define i1 @shift_trunc_wrong_shift(i32 %x) {
255255
define i1 @shift_trunc_wrong_cmp(i32 %x) {
256256
; CHECK-LABEL: @shift_trunc_wrong_cmp(
257257
; CHECK-NEXT: [[SH:%.*]] = lshr i32 [[X:%.*]], 24
258-
; CHECK-NEXT: [[TR:%.*]] = trunc i32 [[SH]] to i8
258+
; CHECK-NEXT: [[TR:%.*]] = trunc nuw i32 [[SH]] to i8
259259
; CHECK-NEXT: [[R:%.*]] = icmp slt i8 [[TR]], 1
260260
; CHECK-NEXT: ret i1 [[R]]
261261
;

llvm/test/Transforms/InstCombine/ctpop.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ define i32 @parity_xor_trunc(i64 %arg, i64 %arg1) {
397397
; CHECK-LABEL: @parity_xor_trunc(
398398
; CHECK-NEXT: [[TMP1:%.*]] = xor i64 [[ARG1:%.*]], [[ARG:%.*]]
399399
; CHECK-NEXT: [[TMP2:%.*]] = call i64 @llvm.ctpop.i64(i64 [[TMP1]]), !range [[RNG5:![0-9]+]]
400-
; CHECK-NEXT: [[I4:%.*]] = trunc i64 [[TMP2]] to i32
400+
; CHECK-NEXT: [[I4:%.*]] = trunc nuw nsw i64 [[TMP2]] to i32
401401
; CHECK-NEXT: [[I5:%.*]] = and i32 [[I4]], 1
402402
; CHECK-NEXT: ret i32 [[I5]]
403403
;

0 commit comments

Comments
 (0)