summaryrefslogtreecommitdiff
path: root/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2010-07-14 23:33:51 +0000
committerOwen Anderson <resistor@mac.com>2010-07-14 23:33:51 +0000
commitbd129a746058dc5d8da089f1351ff417de3114e7 (patch)
tree0c809169211f9fc5c468c9c0550cdc42fe0bf235 /lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
parent14904ce25ccca82ef23b53274f48057d65417ef5 (diff)
downloadllvm-bd129a746058dc5d8da089f1351ff417de3114e7.tar.gz
llvm-bd129a746058dc5d8da089f1351ff417de3114e7.tar.bz2
llvm-bd129a746058dc5d8da089f1351ff417de3114e7.tar.xz
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/InstCombineAndOrXor.cpp')
-rw-r--r--lib/Transforms/InstCombine/InstCombineAndOrXor.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
index 3f4a857c41..57cd76dab0 100644
--- a/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -472,6 +472,24 @@ Value *InstCombiner::FoldAndOfICmps(ICmpInst *LHS, ICmpInst *RHS) {
Value *NewOr = Builder->CreateOr(Val, Val2);
return Builder->CreateICmp(LHSCC, NewOr, LHSCst);
}
+
+ // (icmp ne (A & C1) 0) & (icmp ne (A & C2), 0) -->
+ // (icmp eq (A & (C1|C2)), (C1|C2))
+ if (LHSCC == ICmpInst::ICMP_NE && LHSCst->isZero()) {
+ Instruction *I1 = dyn_cast<Instruction>(Val);
+ Instruction *I2 = dyn_cast<Instruction>(Val2);
+ if (I1 && I1->getOpcode() == Instruction::And &&
+ I2 && I2->getOpcode() == Instruction::And &&
+ I1->getOperand(0) == I1->getOperand(0)) {
+ ConstantInt *CI1 = dyn_cast<ConstantInt>(I1->getOperand(1));
+ ConstantInt *CI2 = dyn_cast<ConstantInt>(I2->getOperand(1));
+ if (CI1 && CI2) {
+ Constant *ConstOr = ConstantExpr::getOr(CI1, CI2);
+ Value *NewAnd = Builder->CreateAnd(I1->getOperand(0), ConstOr);
+ return Builder->CreateICmp(ICmpInst::ICMP_EQ, NewAnd, ConstOr);
+ }
+ }
+ }
}
// From here on, we only handle: