Zheng, Bixia
2009-Dec-07 23:51 UTC
[LLVMdev] a constant folding case causing different results w/ot optimization
Hi, The optimizer folds "(unsigned int) -1.0f" to 0. As a result, the following routine foo returns 0 with optimization, and returns -1 (0xffffffff) without optimization. unsigned int foo() { float myfloat = -1.0f; unsigned int myint = (unsigned int) myfloat; return myint; } INSTCOMBINE ITERATION #0 on IC: ConstFold to: i32 0 from: %conv = fptoui float -1.000000e+000 to i32 ; <i32> [#uses=1] While the result of "(unsigned int) -1.0f" is probably implementation defined, both gcc and Microsoft cl produce -1. Will you consider this an optimizer bug and fix it? Thanks, bixia -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20091207/b04a7a8f/attachment.html>
Eli Friedman
2009-Dec-08 00:50 UTC
[LLVMdev] a constant folding case causing different results w/ot optimization
On Mon, Dec 7, 2009 at 3:51 PM, Zheng, Bixia <Bixia.Zheng at amd.com> wrote:> While the result of â(unsigned int) -1.0fâ is probably implementation > defined, both gcc and Microsoft cl produce -1.LLVM (and C/C++) consider the result to be undefined (i.e. it can produce anything). And it can actually produce results other than -1 on some platforms supported by LLVM. So I don't see any good reason to choose your way of folding it over the current method. -Eli
Chris Lattner
2009-Dec-08 04:58 UTC
[LLVMdev] a constant folding case causing different results w/ot optimization
On Dec 7, 2009, at 4:50 PM, Eli Friedman wrote:> On Mon, Dec 7, 2009 at 3:51 PM, Zheng, Bixia <Bixia.Zheng at amd.com> wrote: >> While the result of â(unsigned int) -1.0fâ is probably implementation >> defined, both gcc and Microsoft cl produce -1. > > LLVM (and C/C++) consider the result to be undefined (i.e. it can > produce anything). And it can actually produce results other than -1 > on some platforms supported by LLVM. So I don't see any good reason > to choose your way of folding it over the current method.Yes. If you're interested in improving this, folding it to undef would be better than to 0. -Chris