summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2008-07-09 05:20:13 +0000
committerNick Lewycky <nicholas@mxc.ca>2008-07-09 05:20:13 +0000
commit364661c43e6b6dbe6ca2f01b2aaa031139e02153 (patch)
tree457b0fbcf90a296badb3cb4aaf1f2c31dabeb983 /llvm/lib/Transforms
parenta660f4bb07e5a8cf446b00c498c8c4c1ec28a447 (diff)
downloadbcm5719-llvm-364661c43e6b6dbe6ca2f01b2aaa031139e02153.tar.gz
bcm5719-llvm-364661c43e6b6dbe6ca2f01b2aaa031139e02153.zip
Fold ((1 << a) & 1) to (a == 0).
llvm-svn: 53276
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/InstructionCombining.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
index 675f7ec5714..27af3c397a1 100644
--- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -3473,6 +3473,18 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
}
break;
+
+ case Instruction::Shl:
+ case Instruction::LShr:
+ // (1 << x) & 1 --> zext(x == 0)
+ // (1 >> x) & 1 --> zext(x == 0)
+ if (AndRHSMask.getLimitedValue() == 1 && Op0LHS == AndRHS) {
+ Instruction *NewICmp = new ICmpInst(ICmpInst::ICMP_EQ, Op0RHS,
+ Constant::getNullValue(I.getType()));
+ InsertNewInstBefore(NewICmp, I);
+ return new ZExtInst(NewICmp, I.getType());
+ }
+ break;
}
if (ConstantInt *Op0CI = dyn_cast<ConstantInt>(Op0I->getOperand(1)))
OpenPOWER on IntegriCloud