[PATCH] D87479: [InstCombine] Don't sink the fdiv from (fmul (fdiv 1.0, %x), %y) if the fdiv isn't in the same basic block as the fmul
Craig Topper via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 13 15:34:09 PST 2023
craig.topper added inline comments.
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp:531
- Value *Z;
- if (match(&I, m_c_FMul(m_OneUse(m_FDiv(m_Value(X), m_Value(Y))),
- m_Value(Z)))) {
- // Sink division: (X / Y) * Z --> (X * Z) / Y
- Value *NewFMul = Builder.CreateFMulFMF(X, Z, &I);
+ // Sink division: (X / Y) * Z --> (X * Z) / Y
+ // Don't sink if the fdiv is a reciprocal in a different basic block as this
----------------
spatel wrote:
> craig.topper wrote:
> > I found another variation of this
> >
> > (X/Y) outside loop
> > Mul with Z inside loop.
> >
> > ->
> >
> > X*Z ends up inside loop
> > / Y ends up in loop
> >
> > ->
> >
> > recip of Y outside loop
> >
> > X*Z in loop
> > mul with reciprocal of Y inside loop.
> >
> >
> >
> >
> > So we went from an fdiv outside loop and one fmul inside the loop to 1 div outside the loop and 2 fmuls inside the loop.
> Does this model it:
> https://godbolt.org/z/W4Ta9jzEn ?
> ...although MachineLICM is managing to pull the fmuls out of the loop there, so there must be some other complication?
MachineLICM doesn't fix it on pure scalar.
https://godbolt.org/z/zGvxxqaTP
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D87479/new/
https://reviews.llvm.org/D87479
More information about the llvm-commits
mailing list