diff options
author | Chris Lattner <sabre@nondot.org> | 2010-01-05 18:09:56 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-01-05 18:09:56 +0000 |
commit | 033574074d3c980057a0cb989d272ec72a8f9523 (patch) | |
tree | da014c262456114da3d4259f2bd4509515327f17 /lib/Transforms/InstCombine/InstCombineCompares.cpp | |
parent | aceba31b7a04fd28680209b2677915378877bc13 (diff) | |
download | external_llvm-033574074d3c980057a0cb989d272ec72a8f9523.tar.gz external_llvm-033574074d3c980057a0cb989d272ec72a8f9523.tar.bz2 external_llvm-033574074d3c980057a0cb989d272ec72a8f9523.zip |
optimize comparisons against cttz/ctlz/ctpop, patch by Alastair Lynn!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92745 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/InstCombine/InstCombineCompares.cpp')
-rw-r--r-- | lib/Transforms/InstCombine/InstCombineCompares.cpp | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineCompares.cpp b/lib/Transforms/InstCombine/InstCombineCompares.cpp index 90ab4f43df..abbc89b0a1 100644 --- a/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/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; } } } |