[llvm] Update foldFMulReassoc to respect absent fast-math flags (PR #88589)

Andy Kaylor via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 16 16:20:30 PDT 2024


andykaylor wrote:

> It kind of would be nice if we could get a matcher that checked the FMF flags of everything in the chain of instructions, but I don't think the matcher infrastructure is set up in a way that makes such a thing possible.

I thought about that, but I don't think we necessarily want to check everything in the chain. Consider this expression:

`match(&I, m_c_FMul(m_AllowReassoc(m_OneUse(m_FDiv(m_Value(X), m_Value(Y)))), m_Value(Z)))`

This is used for the `(X / Y) * Z ==> (X * Z) / Y` transformation. We need reassociation to be enabled on the multiplication and division operations, but we don't need it on whatever X, Y, and Z are. If you're willing to say that we aren't examining X, Y, and Z beyond the fact that they're values, then I think what you're suggesting would be good.

So, maybe something like this?

```
matchFMF(&I, FastMathFlags::AllowReassoc,
         m_c_FMul((m_OneUse(m_FDiv(m_Value(X), m_Value(Y)))), m_Value(Z)))
```
Then if something being matched is an FPMathOperator we check fast math flags, but if it isn't explicitly so in the match expression we don't. Is that what you had in mind?

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


More information about the llvm-commits mailing list