Skip to content

Commit d80d5b9

Browse files
committed
[InstCombine] Canonicalize (sitofp x) -> (uitofp x) if x >= 0
Just a standard canonicalization. Proofs: https://alive2.llvm.org/ce/z/9W4VFm Closes #82404
1 parent f9a1478 commit d80d5b9

File tree

11 files changed

+83
-79
lines changed

11 files changed

+83
-79
lines changed

clang/test/Headers/__clang_hip_math.hip

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,7 +1685,7 @@ extern "C" __device__ double test_j1(double x) {
16851685
// DEFAULT-NEXT: [[__X1_0_I3:%.*]] = phi float [ [[SUB_I:%.*]], [[FOR_BODY_I]] ], [ [[CALL_I21_I]], [[IF_END4_I]] ]
16861686
// DEFAULT-NEXT: [[__X0_0_I2:%.*]] = phi float [ [[__X1_0_I3]], [[FOR_BODY_I]] ], [ [[CALL_I_I]], [[IF_END4_I]] ]
16871687
// DEFAULT-NEXT: [[MUL_I:%.*]] = shl nuw nsw i32 [[__I_0_I4]], 1
1688-
// DEFAULT-NEXT: [[CONV_I:%.*]] = sitofp i32 [[MUL_I]] to float
1688+
// DEFAULT-NEXT: [[CONV_I:%.*]] = uitofp i32 [[MUL_I]] to float
16891689
// DEFAULT-NEXT: [[DIV_I:%.*]] = fdiv contract float [[CONV_I]], [[Y]]
16901690
// DEFAULT-NEXT: [[MUL8_I:%.*]] = fmul contract float [[__X1_0_I3]], [[DIV_I]]
16911691
// DEFAULT-NEXT: [[SUB_I]] = fsub contract float [[MUL8_I]], [[__X0_0_I2]]
@@ -1718,7 +1718,7 @@ extern "C" __device__ double test_j1(double x) {
17181718
// FINITEONLY-NEXT: [[__X1_0_I3:%.*]] = phi float [ [[SUB_I:%.*]], [[FOR_BODY_I]] ], [ [[CALL_I21_I]], [[IF_END4_I]] ]
17191719
// FINITEONLY-NEXT: [[__X0_0_I2:%.*]] = phi float [ [[__X1_0_I3]], [[FOR_BODY_I]] ], [ [[CALL_I_I]], [[IF_END4_I]] ]
17201720
// FINITEONLY-NEXT: [[MUL_I:%.*]] = shl nuw nsw i32 [[__I_0_I4]], 1
1721-
// FINITEONLY-NEXT: [[CONV_I:%.*]] = sitofp i32 [[MUL_I]] to float
1721+
// FINITEONLY-NEXT: [[CONV_I:%.*]] = uitofp i32 [[MUL_I]] to float
17221722
// FINITEONLY-NEXT: [[DIV_I:%.*]] = fdiv nnan ninf contract float [[CONV_I]], [[Y]]
17231723
// FINITEONLY-NEXT: [[MUL8_I:%.*]] = fmul nnan ninf contract float [[__X1_0_I3]], [[DIV_I]]
17241724
// FINITEONLY-NEXT: [[SUB_I]] = fsub nnan ninf contract float [[MUL8_I]], [[__X0_0_I2]]
@@ -1751,7 +1751,7 @@ extern "C" __device__ double test_j1(double x) {
17511751
// APPROX-NEXT: [[__X1_0_I3:%.*]] = phi float [ [[SUB_I:%.*]], [[FOR_BODY_I]] ], [ [[CALL_I21_I]], [[IF_END4_I]] ]
17521752
// APPROX-NEXT: [[__X0_0_I2:%.*]] = phi float [ [[__X1_0_I3]], [[FOR_BODY_I]] ], [ [[CALL_I_I]], [[IF_END4_I]] ]
17531753
// APPROX-NEXT: [[MUL_I:%.*]] = shl nuw nsw i32 [[__I_0_I4]], 1
1754-
// APPROX-NEXT: [[CONV_I:%.*]] = sitofp i32 [[MUL_I]] to float
1754+
// APPROX-NEXT: [[CONV_I:%.*]] = uitofp i32 [[MUL_I]] to float
17551755
// APPROX-NEXT: [[DIV_I:%.*]] = fdiv contract float [[CONV_I]], [[Y]]
17561756
// APPROX-NEXT: [[MUL8_I:%.*]] = fmul contract float [[__X1_0_I3]], [[DIV_I]]
17571757
// APPROX-NEXT: [[SUB_I]] = fsub contract float [[MUL8_I]], [[__X0_0_I2]]
@@ -1788,7 +1788,7 @@ extern "C" __device__ float test_jnf(int x, float y) {
17881788
// DEFAULT-NEXT: [[__X1_0_I3:%.*]] = phi double [ [[SUB_I:%.*]], [[FOR_BODY_I]] ], [ [[CALL_I21_I]], [[IF_END4_I]] ]
17891789
// DEFAULT-NEXT: [[__X0_0_I2:%.*]] = phi double [ [[__X1_0_I3]], [[FOR_BODY_I]] ], [ [[CALL_I_I]], [[IF_END4_I]] ]
17901790
// DEFAULT-NEXT: [[MUL_I:%.*]] = shl nuw nsw i32 [[__I_0_I4]], 1
1791-
// DEFAULT-NEXT: [[CONV_I:%.*]] = sitofp i32 [[MUL_I]] to double
1791+
// DEFAULT-NEXT: [[CONV_I:%.*]] = uitofp i32 [[MUL_I]] to double
17921792
// DEFAULT-NEXT: [[DIV_I:%.*]] = fdiv contract double [[CONV_I]], [[Y]]
17931793
// DEFAULT-NEXT: [[MUL8_I:%.*]] = fmul contract double [[__X1_0_I3]], [[DIV_I]]
17941794
// DEFAULT-NEXT: [[SUB_I]] = fsub contract double [[MUL8_I]], [[__X0_0_I2]]
@@ -1821,7 +1821,7 @@ extern "C" __device__ float test_jnf(int x, float y) {
18211821
// FINITEONLY-NEXT: [[__X1_0_I3:%.*]] = phi double [ [[SUB_I:%.*]], [[FOR_BODY_I]] ], [ [[CALL_I21_I]], [[IF_END4_I]] ]
18221822
// FINITEONLY-NEXT: [[__X0_0_I2:%.*]] = phi double [ [[__X1_0_I3]], [[FOR_BODY_I]] ], [ [[CALL_I_I]], [[IF_END4_I]] ]
18231823
// FINITEONLY-NEXT: [[MUL_I:%.*]] = shl nuw nsw i32 [[__I_0_I4]], 1
1824-
// FINITEONLY-NEXT: [[CONV_I:%.*]] = sitofp i32 [[MUL_I]] to double
1824+
// FINITEONLY-NEXT: [[CONV_I:%.*]] = uitofp i32 [[MUL_I]] to double
18251825
// FINITEONLY-NEXT: [[DIV_I:%.*]] = fdiv nnan ninf contract double [[CONV_I]], [[Y]]
18261826
// FINITEONLY-NEXT: [[MUL8_I:%.*]] = fmul nnan ninf contract double [[__X1_0_I3]], [[DIV_I]]
18271827
// FINITEONLY-NEXT: [[SUB_I]] = fsub nnan ninf contract double [[MUL8_I]], [[__X0_0_I2]]
@@ -1854,7 +1854,7 @@ extern "C" __device__ float test_jnf(int x, float y) {
18541854
// APPROX-NEXT: [[__X1_0_I3:%.*]] = phi double [ [[SUB_I:%.*]], [[FOR_BODY_I]] ], [ [[CALL_I21_I]], [[IF_END4_I]] ]
18551855
// APPROX-NEXT: [[__X0_0_I2:%.*]] = phi double [ [[__X1_0_I3]], [[FOR_BODY_I]] ], [ [[CALL_I_I]], [[IF_END4_I]] ]
18561856
// APPROX-NEXT: [[MUL_I:%.*]] = shl nuw nsw i32 [[__I_0_I4]], 1
1857-
// APPROX-NEXT: [[CONV_I:%.*]] = sitofp i32 [[MUL_I]] to double
1857+
// APPROX-NEXT: [[CONV_I:%.*]] = uitofp i32 [[MUL_I]] to double
18581858
// APPROX-NEXT: [[DIV_I:%.*]] = fdiv contract double [[CONV_I]], [[Y]]
18591859
// APPROX-NEXT: [[MUL8_I:%.*]] = fmul contract double [[__X1_0_I3]], [[DIV_I]]
18601860
// APPROX-NEXT: [[SUB_I]] = fsub contract double [[MUL8_I]], [[__X0_0_I2]]
@@ -4222,7 +4222,7 @@ extern "C" __device__ double test_y1(double x) {
42224222
// DEFAULT-NEXT: [[__X1_0_I3:%.*]] = phi float [ [[SUB_I:%.*]], [[FOR_BODY_I]] ], [ [[CALL_I21_I]], [[IF_END4_I]] ]
42234223
// DEFAULT-NEXT: [[__X0_0_I2:%.*]] = phi float [ [[__X1_0_I3]], [[FOR_BODY_I]] ], [ [[CALL_I_I]], [[IF_END4_I]] ]
42244224
// DEFAULT-NEXT: [[MUL_I:%.*]] = shl nuw nsw i32 [[__I_0_I4]], 1
4225-
// DEFAULT-NEXT: [[CONV_I:%.*]] = sitofp i32 [[MUL_I]] to float
4225+
// DEFAULT-NEXT: [[CONV_I:%.*]] = uitofp i32 [[MUL_I]] to float
42264226
// DEFAULT-NEXT: [[DIV_I:%.*]] = fdiv contract float [[CONV_I]], [[Y]]
42274227
// DEFAULT-NEXT: [[MUL8_I:%.*]] = fmul contract float [[__X1_0_I3]], [[DIV_I]]
42284228
// DEFAULT-NEXT: [[SUB_I]] = fsub contract float [[MUL8_I]], [[__X0_0_I2]]
@@ -4255,7 +4255,7 @@ extern "C" __device__ double test_y1(double x) {
42554255
// FINITEONLY-NEXT: [[__X1_0_I3:%.*]] = phi float [ [[SUB_I:%.*]], [[FOR_BODY_I]] ], [ [[CALL_I21_I]], [[IF_END4_I]] ]
42564256
// FINITEONLY-NEXT: [[__X0_0_I2:%.*]] = phi float [ [[__X1_0_I3]], [[FOR_BODY_I]] ], [ [[CALL_I_I]], [[IF_END4_I]] ]
42574257
// FINITEONLY-NEXT: [[MUL_I:%.*]] = shl nuw nsw i32 [[__I_0_I4]], 1
4258-
// FINITEONLY-NEXT: [[CONV_I:%.*]] = sitofp i32 [[MUL_I]] to float
4258+
// FINITEONLY-NEXT: [[CONV_I:%.*]] = uitofp i32 [[MUL_I]] to float
42594259
// FINITEONLY-NEXT: [[DIV_I:%.*]] = fdiv nnan ninf contract float [[CONV_I]], [[Y]]
42604260
// FINITEONLY-NEXT: [[MUL8_I:%.*]] = fmul nnan ninf contract float [[__X1_0_I3]], [[DIV_I]]
42614261
// FINITEONLY-NEXT: [[SUB_I]] = fsub nnan ninf contract float [[MUL8_I]], [[__X0_0_I2]]
@@ -4288,7 +4288,7 @@ extern "C" __device__ double test_y1(double x) {
42884288
// APPROX-NEXT: [[__X1_0_I3:%.*]] = phi float [ [[SUB_I:%.*]], [[FOR_BODY_I]] ], [ [[CALL_I21_I]], [[IF_END4_I]] ]
42894289
// APPROX-NEXT: [[__X0_0_I2:%.*]] = phi float [ [[__X1_0_I3]], [[FOR_BODY_I]] ], [ [[CALL_I_I]], [[IF_END4_I]] ]
42904290
// APPROX-NEXT: [[MUL_I:%.*]] = shl nuw nsw i32 [[__I_0_I4]], 1
4291-
// APPROX-NEXT: [[CONV_I:%.*]] = sitofp i32 [[MUL_I]] to float
4291+
// APPROX-NEXT: [[CONV_I:%.*]] = uitofp i32 [[MUL_I]] to float
42924292
// APPROX-NEXT: [[DIV_I:%.*]] = fdiv contract float [[CONV_I]], [[Y]]
42934293
// APPROX-NEXT: [[MUL8_I:%.*]] = fmul contract float [[__X1_0_I3]], [[DIV_I]]
42944294
// APPROX-NEXT: [[SUB_I]] = fsub contract float [[MUL8_I]], [[__X0_0_I2]]
@@ -4325,7 +4325,7 @@ extern "C" __device__ float test_ynf(int x, float y) {
43254325
// DEFAULT-NEXT: [[__X1_0_I3:%.*]] = phi double [ [[SUB_I:%.*]], [[FOR_BODY_I]] ], [ [[CALL_I21_I]], [[IF_END4_I]] ]
43264326
// DEFAULT-NEXT: [[__X0_0_I2:%.*]] = phi double [ [[__X1_0_I3]], [[FOR_BODY_I]] ], [ [[CALL_I_I]], [[IF_END4_I]] ]
43274327
// DEFAULT-NEXT: [[MUL_I:%.*]] = shl nuw nsw i32 [[__I_0_I4]], 1
4328-
// DEFAULT-NEXT: [[CONV_I:%.*]] = sitofp i32 [[MUL_I]] to double
4328+
// DEFAULT-NEXT: [[CONV_I:%.*]] = uitofp i32 [[MUL_I]] to double
43294329
// DEFAULT-NEXT: [[DIV_I:%.*]] = fdiv contract double [[CONV_I]], [[Y]]
43304330
// DEFAULT-NEXT: [[MUL8_I:%.*]] = fmul contract double [[__X1_0_I3]], [[DIV_I]]
43314331
// DEFAULT-NEXT: [[SUB_I]] = fsub contract double [[MUL8_I]], [[__X0_0_I2]]
@@ -4358,7 +4358,7 @@ extern "C" __device__ float test_ynf(int x, float y) {
43584358
// FINITEONLY-NEXT: [[__X1_0_I3:%.*]] = phi double [ [[SUB_I:%.*]], [[FOR_BODY_I]] ], [ [[CALL_I21_I]], [[IF_END4_I]] ]
43594359
// FINITEONLY-NEXT: [[__X0_0_I2:%.*]] = phi double [ [[__X1_0_I3]], [[FOR_BODY_I]] ], [ [[CALL_I_I]], [[IF_END4_I]] ]
43604360
// FINITEONLY-NEXT: [[MUL_I:%.*]] = shl nuw nsw i32 [[__I_0_I4]], 1
4361-
// FINITEONLY-NEXT: [[CONV_I:%.*]] = sitofp i32 [[MUL_I]] to double
4361+
// FINITEONLY-NEXT: [[CONV_I:%.*]] = uitofp i32 [[MUL_I]] to double
43624362
// FINITEONLY-NEXT: [[DIV_I:%.*]] = fdiv nnan ninf contract double [[CONV_I]], [[Y]]
43634363
// FINITEONLY-NEXT: [[MUL8_I:%.*]] = fmul nnan ninf contract double [[__X1_0_I3]], [[DIV_I]]
43644364
// FINITEONLY-NEXT: [[SUB_I]] = fsub nnan ninf contract double [[MUL8_I]], [[__X0_0_I2]]
@@ -4391,7 +4391,7 @@ extern "C" __device__ float test_ynf(int x, float y) {
43914391
// APPROX-NEXT: [[__X1_0_I3:%.*]] = phi double [ [[SUB_I:%.*]], [[FOR_BODY_I]] ], [ [[CALL_I21_I]], [[IF_END4_I]] ]
43924392
// APPROX-NEXT: [[__X0_0_I2:%.*]] = phi double [ [[__X1_0_I3]], [[FOR_BODY_I]] ], [ [[CALL_I_I]], [[IF_END4_I]] ]
43934393
// APPROX-NEXT: [[MUL_I:%.*]] = shl nuw nsw i32 [[__I_0_I4]], 1
4394-
// APPROX-NEXT: [[CONV_I:%.*]] = sitofp i32 [[MUL_I]] to double
4394+
// APPROX-NEXT: [[CONV_I:%.*]] = uitofp i32 [[MUL_I]] to double
43954395
// APPROX-NEXT: [[DIV_I:%.*]] = fdiv contract double [[CONV_I]], [[Y]]
43964396
// APPROX-NEXT: [[MUL8_I:%.*]] = fmul contract double [[__X1_0_I3]], [[DIV_I]]
43974397
// APPROX-NEXT: [[SUB_I]] = fsub contract double [[MUL8_I]], [[__X0_0_I2]]

llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1942,7 +1942,11 @@ Instruction *InstCombinerImpl::visitUIToFP(CastInst &CI) {
19421942
}
19431943

19441944
Instruction *InstCombinerImpl::visitSIToFP(CastInst &CI) {
1945-
return commonCastTransforms(CI);
1945+
if (Instruction *R = commonCastTransforms(CI))
1946+
return R;
1947+
if (isKnownNonNegative(CI.getOperand(0), SQ))
1948+
return new UIToFPInst(CI.getOperand(0), CI.getType());
1949+
return nullptr;
19461950
}
19471951

19481952
Instruction *InstCombinerImpl::visitIntToPtr(IntToPtrInst &CI) {

llvm/test/Transforms/InstCombine/add-sitofp.ll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ define double @test(i32 %a) {
3333
define float @test_neg(i32 %a) {
3434
; CHECK-LABEL: @test_neg(
3535
; CHECK-NEXT: [[A_AND:%.*]] = and i32 [[A:%.*]], 1073741823
36-
; CHECK-NEXT: [[A_AND_FP:%.*]] = sitofp i32 [[A_AND]] to float
36+
; CHECK-NEXT: [[A_AND_FP:%.*]] = uitofp i32 [[A_AND]] to float
3737
; CHECK-NEXT: [[RES:%.*]] = fadd float [[A_AND_FP]], 1.000000e+00
3838
; CHECK-NEXT: ret float [[RES]]
3939
;
@@ -67,8 +67,8 @@ define float @test_2_neg(i32 %a, i32 %b) {
6767
; CHECK-LABEL: @test_2_neg(
6868
; CHECK-NEXT: [[A_AND:%.*]] = and i32 [[A:%.*]], 1073741823
6969
; CHECK-NEXT: [[B_AND:%.*]] = and i32 [[B:%.*]], 1073741823
70-
; CHECK-NEXT: [[A_AND_FP:%.*]] = sitofp i32 [[A_AND]] to float
71-
; CHECK-NEXT: [[B_AND_FP:%.*]] = sitofp i32 [[B_AND]] to float
70+
; CHECK-NEXT: [[A_AND_FP:%.*]] = uitofp i32 [[A_AND]] to float
71+
; CHECK-NEXT: [[B_AND_FP:%.*]] = uitofp i32 [[B_AND]] to float
7272
; CHECK-NEXT: [[RES:%.*]] = fadd float [[A_AND_FP]], [[B_AND_FP]]
7373
; CHECK-NEXT: ret float [[RES]]
7474
;
@@ -122,8 +122,8 @@ define <4 x float> @test_4_neg(<4 x i32> %a, <4 x i32> %b) {
122122
; CHECK-LABEL: @test_4_neg(
123123
; CHECK-NEXT: [[A_AND:%.*]] = and <4 x i32> [[A:%.*]], <i32 1073741823, i32 1073741823, i32 1073741823, i32 1073741823>
124124
; CHECK-NEXT: [[B_AND:%.*]] = and <4 x i32> [[B:%.*]], <i32 1073741823, i32 1073741823, i32 1073741823, i32 1073741823>
125-
; CHECK-NEXT: [[A_AND_FP:%.*]] = sitofp <4 x i32> [[A_AND]] to <4 x float>
126-
; CHECK-NEXT: [[B_AND_FP:%.*]] = sitofp <4 x i32> [[B_AND]] to <4 x float>
125+
; CHECK-NEXT: [[A_AND_FP:%.*]] = uitofp <4 x i32> [[A_AND]] to <4 x float>
126+
; CHECK-NEXT: [[B_AND_FP:%.*]] = uitofp <4 x i32> [[B_AND]] to <4 x float>
127127
; CHECK-NEXT: [[RES:%.*]] = fadd <4 x float> [[A_AND_FP]], [[B_AND_FP]]
128128
; CHECK-NEXT: ret <4 x float> [[RES]]
129129
;

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ define half @test_si_si_i8_sub(i8 noundef %x_in, i8 noundef %y_in) {
166166
; CHECK-NEXT: [[X:%.*]] = and i8 [[X_IN:%.*]], 63
167167
; CHECK-NEXT: [[Y:%.*]] = or i8 [[Y_IN:%.*]], -64
168168
; CHECK-NEXT: [[TMP1:%.*]] = sub nsw i8 [[X]], [[Y]]
169-
; CHECK-NEXT: [[R:%.*]] = sitofp i8 [[TMP1]] to half
169+
; CHECK-NEXT: [[R:%.*]] = uitofp i8 [[TMP1]] to half
170170
; CHECK-NEXT: ret half [[R]]
171171
;
172172
%x = and i8 %x_in, 63
@@ -181,7 +181,7 @@ define half @test_si_si_i8_sub_fail_overflow(i8 noundef %x_in, i8 noundef %y_in)
181181
; CHECK-LABEL: @test_si_si_i8_sub_fail_overflow(
182182
; CHECK-NEXT: [[X:%.*]] = and i8 [[X_IN:%.*]], 63
183183
; CHECK-NEXT: [[Y:%.*]] = or i8 [[Y_IN:%.*]], -65
184-
; CHECK-NEXT: [[XF:%.*]] = sitofp i8 [[X]] to half
184+
; CHECK-NEXT: [[XF:%.*]] = uitofp i8 [[X]] to half
185185
; CHECK-NEXT: [[YF:%.*]] = sitofp i8 [[Y]] to half
186186
; CHECK-NEXT: [[R:%.*]] = fsub half [[XF]], [[YF]]
187187
; CHECK-NEXT: ret half [[R]]
@@ -198,7 +198,7 @@ define half @test_si_si_i8_sub_C(i8 noundef %x_in) {
198198
; CHECK-LABEL: @test_si_si_i8_sub_C(
199199
; CHECK-NEXT: [[X:%.*]] = and i8 [[X_IN:%.*]], 63
200200
; CHECK-NEXT: [[TMP1:%.*]] = or disjoint i8 [[X]], 64
201-
; CHECK-NEXT: [[R:%.*]] = sitofp i8 [[TMP1]] to half
201+
; CHECK-NEXT: [[R:%.*]] = uitofp i8 [[TMP1]] to half
202202
; CHECK-NEXT: ret half [[R]]
203203
;
204204
%x = and i8 %x_in, 63
@@ -315,7 +315,7 @@ define half @test_si_si_i8_mul_fail_maybe_zero(i8 noundef %x_in, i8 noundef %y_i
315315
; CHECK-LABEL: @test_si_si_i8_mul_fail_maybe_zero(
316316
; CHECK-NEXT: [[X:%.*]] = and i8 [[X_IN:%.*]], 7
317317
; CHECK-NEXT: [[Y:%.*]] = or i8 [[Y_IN:%.*]], -8
318-
; CHECK-NEXT: [[XF:%.*]] = sitofp i8 [[X]] to half
318+
; CHECK-NEXT: [[XF:%.*]] = uitofp i8 [[X]] to half
319319
; CHECK-NEXT: [[YF:%.*]] = sitofp i8 [[Y]] to half
320320
; CHECK-NEXT: [[R:%.*]] = fmul half [[XF]], [[YF]]
321321
; CHECK-NEXT: ret half [[R]]
@@ -332,7 +332,7 @@ define half @test_si_si_i8_mul_C_fail_no_repr(i8 noundef %x_in) {
332332
; CHECK-LABEL: @test_si_si_i8_mul_C_fail_no_repr(
333333
; CHECK-NEXT: [[XX:%.*]] = and i8 [[X_IN:%.*]], 6
334334
; CHECK-NEXT: [[X:%.*]] = or disjoint i8 [[XX]], 1
335-
; CHECK-NEXT: [[XF:%.*]] = sitofp i8 [[X]] to half
335+
; CHECK-NEXT: [[XF:%.*]] = uitofp i8 [[X]] to half
336336
; CHECK-NEXT: [[R:%.*]] = fmul half [[XF]], 0xHC780
337337
; CHECK-NEXT: ret half [[R]]
338338
;
@@ -347,7 +347,7 @@ define half @test_si_si_i8_mul_C_fail_overflow(i8 noundef %x_in) {
347347
; CHECK-LABEL: @test_si_si_i8_mul_C_fail_overflow(
348348
; CHECK-NEXT: [[XX:%.*]] = and i8 [[X_IN:%.*]], 6
349349
; CHECK-NEXT: [[X:%.*]] = or disjoint i8 [[XX]], 1
350-
; CHECK-NEXT: [[XF:%.*]] = sitofp i8 [[X]] to half
350+
; CHECK-NEXT: [[XF:%.*]] = uitofp i8 [[X]] to half
351351
; CHECK-NEXT: [[R:%.*]] = fmul half [[XF]], 0xHCCC0
352352
; CHECK-NEXT: ret half [[R]]
353353
;
@@ -401,7 +401,7 @@ define half @test_ui_si_i8_mul_fail_signed(i8 noundef %x_in, i8 noundef %y_in) {
401401
; CHECK-NEXT: [[XX:%.*]] = and i8 [[X_IN:%.*]], 7
402402
; CHECK-NEXT: [[X:%.*]] = add nuw nsw i8 [[XX]], 1
403403
; CHECK-NEXT: [[Y:%.*]] = or i8 [[Y_IN:%.*]], -4
404-
; CHECK-NEXT: [[XF:%.*]] = sitofp i8 [[X]] to half
404+
; CHECK-NEXT: [[XF:%.*]] = uitofp i8 [[X]] to half
405405
; CHECK-NEXT: [[YF:%.*]] = uitofp i8 [[Y]] to half
406406
; CHECK-NEXT: [[R:%.*]] = fmul half [[XF]], [[YF]]
407407
; CHECK-NEXT: ret half [[R]]
@@ -541,7 +541,7 @@ define half @test_si_si_i16_sub_fail_no_promotion(i16 noundef %x_in, i16 noundef
541541
; CHECK-LABEL: @test_si_si_i16_sub_fail_no_promotion(
542542
; CHECK-NEXT: [[X:%.*]] = and i16 [[X_IN:%.*]], 2047
543543
; CHECK-NEXT: [[Y:%.*]] = or i16 [[Y_IN:%.*]], -2049
544-
; CHECK-NEXT: [[XF:%.*]] = sitofp i16 [[X]] to half
544+
; CHECK-NEXT: [[XF:%.*]] = uitofp i16 [[X]] to half
545545
; CHECK-NEXT: [[YF:%.*]] = sitofp i16 [[Y]] to half
546546
; CHECK-NEXT: [[R:%.*]] = fsub half [[XF]], [[YF]]
547547
; CHECK-NEXT: ret half [[R]]
@@ -575,7 +575,7 @@ define half @test_ui_si_i16_sub_fail_maybe_signed(i16 noundef %x_in, i16 noundef
575575
; CHECK-NEXT: [[X:%.*]] = or i16 [[X_IN:%.*]], -2048
576576
; CHECK-NEXT: [[Y:%.*]] = and i16 [[Y_IN:%.*]], 2047
577577
; CHECK-NEXT: [[XF:%.*]] = uitofp i16 [[X]] to half
578-
; CHECK-NEXT: [[YF:%.*]] = sitofp i16 [[Y]] to half
578+
; CHECK-NEXT: [[YF:%.*]] = uitofp i16 [[Y]] to half
579579
; CHECK-NEXT: [[R:%.*]] = fsub half [[XF]], [[YF]]
580580
; CHECK-NEXT: ret half [[R]]
581581
;
@@ -643,7 +643,7 @@ define half @test_si_si_i16_mul_fail_overflow(i16 noundef %x_in, i16 noundef %y_
643643
; CHECK-NEXT: [[XX:%.*]] = and i16 [[X_IN:%.*]], 126
644644
; CHECK-NEXT: [[X:%.*]] = or disjoint i16 [[XX]], 1
645645
; CHECK-NEXT: [[Y:%.*]] = or i16 [[Y_IN:%.*]], -257
646-
; CHECK-NEXT: [[XF:%.*]] = sitofp i16 [[X]] to half
646+
; CHECK-NEXT: [[XF:%.*]] = uitofp i16 [[X]] to half
647647
; CHECK-NEXT: [[YF:%.*]] = sitofp i16 [[Y]] to half
648648
; CHECK-NEXT: [[R:%.*]] = fmul half [[XF]], [[YF]]
649649
; CHECK-NEXT: ret half [[R]]
@@ -821,7 +821,7 @@ define half @test_si_si_i12_sub(i12 noundef %x_in, i12 noundef %y_in) {
821821
; CHECK-NEXT: [[X:%.*]] = and i12 [[X_IN:%.*]], 1023
822822
; CHECK-NEXT: [[Y:%.*]] = or i12 [[Y_IN:%.*]], -1024
823823
; CHECK-NEXT: [[TMP1:%.*]] = sub nsw i12 [[X]], [[Y]]
824-
; CHECK-NEXT: [[R:%.*]] = sitofp i12 [[TMP1]] to half
824+
; CHECK-NEXT: [[R:%.*]] = uitofp i12 [[TMP1]] to half
825825
; CHECK-NEXT: ret half [[R]]
826826
;
827827
%x = and i12 %x_in, 1023
@@ -915,7 +915,7 @@ define half @test_si_si_i12_mul_fail_overflow(i12 noundef %x_in, i12 noundef %y_
915915
; CHECK-NEXT: [[XX:%.*]] = and i12 [[X_IN:%.*]], 30
916916
; CHECK-NEXT: [[X:%.*]] = or disjoint i12 [[XX]], 1
917917
; CHECK-NEXT: [[Y:%.*]] = or i12 [[Y_IN:%.*]], -128
918-
; CHECK-NEXT: [[XF:%.*]] = sitofp i12 [[X]] to half
918+
; CHECK-NEXT: [[XF:%.*]] = uitofp i12 [[X]] to half
919919
; CHECK-NEXT: [[YF:%.*]] = sitofp i12 [[Y]] to half
920920
; CHECK-NEXT: [[R:%.*]] = fmul half [[XF]], [[YF]]
921921
; CHECK-NEXT: ret half [[R]]
@@ -933,7 +933,7 @@ define half @test_si_si_i12_mul_fail_maybe_non_zero(i12 noundef %x_in, i12 nound
933933
; CHECK-LABEL: @test_si_si_i12_mul_fail_maybe_non_zero(
934934
; CHECK-NEXT: [[X:%.*]] = and i12 [[X_IN:%.*]], 30
935935
; CHECK-NEXT: [[Y:%.*]] = or i12 [[Y_IN:%.*]], -128
936-
; CHECK-NEXT: [[XF:%.*]] = sitofp i12 [[X]] to half
936+
; CHECK-NEXT: [[XF:%.*]] = uitofp i12 [[X]] to half
937937
; CHECK-NEXT: [[YF:%.*]] = sitofp i12 [[Y]] to half
938938
; CHECK-NEXT: [[R:%.*]] = fmul half [[XF]], [[YF]]
939939
; CHECK-NEXT: ret half [[R]]
@@ -950,7 +950,7 @@ define half @test_si_si_i12_mul_C(i12 noundef %x_in) {
950950
; CHECK-LABEL: @test_si_si_i12_mul_C(
951951
; CHECK-NEXT: [[X:%.*]] = or i12 [[X_IN:%.*]], -64
952952
; CHECK-NEXT: [[TMP1:%.*]] = mul nsw i12 [[X]], -16
953-
; CHECK-NEXT: [[R:%.*]] = sitofp i12 [[TMP1]] to half
953+
; CHECK-NEXT: [[R:%.*]] = uitofp i12 [[TMP1]] to half
954954
; CHECK-NEXT: ret half [[R]]
955955
;
956956
%x = or i12 %x_in, -64

llvm/test/Transforms/InstCombine/clamp-to-minmax.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ define float @mixed_clamp_to_float_1(i32 %x) {
504504
; CHECK-LABEL: @mixed_clamp_to_float_1(
505505
; CHECK-NEXT: [[SI_MIN:%.*]] = call i32 @llvm.smin.i32(i32 [[X:%.*]], i32 255)
506506
; CHECK-NEXT: [[R1:%.*]] = call i32 @llvm.smax.i32(i32 [[SI_MIN]], i32 1)
507-
; CHECK-NEXT: [[R:%.*]] = sitofp i32 [[R1]] to float
507+
; CHECK-NEXT: [[R:%.*]] = uitofp i32 [[R1]] to float
508508
; CHECK-NEXT: ret float [[R]]
509509
;
510510
%si_min_cmp = icmp sgt i32 %x, 255
@@ -539,7 +539,7 @@ define float @mixed_clamp_to_float_2(i32 %x) {
539539
; CHECK-LABEL: @mixed_clamp_to_float_2(
540540
; CHECK-NEXT: [[SI_MIN:%.*]] = call i32 @llvm.smin.i32(i32 [[X:%.*]], i32 255)
541541
; CHECK-NEXT: [[R1:%.*]] = call i32 @llvm.smax.i32(i32 [[SI_MIN]], i32 1)
542-
; CHECK-NEXT: [[R:%.*]] = sitofp i32 [[R1]] to float
542+
; CHECK-NEXT: [[R:%.*]] = uitofp i32 [[R1]] to float
543543
; CHECK-NEXT: ret float [[R]]
544544
;
545545
%si_min_cmp = icmp sgt i32 %x, 255
@@ -572,7 +572,7 @@ define <2 x float> @mixed_clamp_to_float_vec(<2 x i32> %x) {
572572
; CHECK-LABEL: @mixed_clamp_to_float_vec(
573573
; CHECK-NEXT: [[SI_MIN:%.*]] = call <2 x i32> @llvm.smin.v2i32(<2 x i32> [[X:%.*]], <2 x i32> <i32 255, i32 255>)
574574
; CHECK-NEXT: [[R1:%.*]] = call <2 x i32> @llvm.smax.v2i32(<2 x i32> [[SI_MIN]], <2 x i32> <i32 1, i32 1>)
575-
; CHECK-NEXT: [[R:%.*]] = sitofp <2 x i32> [[R1]] to <2 x float>
575+
; CHECK-NEXT: [[R:%.*]] = uitofp <2 x i32> [[R1]] to <2 x float>
576576
; CHECK-NEXT: ret <2 x float> [[R]]
577577
;
578578
%si_min_cmp = icmp sgt <2 x i32> %x, <i32 255, i32 255>

0 commit comments

Comments
 (0)