[llvm] Optimize fptrunc(x)>=C1 --> x>=C2 (PR #99475)

Alexis Engelke via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 25 02:06:05 PDT 2024


aengelke wrote:

> It seems that the double type the fp constant converted to can express the same value with float type without lossing accuracy. The rmNearestTiesToEven has already been applied, and no difference appeared.🫣

It's the opposite direction that is problematic. Consider input `99.99999999`. After the fptrunc, it will be value `100.0f`, which is >= 100.0f. But `99.99999999` is not >= `100.0`. You need to find the smallest(/largest) value of the larger floating-point type which, after truncation, is satisfies the condition.

The [contributor guide](https://llvm.org/docs/InstCombineContributorGuide.html) also says that you should provide alive2 proofs that your transformation is correct. I provided a proof above that the transformation as implemented/tested now is not correct.

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


More information about the llvm-commits mailing list