[llvm] [InstCombine] Fold +0.0 - x to -x if we known x is non positive zero (PR #215871)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 16 01:06:39 PDT 2026
================
@@ -3290,6 +3290,18 @@ Instruction *InstCombinerImpl::visitFSub(BinaryOperator &I) {
if (match(&I, m_FNeg(m_Value(Op))))
return UnaryOperator::CreateFNegFMF(Op, &I);
+ // fsub +0.0, X ==> fneg X if known X is never +0.0
+ if (match(I.getOperand(0), m_PosZeroFP())) {
+ Value *X = I.getOperand(1);
+ DenormalMode Mode = I.getFunction()->getDenormalMode(
+ X->getType()->getScalarType()->getFltSemantics());
+ KnownFPClass Known = computeKnownFPClass(
+ X, fcPosZero | fcSubnormal, getSimplifyQuery().getWithInstruction(&I));
+ if (Known.isKnownNeverLogicalPosZero(Mode) &&
+ (Mode.Input == DenormalMode::IEEE || Known.isKnownNeverSubnormal()))
----------------
dtcxzyw wrote:
I think most of the `fsub->fneg` transformations in visitFSub don't respect FTZ/DTZ...
Perhaps we can replace all the `UnaryOperator::CreateFNegFMF` below with `fsub -0.0, x`, then only handle denormal modes in the canonicalization of `fsub -0.0, X ==> fneg X`.
https://github.com/llvm/llvm-project/pull/215871
More information about the llvm-commits
mailing list