Skip to content

Commit 8a40c65

Browse files
committed
Refactor logic and add additional tests
1 parent 0d761fb commit 8a40c65

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2758,9 +2758,10 @@ static Instruction *foldFNegIntoConstant(Instruction &I, const DataLayout &DL) {
27582758
// -(X * C) --> X * (-C)
27592759
if (match(FNegOp, m_FMul(m_Value(X), m_Constant(C))))
27602760
if (Constant *NegC = ConstantFoldUnaryOpOperand(Instruction::FNeg, C, DL)) {
2761-
FastMathFlags Flag = I.getFastMathFlags() | FNegOp->getFastMathFlags();
2762-
Flag.setNoInfs(I.getFastMathFlags().noInfs() &&
2763-
FNegOp->getFastMathFlags().noInfs());
2761+
FastMathFlags FMF = I.getFastMathFlags();
2762+
FastMathFlags OpFMF = FNegOp->getFastMathFlags();
2763+
FastMathFlags Flag = FMF | OpFMF;
2764+
Flag.setNoInfs(FMF.noInfs() && OpFMF.noInfs());
27642765
return BinaryOperator::CreateFMulFMF(X, NegC, Flag);
27652766
}
27662767
// -(X / C) --> X / (-C)

llvm/test/Transforms/InstCombine/fneg.ll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,4 +1201,14 @@ define <2 x float> @test_fneg_nnan_ninf_mul_with_vec_const(<2 x float> %a) {
12011201
ret <2 x float> %f2
12021202
}
12031203

1204+
define <2 x float> @test_fneg_nnan_ninf_mul_ninf_with_vec_const(<2 x float> %a) {
1205+
; CHECK-LABEL: @test_fneg_nnan_ninf_mul_ninf_with_vec_const(
1206+
; CHECK-NEXT: [[F2:%.*]] = fmul nnan ninf <2 x float> [[A:%.*]], <float -0.000000e+00, float 0.000000e+00>
1207+
; CHECK-NEXT: ret <2 x float> [[F2]]
1208+
;
1209+
%f1 = fmul ninf <2 x float> %a, <float 0.000000, float -0.000000>
1210+
%f2 = fneg nnan ninf <2 x float> %f1
1211+
ret <2 x float> %f2
1212+
}
1213+
12041214
!0 = !{}

0 commit comments

Comments
 (0)