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

Matt Arsenault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 7 12:13:19 PDT 2023


arsenm added a comment.

In D154678#4481361 <https://reviews.llvm.org/D154678#4481361>, @goldstein.w.n wrote:

> Working on adding `ldexp` to backend, but notice that we lose the important information that `exp <= Type->getScalarSizeInBits()`

The useful exponent range is limited by ldexp. The only useful values are between -exp_min - mantissa size to exp_max, outside of that it saturates to 0/inf.

> We can't propagate an assume to the backend either.
> Think to do this, need to add a flag to `ldexp` if `exp` is log of some sort (allows us to reason about whether it may cause denorm/etc).

The exp is interpreted as the log value.

> What do you think?
>
> Edit:
> We lose also information about whether this is for `fdiv` or `fmul` which makes the bounds more constrained, although this is probably less important.

Does that matter? Can we unconditionally turn fdiv into fmul if the divisor is known to be an exact power of 2?

I do think fmul with power of 2 constant in the general case should be more canonical than ldexp. We should turn ldexp with constant exponent into fmuls, and back into ldexp if the target wants.


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