Return undef on FP <-> Int conversions that overflow (PR21330).
authorSanjay Patel <spatel@rotateright.com>
Fri, 10 Oct 2014 23:00:21 +0000 (23:00 +0000)
committerSanjay Patel <spatel@rotateright.com>
Fri, 10 Oct 2014 23:00:21 +0000 (23:00 +0000)
commitadd74ff5fff48ef66b1b6133f2093079cdb42af1
treecad0c336bf67632c20d03c20cad4f4fd349fb51a
parentfab0a999d744f8440b36a28ea374c5924062de0a
Return undef on FP <-> Int conversions that overflow (PR21330).

The LLVM Lang Ref states for signed/unsigned int to float conversions:
"If the value cannot fit in the floating point value, the results are undefined."

And for FP to signed/unsigned int:
"If the value cannot fit in ty2, the results are undefined."

This matches the C definitions.

The existing behavior pins to infinity or a max int value, but that may just
lead to more confusion as seen in:
http://llvm.org/bugs/show_bug.cgi?id=21130

Returning undef will hopefully lead to a less silent failure.

Differential Revision: http://reviews.llvm.org/D5603

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219542 91177308-0d34-0410-b5e6-96231b3b80d8
lib/IR/ConstantFold.cpp
test/Transforms/InstCombine/cast.ll