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 | d655e6e9dc0d21c3a2d76494dec255bb027572ae (patch) | |
tree | 3471f5ec96358f73177c6d13debe9f7b18c64484 | |
parent | 6208610fd602ebdb18bb793152899573d0b2b7ab (diff) | |
download | external_llvm-d655e6e9dc0d21c3a2d76494dec255bb027572ae.zip external_llvm-d655e6e9dc0d21c3a2d76494dec255bb027572ae.tar.gz external_llvm-d655e6e9dc0d21c3a2d76494dec255bb027572ae.tar.bz2 |
Use APInt's umul_ov instead of rolling our own overflow detection.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128380 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Transforms/InstCombine/InstCombineCalls.cpp | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineCalls.cpp b/lib/Transforms/InstCombine/InstCombineCalls.cpp index b5fd0b9..875e9ca 100644 --- a/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/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()), |