[llvm] [DAG] Fold nested add(add(reduce(a), b), add(reduce(c), d)) (PR #115150)
David Green via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 16 07:02:44 PDT 2025
================
@@ -17429,12 +17463,15 @@ SDValue DAGCombiner::visitFADD(SDNode *N) {
DAG.getConstantFP(4.0, DL, VT));
}
}
+ } // enable-unsafe-fp-math && AllowNewConst
+ if (((Options.UnsafeFPMath && Options.NoSignedZerosFPMath) ||
+ (Flags.hasAllowReassociation() && Flags.hasNoSignedZeros()))) {
----------------
davemgreen wrote:
Hi - the last stage of DAG combining, after operations are legalized, will perform legalization on any newly created nodes to make sure nothing illegal is generated into selection. If the fp imm is not legal for the target, but the original two inputs to the are, it still gets a chance to legalize them. Otherwise you would imagine we would see many more cases as immediate can be created from a lot of places (and it would be the fadd(C1, C2) fold that was performing the incorrect fold). I feel doubtful it is possible to have that happen - that all the nodes are not optimized/reassociated earlier but it does constant fold after legalization. Some targets legalize most fp imm's to some from of wrapper / load, so constant folding isn't possible that late.
I think that AllowNewConst is either just a heuristic to prevent worse code, or is old and no longer applies. It is hard to tell as even if I set AllowNewConst=true nothing changes.
https://github.com/llvm/llvm-project/pull/115150
More information about the llvm-commits
mailing list