[PATCH] D44909: [DAGCombine] (float)((int) f) --> ftrunc (PR36617)

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 11 09:12:01 PDT 2018


spatel added a comment.

In https://reviews.llvm.org/D44909#1128334, @spatel wrote:

> In https://reviews.llvm.org/D44909#1126945, @rdhindsa wrote:
>
> > What is the expected behavior for casting float values in range (-1.0 , 0.0) from float->int->float? If the expected value is -0.0 (instead of 0.0), what is the reason for that?
>
>
> Not sure I understand the question. Casting FP (-1.0, 0.0) to int with round-to-zero mode results in integer 0. Converting that back to FP is always 0.0.


Ah, I see - we get this wrong because we may now produce -0.0 instead of 0.0.

Ie, trunc(), ISD::FTRUNC, and presumably all of the hardware instructions that map to those ops play by the IEEE754 rounding rules:
"These operations convert zero operands to zero results of the same sign."

So we can't do this without 'nsz', right?


Repository:
  rL LLVM

https://reviews.llvm.org/D44909





More information about the llvm-commits mailing list