aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2008-07-09 07:29:11 +0000
committerNick Lewycky <nicholas@mxc.ca>2008-07-09 07:29:11 +0000
commit9ee863ecc00ff191bfec3f1421d80b41989f4413 (patch)
tree05b966209bbd8d3a72fcf2d780ce14acbe9ea921 /lib/Transforms
parent1afe5c3ff8f37a94e47379ff9535b5e03faca020 (diff)
Fold (a < 8) && (b < 8) into (a|b) < 8 for unsigned less or greater than.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53282 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 27af3c397a..8d35bb5af0 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -3594,6 +3594,22 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
}
}
+
+ { // (icmp ugt/ult A, C) & (icmp B, C) --> (icmp (A|B), C)
+ // where C is a power of 2
+ Value *A, *B;
+ ConstantInt *C1, *C2;
+ ICmpInst::Predicate LHSCC, RHSCC;
+ if (match(&I, m_And(m_ICmp(LHSCC, m_Value(A), m_ConstantInt(C1)),
+ m_ICmp(RHSCC, m_Value(B), m_ConstantInt(C2)))))
+ if (C1 == C2 && LHSCC == RHSCC && C1->getValue().isPowerOf2() &&
+ (LHSCC == ICmpInst::ICMP_ULT || LHSCC == ICmpInst::ICMP_UGT)) {
+ Instruction *NewOr = BinaryOperator::CreateOr(A, B);
+ InsertNewInstBefore(NewOr, I);
+ return new ICmpInst(LHSCC, NewOr, C1);
+ }
+ }
+
if (ICmpInst *RHS = dyn_cast<ICmpInst>(Op1)) {
// (icmp1 A, B) & (icmp2 A, B) --> (icmp3 A, B)
if (Instruction *R = AssociativeOpt(I, FoldICmpLogical(*this, RHS)))