[llvm-commits] [llvm] r59400 - /llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
Chris Lattner
sabre at nondot.org
Sat Nov 15 21:10:52 PST 2008
Author: lattner
Date: Sat Nov 15 23:10:52 2008
New Revision: 59400
URL: http://llvm.org/viewvc/llvm-project?rev=59400&view=rev
Log:
merge a check into a place where it is simpler.
Modified:
llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=59400&r1=59399&r2=59400&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Sat Nov 15 23:10:52 2008
@@ -3556,15 +3556,28 @@
/// FoldAndOfICmps - Fold (icmp)&(icmp) if possible.
Instruction *InstCombiner::FoldAndOfICmps(Instruction &I,
ICmpInst *LHS, ICmpInst *RHS) {
- Value *Val;
+ Value *Val, *Val2;
ConstantInt *LHSCst, *RHSCst;
ICmpInst::Predicate LHSCC, RHSCC;
- // (icmp1 A, C1) & (icmp2 A, C2) --> something simpler.
+ // This only handles icmp of constants: (icmp1 A, C1) & (icmp2 B, C2).
if (!match(LHS, m_ICmp(LHSCC, m_Value(Val), m_ConstantInt(LHSCst))) ||
- !match(RHS, m_ICmp(RHSCC, m_Specific(Val), m_ConstantInt(RHSCst))))
+ !match(RHS, m_ICmp(RHSCC, m_Value(Val2), m_ConstantInt(RHSCst))))
return 0;
-
+
+ // (icmp ult A, C) & (icmp ult B, C) --> (icmp ult (A|B), C)
+ // where C is a power of 2
+ if (LHSCst == RHSCst && LHSCC == RHSCC && LHSCC == ICmpInst::ICMP_ULT &&
+ LHSCst->getValue().isPowerOf2()) {
+ Instruction *NewOr = BinaryOperator::CreateOr(Val, Val2);
+ InsertNewInstBefore(NewOr, I);
+ return new ICmpInst(LHSCC, NewOr, LHSCst);
+ }
+
+ // From here on, we only handle:
+ // (icmp1 A, C1) & (icmp2 A, C2) --> something simpler.
+ if (Val != Val2) return 0;
+
// ICMP_[US][GL]E X, CST is folded to ICMP_[US][GL]T elsewhere.
if (LHSCC == ICmpInst::ICMP_UGE || LHSCC == ICmpInst::ICMP_ULE ||
RHSCC == ICmpInst::ICMP_UGE || RHSCC == ICmpInst::ICMP_ULE ||
@@ -3931,22 +3944,6 @@
}
}
- { // (icmp ult A, C) & (icmp ult B, C) --> (icmp ult (A|B), C)
- // where C is a power of 2
- Value *A, *B;
- ConstantInt *C1, *C2;
- ICmpInst::Predicate LHSCC = ICmpInst::BAD_ICMP_PREDICATE;
- ICmpInst::Predicate RHSCC = ICmpInst::BAD_ICMP_PREDICATE;
- 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 && LHSCC == ICmpInst::ICMP_ULT &&
- C1->getValue().isPowerOf2()) {
- 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)))
More information about the llvm-commits
mailing list