[PATCH] D19178: Broaden FoldItoFPtoI to try and establish whether the integer value fits into the float type

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Mon May 9 19:07:58 PDT 2016


reames requested changes to this revision.
reames added a comment.
This revision now requires changes to proceed.

Comments inline.


================
Comment at: lib/Transforms/InstCombine/InstCombineCasts.cpp:1463
@@ +1462,3 @@
+    int MostSignificantPossiblySetBit = 0;
+    bool PossiblyNegative = IsInputSigned && !KnownZero[BitWidth - 1];
+    for(int i = BitWidth - PossiblyNegative - 1; i != 0; i--) {
----------------
This isn't what you want.  In particular, this doesn't produce a useful answer for any (known) positive number since you'll immediately exit the loop.

A better approach here is to look for a prefix which is known to be either zero or one.  (i.e. 0000 or 1111, not 0101.)  For a signed number, you can simply drop those bits entirely since the sign is encoded separately.  For an unsigned, you can only drop a zero prefix.  This can be written easily using countNumberOfLeadingX

================
Comment at: test/Transforms/InstCombine/sitofp.ll:192
@@ +191,3 @@
+define i32 @test20(i32 %A) nounwind {
+ %B = and i32 %A, 16777215
+ %C = sitofp i32 %B to float
----------------
Absolutely minimum testing you're going to need:
sitofp positive number in and out of range
sitofp negative number in and out of range
uitofp number in and out of range

All in the form of LIT tests.


http://reviews.llvm.org/D19178





More information about the llvm-commits mailing list