aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-09-19 19:05:02 +0000
committerChris Lattner <sabre@nondot.org>2003-09-19 19:05:02 +0000
commit62a355cc6e5bc37a55ce378725eefdd74e676084 (patch)
tree676abb76b37a0fdbc7abf5c6a4097aa79389593e /lib/Transforms
parent0daee350cf4d2f6a3a3c2edd6e3efe8a8a8795b7 (diff)
Implement InstCombine/and.ll:test(15|16)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8607 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index daa943ca1e..787c1a5caa 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -798,6 +798,33 @@ Instruction *InstCombiner::OptAndOp(Instruction *Op,
}
}
break;
+
+ case Instruction::Shl: {
+ // We know that the AND will not produce any of the bits shifted in, so if
+ // the anded constant includes them, clear them now!
+ //
+ Constant *AllOne = ConstantIntegral::getAllOnesValue(AndRHS->getType());
+ Constant *CI = *AndRHS & *(*AllOne << *OpRHS);
+ if (CI != AndRHS) {
+ TheAnd.setOperand(1, CI);
+ return &TheAnd;
+ }
+ break;
+ }
+ case Instruction::Shr:
+ // We know that the AND will not produce any of the bits shifted in, so if
+ // the anded constant includes them, clear them now! This only applies to
+ // unsigned shifts, because a signed shr may bring in set bits!
+ //
+ if (AndRHS->getType()->isUnsigned()) {
+ Constant *AllOne = ConstantIntegral::getAllOnesValue(AndRHS->getType());
+ Constant *CI = *AndRHS & *(*AllOne >> *OpRHS);
+ if (CI != AndRHS) {
+ TheAnd.setOperand(1, CI);
+ return &TheAnd;
+ }
+ }
+ break;
}
return 0;
}