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 | 8aff4f8efcd2e9b44f03744da66222accf9e790c (patch) | |
tree | 44d02e09ac76b5a70ff18e9ba3eca626188125e0 /llvm/lib/Transforms | |
parent | f5199debc0fabb30dff6367a62f70b2af1efea12 (diff) | |
download | bcm5719-llvm-8aff4f8efcd2e9b44f03744da66222accf9e790c.tar.gz bcm5719-llvm-8aff4f8efcd2e9b44f03744da66222accf9e790c.zip |
Transform any logical shift of a power of two into an exact/NUW shift when
in a known-non-zero context.
llvm-svn: 131887
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp index fdec6407b80..f3d10611ad2 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp +++ b/llvm/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; |