[PATCH] Teach ComputeNumSignBits about signed divisions

David Majnemer david.majnemer at gmail.com
Tue Mar 3 13:18:25 PST 2015


REPOSITORY
  rL LLVM

================
Comment at: ../llvm/lib/Analysis/ValueTracking.cpp:1738
@@ +1737,3 @@
+      // Add floor(log(c)) bits.
+      return NumBits + Denominator->logBase2();
+    }
----------------
I think this result can become larger than the bitwidth if your numerator is very small and your denominator is very large.

Arithmetically, the result of such a division would be zero but we might not have simplified it yet.

An example of this would be 

%and = and i32 %x, 1
%div = sdiv i32 %and, 1073741824

The number of sign bits in %and is 31 and they are all zero.
The log-base2 of the denominator is 30.  I don't think the answer coming from this query cannot be larger than the bitwdith.

http://reviews.llvm.org/D8028

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the llvm-commits mailing list