[llvm] [AMDGPU][DAGCombiner][GlobalISel] Prevent FMA contraction when multiply cannot be eliminated (PR #169735)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 30 09:54:58 PST 2026
================
@@ -17227,6 +17224,110 @@ static bool isContractableFMUL(const TargetOptions &Options, SDValue N) {
N->getFlags().hasAllowContract();
}
+// Check if a node is a fused FMA or FMAD operation.
+template <class MatcherClass>
+static bool isFusedOp(const MatcherClass &matcher, SDValue N) {
+ return matcher.match(N, ISD::FMA) || matcher.match(N, ISD::FMAD);
+}
+
+// Check if all uses of a multiply can be contracted into FMA operations.
+// Returns true if all uses of the multiply are contractable, meaning the
+// multiply can potentially be eliminated through FMA contraction.
+// Returns false if any use cannot be contracted, which would mean contracting
+// would duplicate the multiply without reducing the total number of operations.
+//
+// This uses a simple, non-recursive check for the following patterns:
+// - fmul --> fadd/fsub: Direct contraction
+// - fmul --> fneg --> fsub: FNEG folds into FMA with negated operand
+// - fmul --> fpext --> {fadd, fsub, fma}: FPEXT folds if it can be folded
+// - fmul --> fma: Assume FMA can always be contracted (to avoid complexity)
+static bool allMulUsesCanBeContracted(SDValue Mul,
+ const unsigned PreferredFusedOpcode,
+ const TargetLowering &TLI,
+ SelectionDAG &DAG) {
+ // Default to always contracting on non-AMDGCN targets.
+ const Triple &TT = TLI.getTargetMachine().getTargetTriple();
+ if (!TT.isAMDGCN())
+ return true;
----------------
arsenm wrote:
Remove this. This should be done universally and you can't have triple checks
https://github.com/llvm/llvm-project/pull/169735
More information about the llvm-commits
mailing list