diff options
author | Owen Anderson <resistor@mac.com> | 2010-07-14 23:33:51 +0000 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2010-07-14 23:33:51 +0000 |
commit | bd129a746058dc5d8da089f1351ff417de3114e7 (patch) | |
tree | 0c809169211f9fc5c468c9c0550cdc42fe0bf235 /lib/Transforms/InstCombine/InstCombineSelect.cpp | |
parent | 14904ce25ccca82ef23b53274f48057d65417ef5 (diff) |
Add instcombine transforms to optimize tests of multiple bits of the same value into a single larger comparison.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@108378 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/InstCombine/InstCombineSelect.cpp')
-rw-r--r-- | lib/Transforms/InstCombine/InstCombineSelect.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineSelect.cpp b/lib/Transforms/InstCombine/InstCombineSelect.cpp index c44fe9db6e..c85d74ad7d 100644 --- a/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -699,6 +699,31 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) { SI.setOperand(2, TrueVal); return &SI; } + + // select (or (A == 0) (B == 0)) T, F--> select (and (A != 0) (B != 0)) F, T + // Note: This is a canonicalization rather than an optimization, and is used + // to expose opportunities to other instcombine transforms. + Instruction* CondInst = dyn_cast<Instruction>(CondVal); + if (CondInst && CondInst->getOpcode() == Instruction::Or) { + ICmpInst *LHSCmp = dyn_cast<ICmpInst>(CondInst->getOperand(0)); + ICmpInst *RHSCmp = dyn_cast<ICmpInst>(CondInst->getOperand(1)); + if (LHSCmp && LHSCmp->getPredicate() == ICmpInst::ICMP_EQ && + RHSCmp && RHSCmp->getPredicate() == ICmpInst::ICMP_EQ) { + ConstantInt* C1 = dyn_cast<ConstantInt>(LHSCmp->getOperand(1)); + ConstantInt* C2 = dyn_cast<ConstantInt>(RHSCmp->getOperand(1)); + if (C1 && C1->isZero() && C2 && C2->isZero()) { + LHSCmp->setPredicate(ICmpInst::ICMP_NE); + RHSCmp->setPredicate(ICmpInst::ICMP_NE); + Value *And = + InsertNewInstBefore(BinaryOperator::CreateAnd(LHSCmp, RHSCmp, + "and."+CondVal->getName()), SI); + SI.setOperand(0, And); + SI.setOperand(1, FalseVal); + SI.setOperand(2, TrueVal); + return &SI; + } + } + } return 0; } |