diff options
author | Chris Lattner <sabre@nondot.org> | 2011-05-23 00:21:50 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2011-05-23 00:21:50 +0000 |
commit | 05cd88656135255b545d24adb51c2ba1b5c8b99e (patch) | |
tree | 53a1eb6bec56af7222ee7474e48071b2af22f2bc /lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | |
parent | f415d8b64687d4db7e1986b74e9da6cae72c0fd1 (diff) |
Transform any logical shift of a power of two into an exact/NUW shift when
in a known-non-zero context.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131887 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/InstCombine/InstCombineMulDivRem.cpp')
-rw-r--r-- | lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp index fdec6407b8..f3d10611ad 100644 --- a/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp +++ b/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp @@ -29,6 +29,23 @@ static Value *simplifyValueKnownNonZero(Value *V, InstCombiner &IC) { // code. if (!V->hasOneUse()) return 0; + + // (PowerOfTwo >>u B) --> isExact since shifting out the result would make it + // inexact. Similarly for <<. + if (BinaryOperator *I = dyn_cast<BinaryOperator>(V)) + if (I->isLogicalShift() && + isPowerOfTwo(I->getOperand(0), IC.getTargetData())) { + if (I->getOpcode() == Instruction::LShr && !I->isExact()) { + I->setIsExact(); + return I; + } + + if (I->getOpcode() == Instruction::Shl && !I->hasNoUnsignedWrap()) { + I->setHasNoUnsignedWrap(); + return I; + } + } + // ((1 << A) >>u B) --> (1 << (A-B)) // Because V cannot be zero, we know that B is less than A. Value *A = 0, *B = 0, *PowerOf2 = 0; |