diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2011-03-27 15:04:38 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2011-03-27 15:04:38 +0000 |
commit | 1f90da127f7f2b882ac8bd25e45a4e7b0b359b20 (patch) | |
tree | 651a7bc545c2c738bed4b38f90fa50c5fd3455f4 /llvm/lib/Transforms | |
parent | 0bb2ad2cf7f8032492401d82e0cb6be6b98406a0 (diff) | |
download | bcm5719-llvm-1f90da127f7f2b882ac8bd25e45a4e7b0b359b20.tar.gz bcm5719-llvm-1f90da127f7f2b882ac8bd25e45a4e7b0b359b20.zip |
Use APInt's umul_ov instead of rolling our own overflow detection.
llvm-svn: 128380
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp index b5fd0b9af40..875e9cae582 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -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()), |