[llvm] [InstCombine] Canonicalize reassoc contract fmuladd to fmul + fadd (PR #90434)

Joshua Cranmer via llvm-commits llvm-commits at lists.llvm.org
Mon May 6 11:26:21 PDT 2024


jcranmer-intel wrote:

> According to https://llvm.org/docs/LangRef.html#fast-math-flags, I think only contract and reassoc is required for this transformation. a) contract: fusing a multiply followed by an addition into a fused multiply-and-add b) reassoc: reassociation transformations when there may be other fp operations.

This isn't covered well by any of the existing flags. `fmuladd` is basically "`fma`, but if there's no hardware instruction, give me `fmul + fadd` instead". `contract` generally implies a one-way transformation to a better form, so `contract fma` can't yield `fmul + fadd`. But also, as arsenm notes, `contract fmul + fadd` also allows more transformations than just forming `fma`; `fmuladd` implies just a single possible transformation, hence why a separate intrinsic is needed.

Thinking in my head through every possibility, `contract` should be the only flag needed to allow `fmuladd` to be represented as `fma`; `reassoc` is irrelevant.

In any case, you should also have tests for the propagation of non-necessary FMF flags to the expanded instructions.

https://github.com/llvm/llvm-project/pull/90434


More information about the llvm-commits mailing list