[PATCH] D154678: [InstCombine] Fold IEEE `fmul`/`fdiv` by Pow2 to `add`/`sub` of exp

Noah Goldstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 7 08:27:44 PDT 2023


goldstein.w.n added a comment.

In D154678#4480022 <https://reviews.llvm.org/D154678#4480022>, @arsenm wrote:

> My current thought is this is a worse canonical form for floating point operations and would be better done in codegen. This is going to interfere with FMA matching, plus computeKnownFPClass is going to give up on the integer ops and cast.

There a reason we can't handle bitcasts in `computeKnownFPClass` using knownbits from the integer type coming in?

I would agree with you if we were replacing the int-to-fp with a fp-to-int, but there is no float except for the constant until the `fdiv`/`fmul`.
is `fmul`/`fdiv` by constant really preferable to `add`/`sub` of a constant?

> This is also similar to a codegen combine I’ve been planning on doing to fold fmul by power of 2 to ldexp. That has the same FMA interference properties, but is easier to deal with. Have you considered introducing ldexp instead and breaking that in codegen if ldexp isn’t legal?

That does seem more principled. Then we get to remove all the casts.

is `(fmul/fdiv C, (uitofp Pow2))` directly equiv to `(ldexp C, Log2(Pow2))`?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154678/new/

https://reviews.llvm.org/D154678



More information about the llvm-commits mailing list