diff options
author | Chris Lattner <sabre@nondot.org> | 2004-09-27 16:18:50 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-09-27 16:18:50 +0000 |
commit | f63f647345d0305685e837ad7d89181ea643c2e2 (patch) | |
tree | b28e2cc1ace8e18469b078cfab1a11b457a9f1d9 /lib/Transforms | |
parent | a281b6fa6466c6a9cbd60008edc1681fc58a5eb7 (diff) | |
download | external_llvm-f63f647345d0305685e837ad7d89181ea643c2e2.zip external_llvm-f63f647345d0305685e837ad7d89181ea643c2e2.tar.gz external_llvm-f63f647345d0305685e837ad7d89181ea643c2e2.tar.bz2 |
Fold: (setcc (shr X, ShAmt), CI), where 'cc' is eq or ne. This xform
triggers often, for example:
6x in povray, 1x in gzip, 279x in gcc, 1x in crafty, 8x in eon, 11x in perlbmk,
362x in gap, 4x in vortex, 14 in m88ksim, 211x in 126.gcc, 1x in compress,
11x in ijpeg, and 4x in 147.vortex.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16521 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index e579cf1..cdfdc34 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -1545,6 +1545,51 @@ Instruction *InstCombiner::visitSetCondInst(BinaryOperator &I) { } } break; + case Instruction::Shr: // shr: (setcc (shr X, ShAmt), CI) + if (ConstantUInt *ShAmt = dyn_cast<ConstantUInt>(LHSI->getOperand(1))) { + unsigned ShAmtVal = ShAmt->getValue(); + + switch (I.getOpcode()) { + default: break; + case Instruction::SetEQ: + case Instruction::SetNE: { + // If we are comparing against bits always shifted out, the + // comparison cannot succeed. + Constant *Comp = + ConstantExpr::getShr(ConstantExpr::getShl(CI, ShAmt), ShAmt); + + if (Comp != CI) {// Comparing against a bit that we know is zero. + bool IsSetNE = I.getOpcode() == Instruction::SetNE; + Constant *Cst = ConstantBool::get(IsSetNE); + return ReplaceInstUsesWith(I, Cst); + } + + if (LHSI->hasOneUse() || CI->isNullValue()) { + // Otherwise strength reduce the shift into an and. + uint64_t Val = ~0ULL; // All ones. + Val <<= ShAmtVal; // Shift over to the right spot. + + Constant *Mask; + if (CI->getType()->isUnsigned()) { + unsigned TypeBits = CI->getType()->getPrimitiveSize()*8; + Val &= (1ULL << TypeBits)-1; + Mask = ConstantUInt::get(CI->getType(), Val); + } else { + Mask = ConstantSInt::get(CI->getType(), Val); + } + + Instruction *AndI = + BinaryOperator::createAnd(LHSI->getOperand(0), + Mask, LHSI->getName()+".mask"); + Value *And = InsertNewInstBefore(AndI, I); + return new SetCondInst(I.getOpcode(), And, + ConstantExpr::getShl(CI, ShAmt)); + } + break; + } + } + } + break; case Instruction::Div: if (0 && isa<ConstantInt>(LHSI->getOperand(1))) { |