summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-01-05 18:09:56 +0000
committerChris Lattner <sabre@nondot.org>2010-01-05 18:09:56 +0000
commit54f4e39956577c1e3ba75697ffd135e9fdb56d9b (patch)
tree3108807cb8cf30aa3e8fd5fd3364ee751fd2560e /llvm/lib/Transforms
parent7bf01ea165fa61605e9a9fbf3da33c15a560e3e8 (diff)
downloadbcm5719-llvm-54f4e39956577c1e3ba75697ffd135e9fdb56d9b.tar.gz
bcm5719-llvm-54f4e39956577c1e3ba75697ffd135e9fdb56d9b.zip
optimize comparisons against cttz/ctlz/ctpop, patch by Alastair Lynn!
llvm-svn: 92745
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp24
1 files changed, 23 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 90ab4f43df0..abbc89b0a10 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -1418,11 +1418,33 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
}
} else if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(LHSI)) {
// Handle icmp {eq|ne} <intrinsic>, intcst.
- if (II->getIntrinsicID() == Intrinsic::bswap) {
+ switch (II->getIntrinsicID()) {
+ case Intrinsic::bswap:
Worklist.Add(II);
ICI.setOperand(0, II->getOperand(1));
ICI.setOperand(1, ConstantInt::get(II->getContext(), RHSV.byteSwap()));
return &ICI;
+ case Intrinsic::ctlz:
+ case Intrinsic::cttz:
+ // ctz(A) == bitwidth(a) -> A == 0 and likewise for !=
+ if (RHSV == RHS->getType()->getBitWidth()) {
+ Worklist.Add(II);
+ ICI.setOperand(0, II->getOperand(1));
+ ICI.setOperand(1, ConstantInt::get(RHS->getType(), 0));
+ return &ICI;
+ }
+ break;
+ case Intrinsic::ctpop:
+ // popcount(A) == 0 -> A == 0 and likewise for !=
+ if (RHS->isZero()) {
+ Worklist.Add(II);
+ ICI.setOperand(0, II->getOperand(1));
+ ICI.setOperand(1, RHS);
+ return &ICI;
+ }
+ break;
+ default:
+ break;
}
}
}
OpenPOWER on IntegriCloud