summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-11-05 07:40:31 +0000
committerChris Lattner <sabre@nondot.org>2005-11-05 07:40:31 +0000
commitdd0c174082eda6cf40ae58c8218b43b253214e92 (patch)
tree0522e20c364252b045a490318fd4f4b693515beb /llvm/lib/Transforms
parente9ff0eaf5b025b630ae1d1fa73a6c757a8223184 (diff)
downloadbcm5719-llvm-dd0c174082eda6cf40ae58c8218b43b253214e92.tar.gz
bcm5719-llvm-dd0c174082eda6cf40ae58c8218b43b253214e92.zip
Turn sdiv into udiv if both operands have a clear sign bit. This occurs
a few times in crafty: OLD: %tmp.36 = div int %tmp.35, 8 ; <int> [#uses=1] NEW: %tmp.36 = div uint %tmp.35, 8 ; <uint> [#uses=0] OLD: %tmp.19 = div int %tmp.18, 8 ; <int> [#uses=1] NEW: %tmp.19 = div uint %tmp.18, 8 ; <uint> [#uses=0] OLD: %tmp.117 = div int %tmp.116, 8 ; <int> [#uses=1] NEW: %tmp.117 = div uint %tmp.116, 8 ; <uint> [#uses=0] OLD: %tmp.92 = div int %tmp.91, 8 ; <int> [#uses=1] NEW: %tmp.92 = div uint %tmp.91, 8 ; <uint> [#uses=0] Which all turn into shrs. llvm-svn: 24190
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/InstructionCombining.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
index 4a764c996d7..1164fb2e03e 100644
--- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -1240,6 +1240,25 @@ Instruction *InstCombiner::visitDiv(BinaryOperator &I) {
if (LHS->equalsInt(0))
return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
+ if (I.getType()->isSigned()) {
+ // If the top bits of both operands are zero (i.e. we can prove they are
+ // unsigned inputs), turn this into a udiv.
+ ConstantIntegral *MaskV = ConstantSInt::getMinValue(I.getType());
+ if (MaskedValueIsZero(Op1, MaskV) && MaskedValueIsZero(Op0, MaskV)) {
+ const Type *NTy = Op0->getType()->getUnsignedVersion();
+ Instruction *LHS = new CastInst(Op0, NTy, Op0->getName());
+ InsertNewInstBefore(LHS, I);
+ Value *RHS;
+ if (Constant *R = dyn_cast<Constant>(Op1))
+ RHS = ConstantExpr::getCast(R, NTy);
+ else
+ RHS = InsertNewInstBefore(new CastInst(Op1, NTy, Op1->getName()), I);
+ Instruction *Div = BinaryOperator::createDiv(LHS, RHS, I.getName());
+ InsertNewInstBefore(Div, I);
+ return new CastInst(Div, I.getType());
+ }
+ }
+
return 0;
}
OpenPOWER on IntegriCloud