Index: lib/Transforms/InstCombine/InstCombineAddSub.cpp =================================================================== --- lib/Transforms/InstCombine/InstCombineAddSub.cpp +++ lib/Transforms/InstCombine/InstCombineAddSub.cpp @@ -1762,6 +1762,14 @@ TLI, DT, AT)) return ReplaceInstUsesWith(I, V); + // fsub nsz 0, X ==> fsub nsz -0.0, X + if (I.getFastMathFlags().noSignedZeros() && match(Op0, m_Zero())) { + // Subtraction from -0.0 is the canonical form of fneg. + Instruction *NewI = BinaryOperator::CreateFNeg(Op1); + NewI->copyFastMathFlags(&I); + return NewI; + } + if (isa(Op0)) if (SelectInst *SI = dyn_cast(Op1)) if (Instruction *NV = FoldOpIntoSelect(I, SI)) Index: test/Transforms/InstCombine/fast-math.ll =================================================================== --- test/Transforms/InstCombine/fast-math.ll +++ test/Transforms/InstCombine/fast-math.ll @@ -93,7 +93,7 @@ ret float %t3 ; CHECK-LABEL: @fold9( -; CHECK: fsub fast float 0.000000e+00, %f2 +; CHECK: fsub fast float -0.000000e+00, %f2 } ; Let C3 = C1 + C2. (f1 + C1) + (f2 + C2) => (f1 + f2) + C3 instead of @@ -322,6 +322,14 @@ ; CHECK: fmul float %f1, %f2 } +define float @fneg2(float %x) { + %sub = fsub nsz float 0.0, %x + ret float %sub +; CHECK-LABEL: @fneg2( +; CHECK-NEXT: fsub nsz float -0.000000e+00, %x +; CHECK-NEXT: ret float +} + ; ========================================================================= ; ; Testing-cases about div