[llvm-commits] [llvm] r128380 - /llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp

Benjamin Kramer benny.kra at googlemail.com
Sun Mar 27 08:04:38 PDT 2011


Author: d0k
Date: Sun Mar 27 10:04:38 2011
New Revision: 128380

URL: http://llvm.org/viewvc/llvm-project?rev=128380&view=rev
Log:
Use APInt's umul_ov instead of rolling our own overflow detection.

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp?rev=128380&r1=128379&r2=128380&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp Sun Mar 27 10:04:38 2011
@@ -487,14 +487,15 @@
     APInt RHSKnownOne(BitWidth, 0);
     ComputeMaskedBits(RHS, Mask, RHSKnownZero, RHSKnownOne);
 
-    // Get the largest possible values for each operand, extended to be large
-    // enough so that every possible product of two BitWidth-sized ints fits.
-    APInt LHSMax = (~LHSKnownZero).zext(BitWidth*2);
-    APInt RHSMax = (~RHSKnownZero).zext(BitWidth*2);
+    // Get the largest possible values for each operand.
+    APInt LHSMax = ~LHSKnownZero;
+    APInt RHSMax = ~RHSKnownZero;
 
     // If multiplying the maximum values does not overflow then we can turn
     // this into a plain NUW mul.
-    if ((LHSMax * RHSMax).getActiveBits() <= BitWidth) {
+    bool Overflow;
+    LHSMax.umul_ov(RHSMax, Overflow);
+    if (!Overflow) {
       Value *Mul = Builder->CreateNUWMul(LHS, RHS, "umul_with_overflow");
       Constant *V[] = {
         UndefValue::get(LHS->getType()),





More information about the llvm-commits mailing list