Use APInt's umul_ov instead of rolling our own overflow detection.
authorBenjamin Kramer <benny.kra@googlemail.com>
Sun, 27 Mar 2011 15:04:38 +0000 (15:04 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Sun, 27 Mar 2011 15:04:38 +0000 (15:04 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128380 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstCombineCalls.cpp

index b5fd0b9af40854ffc94c6efb836fb5b0b5c5e87a..875e9cae58268c20431f2f88d36ca32cce500b15 100644 (file)
@@ -487,14 +487,15 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
     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()),