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 ; [#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

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

Yes. If you're interested in improving this, folding it to undef would be better than to 0.

-Chris