Skip to content

Commit 70d0ebb

Browse files
committed
[InstCombine] Fix behavior for (fmul (sitfp x), 0)
Bug was introduced in #82555 We where missing check that the constant was non-zero for signed + mul transform. Closes #85298
1 parent 3236d97 commit 70d0ebb

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,6 +1481,11 @@ Instruction *InstCombinerImpl::foldFBinOpOfIntCastsFromSign(
14811481

14821482
// If we have a constant rhs, see if we can losslessly convert it to an int.
14831483
if (Op1FpC != nullptr) {
1484+
// Signed + Mul req non-zero
1485+
if (OpsFromSigned && BO.getOpcode() == Instruction::FMul &&
1486+
!match(Op1FpC, m_NonZeroFP()))
1487+
return nullptr;
1488+
14841489
Constant *Op1IntC = ConstantFoldCastOperand(
14851490
OpsFromSigned ? Instruction::FPToSI : Instruction::FPToUI, Op1FpC,
14861491
IntTy, DL);

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,8 +1010,11 @@ 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
1014+
; CHECK-NEXT: [[CONV1_I:%.*]] = sitofp i16 [[CONV_I]] to float
1015+
; CHECK-NEXT: [[MUL3_I_I:%.*]] = fmul float [[CONV1_I]], 0.000000e+00
10131016
; CHECK-NEXT: store i32 [[SEL]], ptr [[G_2345:%.*]], align 4
1014-
; CHECK-NEXT: ret float 0.000000e+00
1017+
; CHECK-NEXT: ret float [[MUL3_I_I]]
10151018
;
10161019
%sel = select i1 %c, i32 65529, i32 53264
10171020
%conv.i = trunc i32 %sel to i16
@@ -1024,8 +1027,13 @@ define float @missed_nonzero_check_on_constant_for_si_fmul(i1 %c, i1 %.b, ptr %g
10241027
define <2 x float> @missed_nonzero_check_on_constant_for_si_fmul_vec(i1 %c, i1 %.b, ptr %g_2345) {
10251028
; CHECK-LABEL: @missed_nonzero_check_on_constant_for_si_fmul_vec(
10261029
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[C:%.*]], i32 65529, i32 53264
1030+
; CHECK-NEXT: [[CONV_I_S:%.*]] = trunc i32 [[SEL]] to i16
1031+
; CHECK-NEXT: [[CONV_I_V:%.*]] = insertelement <2 x i16> poison, i16 [[CONV_I_S]], i64 0
1032+
; CHECK-NEXT: [[CONV_I:%.*]] = shufflevector <2 x i16> [[CONV_I_V]], <2 x i16> poison, <2 x i32> zeroinitializer
1033+
; CHECK-NEXT: [[CONV1_I:%.*]] = sitofp <2 x i16> [[CONV_I]] to <2 x float>
1034+
; CHECK-NEXT: [[MUL3_I_I:%.*]] = fmul <2 x float> [[CONV1_I]], zeroinitializer
10271035
; CHECK-NEXT: store i32 [[SEL]], ptr [[G_2345:%.*]], align 4
1028-
; CHECK-NEXT: ret <2 x float> zeroinitializer
1036+
; CHECK-NEXT: ret <2 x float> [[MUL3_I_I]]
10291037
;
10301038
%sel = select i1 %c, i32 65529, i32 53264
10311039
%conv.i.s = trunc i32 %sel to i16

0 commit comments

Comments
 (0)