[llvm-commits] [llvm] r75255 - in /llvm/trunk: include/llvm/Support/NoFolder.h include/llvm/Support/PatternMatch.h lib/Transforms/Scalar/InstructionCombining.cpp lib/Transforms/Utils/AddrModeMatcher.cpp

Owen Anderson resistor at mac.com
Fri Jul 10 10:35:02 PDT 2009


Author: resistor
Date: Fri Jul 10 12:35:01 2009
New Revision: 75255

URL: http://llvm.org/viewvc/llvm-project?rev=75255&view=rev
Log:
Push LLVMContext through the PatternMatch API.

Modified:
    llvm/trunk/include/llvm/Support/NoFolder.h
    llvm/trunk/include/llvm/Support/PatternMatch.h
    llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
    llvm/trunk/lib/Transforms/Utils/AddrModeMatcher.cpp

Modified: llvm/trunk/include/llvm/Support/NoFolder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/NoFolder.h?rev=75255&r1=75254&r2=75255&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Support/NoFolder.h (original)
+++ llvm/trunk/include/llvm/Support/NoFolder.h Fri Jul 10 12:35:01 2009
@@ -30,7 +30,10 @@
 
 /// NoFolder - Create "constants" (actually, values) with no folding.
 class NoFolder {
+  LLVMContext &Context;
 public:
+  
+  NoFolder(LLVMContext &C) : Context(C) { }
 
   //===--------------------------------------------------------------------===//
   // Binary Operators
@@ -113,7 +116,7 @@
 
   Constant *CreateGetElementPtr(Constant *C, Constant* const *IdxList,
                                 unsigned NumIdx) const {
-    return ConstantExpr::getGetElementPtr(C, IdxList, NumIdx);
+    return Context.getConstantExprGetElementPtr(C, IdxList, NumIdx);
   }
   Value *CreateGetElementPtr(Constant *C, Value* const *IdxList,
                              unsigned NumIdx) const {

Modified: llvm/trunk/include/llvm/Support/PatternMatch.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/PatternMatch.h?rev=75255&r1=75254&r2=75255&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Support/PatternMatch.h (original)
+++ llvm/trunk/include/llvm/Support/PatternMatch.h Fri Jul 10 12:35:01 2009
@@ -31,19 +31,20 @@
 
 #include "llvm/Constants.h"
 #include "llvm/Instructions.h"
+#include "llvm/LLVMContext.h"
 
 namespace llvm {
 namespace PatternMatch {
 
 template<typename Val, typename Pattern>
-bool match(Val *V, const Pattern &P) {
-  return const_cast<Pattern&>(P).match(V);
+bool match(Val *V, const Pattern &P, LLVMContext &Context) {
+  return const_cast<Pattern&>(P).match(V, Context);
 }
 
 template<typename Class>
 struct leaf_ty {
   template<typename ITy>
-  bool match(ITy *V) { return isa<Class>(V); }
+  bool match(ITy *V, LLVMContext&) { return isa<Class>(V); }
 };
 
 /// m_Value() - Match an arbitrary value and ignore it.
@@ -54,7 +55,7 @@
 template<int64_t Val>
 struct constantint_ty {
   template<typename ITy>
-  bool match(ITy *V) {
+  bool match(ITy *V, LLVMContext&) {
     if (const ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
       const APInt &CIV = CI->getValue();
       if (Val >= 0)
@@ -77,7 +78,7 @@
 
 struct zero_ty {
   template<typename ITy>
-  bool match(ITy *V) {
+  bool match(ITy *V, LLVMContext&) {
     if (const Constant *C = dyn_cast<Constant>(V))
       return C->isNullValue();
     return false;
@@ -94,7 +95,7 @@
   bind_ty(Class *&V) : VR(V) {}
 
   template<typename ITy>
-  bool match(ITy *V) {
+  bool match(ITy *V, LLVMContext&) {
     if (Class *CV = dyn_cast<Class>(V)) {
       VR = CV;
       return true;
@@ -115,7 +116,7 @@
   specificval_ty(const Value *V) : Val(V) {}
 
   template<typename ITy>
-  bool match(ITy *V) {
+  bool match(ITy *V, LLVMContext&) {
     return V == Val;
   }
 };
@@ -137,15 +138,15 @@
   BinaryOp_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
 
   template<typename OpTy>
-  bool match(OpTy *V) {
+  bool match(OpTy *V, LLVMContext &Context) {
     if (V->getValueID() == Value::InstructionVal + Opcode) {
       ConcreteTy *I = cast<ConcreteTy>(V);
-      return I->getOpcode() == Opcode && L.match(I->getOperand(0)) &&
-             R.match(I->getOperand(1));
+      return I->getOpcode() == Opcode && L.match(I->getOperand(0), Context) &&
+             R.match(I->getOperand(1), Context);
     }
     if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V))
-      return CE->getOpcode() == Opcode && L.match(CE->getOperand(0)) &&
-             R.match(CE->getOperand(1));
+      return CE->getOpcode() == Opcode && L.match(CE->getOperand(0), Context) &&
+             R.match(CE->getOperand(1), Context);
     return false;
   }
 };
@@ -269,20 +270,20 @@
   Shr_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
 
   template<typename OpTy>
-  bool match(OpTy *V) {
+  bool match(OpTy *V, LLVMContext &Context) {
     if (V->getValueID() == Value::InstructionVal + Instruction::LShr ||
         V->getValueID() == Value::InstructionVal + Instruction::AShr) {
       ConcreteTy *I = cast<ConcreteTy>(V);
       return (I->getOpcode() == Instruction::AShr ||
               I->getOpcode() == Instruction::LShr) &&
-             L.match(I->getOperand(0)) &&
-             R.match(I->getOperand(1));
+             L.match(I->getOperand(0), Context) &&
+             R.match(I->getOperand(1), Context);
     }
     if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V))
       return (CE->getOpcode() == Instruction::LShr ||
               CE->getOpcode() == Instruction::AShr) &&
-             L.match(CE->getOperand(0)) &&
-             R.match(CE->getOperand(1));
+             L.match(CE->getOperand(0), Context) &&
+             R.match(CE->getOperand(1), Context);
     return false;
   }
 };
@@ -309,9 +310,10 @@
     : Opcode(0), L(LHS), R(RHS) {}
 
   template<typename OpTy>
-  bool match(OpTy *V) {
+  bool match(OpTy *V, LLVMContext &Context) {
     if (Class *I = dyn_cast<Class>(V))
-      if (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) {
+      if (L.match(I->getOperand(0), Context) &&
+          R.match(I->getOperand(1), Context)) {
         if (Opcode)
           *Opcode = I->getOpcode();
         return true;
@@ -354,9 +356,10 @@
     : Predicate(Pred), L(LHS), R(RHS) {}
 
   template<typename OpTy>
-  bool match(OpTy *V) {
+  bool match(OpTy *V, LLVMContext &Context) {
     if (Class *I = dyn_cast<Class>(V))
-      if (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) {
+      if (L.match(I->getOperand(0), Context) &&
+          R.match(I->getOperand(1), Context)) {
         Predicate = I->getPredicate();
         return true;
       }
@@ -393,11 +396,11 @@
     : C(Cond), L(LHS), R(RHS) {}
 
   template<typename OpTy>
-  bool match(OpTy *V) {
+  bool match(OpTy *V, LLVMContext &Context) {
     if (SelectInst *I = dyn_cast<SelectInst>(V))
-      return C.match(I->getOperand(0)) &&
-             L.match(I->getOperand(1)) &&
-             R.match(I->getOperand(2));
+      return C.match(I->getOperand(0), Context) &&
+             L.match(I->getOperand(1), Context) &&
+             R.match(I->getOperand(2), Context);
     return false;
   }
 };
@@ -430,9 +433,9 @@
   CastClass_match(const Op_t &OpMatch) : Op(OpMatch) {}
 
   template<typename OpTy>
-  bool match(OpTy *V) {
+  bool match(OpTy *V, LLVMContext &Context) {
     if (Class *I = dyn_cast<Class>(V))
-      return Op.match(I->getOperand(0));
+      return Op.match(I->getOperand(0), Context);
     return false;
   }
 };
@@ -454,27 +457,27 @@
   not_match(const LHS_t &LHS) : L(LHS) {}
 
   template<typename OpTy>
-  bool match(OpTy *V) {
+  bool match(OpTy *V, LLVMContext &Context) {
     if (Instruction *I = dyn_cast<Instruction>(V))
       if (I->getOpcode() == Instruction::Xor)
-        return matchIfNot(I->getOperand(0), I->getOperand(1));
+        return matchIfNot(I->getOperand(0), I->getOperand(1), Context);
     if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V))
       if (CE->getOpcode() == Instruction::Xor)
-        return matchIfNot(CE->getOperand(0), CE->getOperand(1));
+        return matchIfNot(CE->getOperand(0), CE->getOperand(1), Context);
     if (ConstantInt *CI = dyn_cast<ConstantInt>(V))
-      return L.match(ConstantExpr::getNot(CI));
+      return L.match(Context.getConstantExprNot(CI), Context);
     return false;
   }
 private:
-  bool matchIfNot(Value *LHS, Value *RHS) {
+  bool matchIfNot(Value *LHS, Value *RHS, LLVMContext &Context) {
     if (ConstantInt *CI = dyn_cast<ConstantInt>(RHS))
-      return CI->isAllOnesValue() && L.match(LHS);
+      return CI->isAllOnesValue() && L.match(LHS, Context);
     if (ConstantInt *CI = dyn_cast<ConstantInt>(LHS))
-      return CI->isAllOnesValue() && L.match(RHS);
+      return CI->isAllOnesValue() && L.match(RHS, Context);
     if (ConstantVector *CV = dyn_cast<ConstantVector>(RHS))
-      return CV->isAllOnesValue() && L.match(LHS);
+      return CV->isAllOnesValue() && L.match(LHS, Context);
     if (ConstantVector *CV = dyn_cast<ConstantVector>(LHS))
-      return CV->isAllOnesValue() && L.match(RHS);
+      return CV->isAllOnesValue() && L.match(RHS, Context);
     return false;
   }
 };
@@ -490,21 +493,21 @@
   neg_match(const LHS_t &LHS) : L(LHS) {}
 
   template<typename OpTy>
-  bool match(OpTy *V) {
+  bool match(OpTy *V, LLVMContext &Context) {
     if (Instruction *I = dyn_cast<Instruction>(V))
       if (I->getOpcode() == Instruction::Sub)
-        return matchIfNeg(I->getOperand(0), I->getOperand(1));
+        return matchIfNeg(I->getOperand(0), I->getOperand(1), Context);
     if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V))
       if (CE->getOpcode() == Instruction::Sub)
-        return matchIfNeg(CE->getOperand(0), CE->getOperand(1));
+        return matchIfNeg(CE->getOperand(0), CE->getOperand(1), Context);
     if (ConstantInt *CI = dyn_cast<ConstantInt>(V))
-      return L.match(ConstantExpr::getNeg(CI));
+      return L.match(Context.getConstantExprNeg(CI), Context);
     return false;
   }
 private:
-  bool matchIfNeg(Value *LHS, Value *RHS) {
-    return LHS == ConstantExpr::getZeroValueForNegationExpr(LHS->getType()) &&
-           L.match(RHS);
+  bool matchIfNeg(Value *LHS, Value *RHS, LLVMContext &Context) {
+    return LHS == Context.getZeroValueForNegation(LHS->getType()) &&
+           L.match(RHS, Context);
   }
 };
 
@@ -519,21 +522,21 @@
   fneg_match(const LHS_t &LHS) : L(LHS) {}
 
   template<typename OpTy>
-  bool match(OpTy *V) {
+  bool match(OpTy *V, LLVMContext &Context) {
     if (Instruction *I = dyn_cast<Instruction>(V))
       if (I->getOpcode() == Instruction::FSub)
-        return matchIfFNeg(I->getOperand(0), I->getOperand(1));
+        return matchIfFNeg(I->getOperand(0), I->getOperand(1), Context);
     if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V))
       if (CE->getOpcode() == Instruction::FSub)
-        return matchIfFNeg(CE->getOperand(0), CE->getOperand(1));
+        return matchIfFNeg(CE->getOperand(0), CE->getOperand(1), Context);
     if (ConstantFP *CF = dyn_cast<ConstantFP>(V))
-      return L.match(ConstantExpr::getFNeg(CF));
+      return L.match(Context.getConstantExprFNeg(CF), Context);
     return false;
   }
 private:
-  bool matchIfFNeg(Value *LHS, Value *RHS) {
-    return LHS == ConstantExpr::getZeroValueForNegationExpr(LHS->getType()) &&
-           L.match(RHS);
+  bool matchIfFNeg(Value *LHS, Value *RHS, LLVMContext &Context) {
+    return LHS == Context.getZeroValueForNegation(LHS->getType()) &&
+           L.match(RHS, Context);
   }
 };
 
@@ -554,10 +557,10 @@
   }
 
   template<typename OpTy>
-  bool match(OpTy *V) {
+  bool match(OpTy *V, LLVMContext &Context) {
     if (BranchInst *BI = dyn_cast<BranchInst>(V))
       if (BI->isConditional()) {
-        if (Cond.match(BI->getCondition())) {
+        if (Cond.match(BI->getCondition(), Context)) {
           T = BI->getSuccessor(0);
           F = BI->getSuccessor(1);
           return true;

Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=75255&r1=75254&r2=75255&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Fri Jul 10 12:35:01 2009
@@ -1889,7 +1889,7 @@
   AddMaskingAnd(Constant *c, LLVMContext *C) : C2(c), Context(C) {}
   bool shouldApply(Value *LHS) const {
     ConstantInt *C1;
-    return match(LHS, m_And(m_Value(), m_ConstantInt(C1))) &&
+    return match(LHS, m_And(m_Value(), m_ConstantInt(C1)), *Context) &&
            Context->getConstantExprAnd(C1, C2)->isNullValue();
   }
   Instruction *apply(BinaryOperator &Add) const {
@@ -2114,7 +2114,7 @@
     ConstantInt *XorRHS = 0;
     Value *XorLHS = 0;
     if (isa<ConstantInt>(RHSC) &&
-        match(LHS, m_Xor(m_Value(XorLHS), m_ConstantInt(XorRHS)))) {
+        match(LHS, m_Xor(m_Value(XorLHS), m_ConstantInt(XorRHS)), *Context)) {
       uint32_t TySizeBits = I.getType()->getScalarSizeInBits();
       const APInt& RHSVal = cast<ConstantInt>(RHSC)->getValue();
       
@@ -2220,7 +2220,7 @@
   
 
   // (A & C1)+(B & C2) --> (A & C1)|(B & C2) iff C1&C2 == 0
-  if (match(RHS, m_And(m_Value(), m_ConstantInt(C2))))
+  if (match(RHS, m_And(m_Value(), m_ConstantInt(C2)), *Context))
     if (Instruction *R = AssociativeOpt(I, AddMaskingAnd(C2, Context), Context))
       return R;
   
@@ -2244,8 +2244,8 @@
   // W*X + Y*Z --> W * (X+Z)  iff W == Y
   if (I.getType()->isIntOrIntVector()) {
     Value *W, *X, *Y, *Z;
-    if (match(LHS, m_Mul(m_Value(W), m_Value(X))) &&
-        match(RHS, m_Mul(m_Value(Y), m_Value(Z)))) {
+    if (match(LHS, m_Mul(m_Value(W), m_Value(X)), *Context) &&
+        match(RHS, m_Mul(m_Value(Y), m_Value(Z)), *Context)) {
       if (W != Y) {
         if (W == Z) {
           std::swap(Y, Z);
@@ -2267,11 +2267,12 @@
 
   if (ConstantInt *CRHS = dyn_cast<ConstantInt>(RHS)) {
     Value *X = 0;
-    if (match(LHS, m_Not(m_Value(X))))    // ~X + C --> (C-1) - X
+    if (match(LHS, m_Not(m_Value(X)), *Context))    // ~X + C --> (C-1) - X
       return BinaryOperator::CreateSub(SubOne(CRHS, Context), X);
 
     // (X & FF00) + xx00  -> (X+xx00) & FF00
-    if (LHS->hasOneUse() && match(LHS, m_And(m_Value(X), m_ConstantInt(C2)))) {
+    if (LHS->hasOneUse() &&
+        match(LHS, m_And(m_Value(X), m_ConstantInt(C2)), *Context)) {
       Constant *Anded = Context->getConstantExprAnd(CRHS, C2);
       if (Anded == CRHS) {
         // See if all bits from the first bit set in the Add RHS up are included
@@ -2336,10 +2337,12 @@
 
       // Can we fold the add into the argument of the select?
       // We check both true and false select arguments for a matching subtract.
-      if (match(FV, m_Zero()) && match(TV, m_Sub(m_Value(N), m_Specific(A))))
+      if (match(FV, m_Zero(), *Context) &&
+          match(TV, m_Sub(m_Value(N), m_Specific(A)), *Context))
         // Fold the add into the true select value.
         return SelectInst::Create(SI->getCondition(), N, A);
-      if (match(TV, m_Zero()) && match(FV, m_Sub(m_Value(N), m_Specific(A))))
+      if (match(TV, m_Zero(), *Context) &&
+          match(FV, m_Sub(m_Value(N), m_Specific(A)), *Context))
         // Fold the add into the false select value.
         return SelectInst::Create(SI->getCondition(), A, N);
     }
@@ -2483,7 +2486,7 @@
 
     // C - ~X == X + (1+C)
     Value *X = 0;
-    if (match(Op1, m_Not(m_Value(X))))
+    if (match(Op1, m_Not(m_Value(X)), *Context))
       return BinaryOperator::CreateAdd(X, AddOne(C, Context));
 
     // -(X >>u 31) -> (X >>s 31)
@@ -3786,8 +3789,10 @@
   ICmpInst::Predicate LHSCC, RHSCC;
   
   // 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_Value(Val2), m_ConstantInt(RHSCst))))
+  if (!match(LHS, m_ICmp(LHSCC, m_Value(Val),
+                         m_ConstantInt(LHSCst)), *Context) ||
+      !match(RHS, m_ICmp(RHSCC, m_Value(Val2),
+                         m_ConstantInt(RHSCst)), *Context))
     return 0;
   
   // (icmp ult A, C) & (icmp ult B, C) --> (icmp ult (A|B), C)
@@ -4120,30 +4125,30 @@
   
   {
     Value *A = 0, *B = 0, *C = 0, *D = 0;
-    if (match(Op0, m_Or(m_Value(A), m_Value(B)))) {
+    if (match(Op0, m_Or(m_Value(A), m_Value(B)), *Context)) {
       if (A == Op1 || B == Op1)    // (A | ?) & A  --> A
         return ReplaceInstUsesWith(I, Op1);
     
       // (A|B) & ~(A&B) -> A^B
-      if (match(Op1, m_Not(m_And(m_Value(C), m_Value(D))))) {
+      if (match(Op1, m_Not(m_And(m_Value(C), m_Value(D))), *Context)) {
         if ((A == C && B == D) || (A == D && B == C))
           return BinaryOperator::CreateXor(A, B);
       }
     }
     
-    if (match(Op1, m_Or(m_Value(A), m_Value(B)))) {
+    if (match(Op1, m_Or(m_Value(A), m_Value(B)), *Context)) {
       if (A == Op0 || B == Op0)    // A & (A | ?)  --> A
         return ReplaceInstUsesWith(I, Op0);
 
       // ~(A&B) & (A|B) -> A^B
-      if (match(Op0, m_Not(m_And(m_Value(C), m_Value(D))))) {
+      if (match(Op0, m_Not(m_And(m_Value(C), m_Value(D))), *Context)) {
         if ((A == C && B == D) || (A == D && B == C))
           return BinaryOperator::CreateXor(A, B);
       }
     }
     
     if (Op0->hasOneUse() &&
-        match(Op0, m_Xor(m_Value(A), m_Value(B)))) {
+        match(Op0, m_Xor(m_Value(A), m_Value(B)), *Context)) {
       if (A == Op1) {                                // (A^B)&A -> A&(A^B)
         I.swapOperands();     // Simplify below
         std::swap(Op0, Op1);
@@ -4155,7 +4160,7 @@
     }
 
     if (Op1->hasOneUse() &&
-        match(Op1, m_Xor(m_Value(A), m_Value(B)))) {
+        match(Op1, m_Xor(m_Value(A), m_Value(B)), *Context)) {
       if (B == Op0) {                                // B&(A^B) -> B&(B^A)
         cast<BinaryOperator>(Op1)->swapOperands();
         std::swap(A, B);
@@ -4168,11 +4173,11 @@
     }
 
     // (A&((~A)|B)) -> A&B
-    if (match(Op0, m_Or(m_Not(m_Specific(Op1)), m_Value(A))) ||
-        match(Op0, m_Or(m_Value(A), m_Not(m_Specific(Op1)))))
+    if (match(Op0, m_Or(m_Not(m_Specific(Op1)), m_Value(A)), *Context) ||
+        match(Op0, m_Or(m_Value(A), m_Not(m_Specific(Op1))), *Context))
       return BinaryOperator::CreateAnd(A, Op1);
-    if (match(Op1, m_Or(m_Not(m_Specific(Op0)), m_Value(A))) ||
-        match(Op1, m_Or(m_Value(A), m_Not(m_Specific(Op0)))))
+    if (match(Op1, m_Or(m_Not(m_Specific(Op0)), m_Value(A)), *Context) ||
+        match(Op1, m_Or(m_Value(A), m_Not(m_Specific(Op0))), *Context))
       return BinaryOperator::CreateAnd(A, Op0);
   }
   
@@ -4238,8 +4243,10 @@
       } else {
         Value *Op0LHS, *Op0RHS, *Op1LHS, *Op1RHS;
         FCmpInst::Predicate Op0CC, Op1CC;
-        if (match(Op0, m_FCmp(Op0CC, m_Value(Op0LHS), m_Value(Op0RHS))) &&
-            match(Op1, m_FCmp(Op1CC, m_Value(Op1LHS), m_Value(Op1RHS)))) {
+        if (match(Op0, m_FCmp(Op0CC, m_Value(Op0LHS),
+                  m_Value(Op0RHS)), *Context) &&
+            match(Op1, m_FCmp(Op1CC, m_Value(Op1LHS),
+                  m_Value(Op1RHS)), *Context)) {
           if (Op0LHS == Op1RHS && Op0RHS == Op1LHS) {
             // Swap RHS operands to match LHS.
             Op1CC = FCmpInst::getSwappedPredicate(Op1CC);
@@ -4452,21 +4459,22 @@
 /// If A is (cond?-1:0) and either B or D is ~(cond?-1,0) or (cond?0,-1), then
 /// we can simplify this expression to "cond ? C : D or B".
 static Instruction *MatchSelectFromAndOr(Value *A, Value *B,
-                                         Value *C, Value *D) {
+                                         Value *C, Value *D,
+                                         LLVMContext *Context) {
   // If A is not a select of -1/0, this cannot match.
   Value *Cond = 0;
-  if (!match(A, m_SelectCst<-1, 0>(m_Value(Cond))))
+  if (!match(A, m_SelectCst<-1, 0>(m_Value(Cond)), *Context))
     return 0;
 
   // ((cond?-1:0)&C) | (B&(cond?0:-1)) -> cond ? C : B.
-  if (match(D, m_SelectCst<0, -1>(m_Specific(Cond))))
+  if (match(D, m_SelectCst<0, -1>(m_Specific(Cond)), *Context))
     return SelectInst::Create(Cond, C, B);
-  if (match(D, m_Not(m_SelectCst<-1, 0>(m_Specific(Cond)))))
+  if (match(D, m_Not(m_SelectCst<-1, 0>(m_Specific(Cond))), *Context))
     return SelectInst::Create(Cond, C, B);
   // ((cond?-1:0)&C) | ((cond?0:-1)&D) -> cond ? C : D.
-  if (match(B, m_SelectCst<0, -1>(m_Specific(Cond))))
+  if (match(B, m_SelectCst<0, -1>(m_Specific(Cond)), *Context))
     return SelectInst::Create(Cond, C, D);
-  if (match(B, m_Not(m_SelectCst<-1, 0>(m_Specific(Cond)))))
+  if (match(B, m_Not(m_SelectCst<-1, 0>(m_Specific(Cond))), *Context))
     return SelectInst::Create(Cond, C, D);
   return 0;
 }
@@ -4479,8 +4487,10 @@
   ICmpInst::Predicate LHSCC, RHSCC;
   
   // 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_Value(Val2), m_ConstantInt(RHSCst))))
+  if (!match(LHS, m_ICmp(LHSCC, m_Value(Val),
+             m_ConstantInt(LHSCst)), *Context) ||
+      !match(RHS, m_ICmp(RHSCC, m_Value(Val2),
+             m_ConstantInt(RHSCst)), *Context))
     return 0;
   
   // From here on, we only handle:
@@ -4651,7 +4661,7 @@
 
   Value *V1 = 0;
   ConstantInt *CI2 = 0;
-  if (!match(Op, m_And(m_Value(V1), m_ConstantInt(CI2)))) return 0;
+  if (!match(Op, m_And(m_Value(V1), m_ConstantInt(CI2)), *Context)) return 0;
 
   APInt Xor = CI1->getValue() ^ CI2->getValue();
   if (!Xor.isAllOnesValue()) return 0;
@@ -4693,7 +4703,8 @@
   if (ConstantInt *RHS = dyn_cast<ConstantInt>(Op1)) {
     ConstantInt *C1 = 0; Value *X = 0;
     // (X & C1) | C2 --> (X | C2) & (C1|C2)
-    if (match(Op0, m_And(m_Value(X), m_ConstantInt(C1))) && isOnlyUse(Op0)) {
+    if (match(Op0, m_And(m_Value(X), m_ConstantInt(C1)), *Context) && 
+        isOnlyUse(Op0)) {
       Instruction *Or = BinaryOperator::CreateOr(X, RHS);
       InsertNewInstBefore(Or, I);
       Or->takeName(Op0);
@@ -4702,7 +4713,8 @@
     }
 
     // (X ^ C1) | C2 --> (X | C2) ^ (C1&~C2)
-    if (match(Op0, m_Xor(m_Value(X), m_ConstantInt(C1))) && isOnlyUse(Op0)) {
+    if (match(Op0, m_Xor(m_Value(X), m_ConstantInt(C1)), *Context) && 
+        isOnlyUse(Op0)) {
       Instruction *Or = BinaryOperator::CreateOr(X, RHS);
       InsertNewInstBefore(Or, I);
       Or->takeName(Op0);
@@ -4722,25 +4734,26 @@
   Value *A = 0, *B = 0;
   ConstantInt *C1 = 0, *C2 = 0;
 
-  if (match(Op0, m_And(m_Value(A), m_Value(B))))
+  if (match(Op0, m_And(m_Value(A), m_Value(B)), *Context))
     if (A == Op1 || B == Op1)    // (A & ?) | A  --> A
       return ReplaceInstUsesWith(I, Op1);
-  if (match(Op1, m_And(m_Value(A), m_Value(B))))
+  if (match(Op1, m_And(m_Value(A), m_Value(B)), *Context))
     if (A == Op0 || B == Op0)    // A | (A & ?)  --> A
       return ReplaceInstUsesWith(I, Op0);
 
   // (A | B) | C  and  A | (B | C)                  -> bswap if possible.
   // (A >> B) | (C << D)  and  (A << B) | (B >> C)  -> bswap if possible.
-  if (match(Op0, m_Or(m_Value(), m_Value())) ||
-      match(Op1, m_Or(m_Value(), m_Value())) ||
-      (match(Op0, m_Shift(m_Value(), m_Value())) &&
-       match(Op1, m_Shift(m_Value(), m_Value())))) {
+  if (match(Op0, m_Or(m_Value(), m_Value()), *Context) ||
+      match(Op1, m_Or(m_Value(), m_Value()), *Context) ||
+      (match(Op0, m_Shift(m_Value(), m_Value()), *Context) &&
+       match(Op1, m_Shift(m_Value(), m_Value()), *Context))) {
     if (Instruction *BSwap = MatchBSwap(I))
       return BSwap;
   }
   
   // (X^C)|Y -> (X|Y)^C iff Y&C == 0
-  if (Op0->hasOneUse() && match(Op0, m_Xor(m_Value(A), m_ConstantInt(C1))) &&
+  if (Op0->hasOneUse() &&
+      match(Op0, m_Xor(m_Value(A), m_ConstantInt(C1)), *Context) &&
       MaskedValueIsZero(Op1, C1->getValue())) {
     Instruction *NOr = BinaryOperator::CreateOr(A, Op1);
     InsertNewInstBefore(NOr, I);
@@ -4749,7 +4762,8 @@
   }
 
   // Y|(X^C) -> (X|Y)^C iff Y&C == 0
-  if (Op1->hasOneUse() && match(Op1, m_Xor(m_Value(A), m_ConstantInt(C1))) &&
+  if (Op1->hasOneUse() &&
+      match(Op1, m_Xor(m_Value(A), m_ConstantInt(C1)), *Context) &&
       MaskedValueIsZero(Op0, C1->getValue())) {
     Instruction *NOr = BinaryOperator::CreateOr(A, Op0);
     InsertNewInstBefore(NOr, I);
@@ -4759,8 +4773,8 @@
 
   // (A & C)|(B & D)
   Value *C = 0, *D = 0;
-  if (match(Op0, m_And(m_Value(A), m_Value(C))) &&
-      match(Op1, m_And(m_Value(B), m_Value(D)))) {
+  if (match(Op0, m_And(m_Value(A), m_Value(C)), *Context) &&
+      match(Op1, m_And(m_Value(B), m_Value(D)), *Context)) {
     Value *V1 = 0, *V2 = 0, *V3 = 0;
     C1 = dyn_cast<ConstantInt>(C);
     C2 = dyn_cast<ConstantInt>(D);
@@ -4770,7 +4784,7 @@
       // replace with V+N.
       if (C1->getValue() == ~C2->getValue()) {
         if ((C2->getValue() & (C2->getValue()+1)) == 0 && // C2 == 0+1+
-            match(A, m_Add(m_Value(V1), m_Value(V2)))) {
+            match(A, m_Add(m_Value(V1), m_Value(V2)), *Context)) {
           // Add commutes, try both ways.
           if (V1 == B && MaskedValueIsZero(V2, C2->getValue()))
             return ReplaceInstUsesWith(I, A);
@@ -4779,7 +4793,7 @@
         }
         // Or commutes, try both ways.
         if ((C1->getValue() & (C1->getValue()+1)) == 0 &&
-            match(B, m_Add(m_Value(V1), m_Value(V2)))) {
+            match(B, m_Add(m_Value(V1), m_Value(V2)), *Context)) {
           // Add commutes, try both ways.
           if (V1 == A && MaskedValueIsZero(V2, C1->getValue()))
             return ReplaceInstUsesWith(I, B);
@@ -4810,30 +4824,30 @@
     }
 
     // (A & (C0?-1:0)) | (B & ~(C0?-1:0)) ->  C0 ? A : B, and commuted variants
-    if (Instruction *Match = MatchSelectFromAndOr(A, B, C, D))
+    if (Instruction *Match = MatchSelectFromAndOr(A, B, C, D, Context))
       return Match;
-    if (Instruction *Match = MatchSelectFromAndOr(B, A, D, C))
+    if (Instruction *Match = MatchSelectFromAndOr(B, A, D, C, Context))
       return Match;
-    if (Instruction *Match = MatchSelectFromAndOr(C, B, A, D))
+    if (Instruction *Match = MatchSelectFromAndOr(C, B, A, D, Context))
       return Match;
-    if (Instruction *Match = MatchSelectFromAndOr(D, A, B, C))
+    if (Instruction *Match = MatchSelectFromAndOr(D, A, B, C, Context))
       return Match;
 
     // ((A&~B)|(~A&B)) -> A^B
-    if ((match(C, m_Not(m_Specific(D))) &&
-         match(B, m_Not(m_Specific(A)))))
+    if ((match(C, m_Not(m_Specific(D)), *Context) &&
+         match(B, m_Not(m_Specific(A)), *Context)))
       return BinaryOperator::CreateXor(A, D);
     // ((~B&A)|(~A&B)) -> A^B
-    if ((match(A, m_Not(m_Specific(D))) &&
-         match(B, m_Not(m_Specific(C)))))
+    if ((match(A, m_Not(m_Specific(D)), *Context) &&
+         match(B, m_Not(m_Specific(C)), *Context)))
       return BinaryOperator::CreateXor(C, D);
     // ((A&~B)|(B&~A)) -> A^B
-    if ((match(C, m_Not(m_Specific(B))) &&
-         match(D, m_Not(m_Specific(A)))))
+    if ((match(C, m_Not(m_Specific(B)), *Context) &&
+         match(D, m_Not(m_Specific(A)), *Context)))
       return BinaryOperator::CreateXor(A, B);
     // ((~B&A)|(B&~A)) -> A^B
-    if ((match(A, m_Not(m_Specific(B))) &&
-         match(D, m_Not(m_Specific(C)))))
+    if ((match(A, m_Not(m_Specific(B)), *Context) &&
+         match(D, m_Not(m_Specific(C)), *Context)))
       return BinaryOperator::CreateXor(C, B);
   }
   
@@ -4853,26 +4867,26 @@
   }
 
   // ((A|B)&1)|(B&-2) -> (A&1) | B
-  if (match(Op0, m_And(m_Or(m_Value(A), m_Value(B)), m_Value(C))) ||
-      match(Op0, m_And(m_Value(C), m_Or(m_Value(A), m_Value(B))))) {
+  if (match(Op0, m_And(m_Or(m_Value(A), m_Value(B)), m_Value(C)), *Context) ||
+      match(Op0, m_And(m_Value(C), m_Or(m_Value(A), m_Value(B))), *Context)) {
     Instruction *Ret = FoldOrWithConstants(I, Op1, A, B, C);
     if (Ret) return Ret;
   }
   // (B&-2)|((A|B)&1) -> (A&1) | B
-  if (match(Op1, m_And(m_Or(m_Value(A), m_Value(B)), m_Value(C))) ||
-      match(Op1, m_And(m_Value(C), m_Or(m_Value(A), m_Value(B))))) {
+  if (match(Op1, m_And(m_Or(m_Value(A), m_Value(B)), m_Value(C)), *Context) ||
+      match(Op1, m_And(m_Value(C), m_Or(m_Value(A), m_Value(B))), *Context)) {
     Instruction *Ret = FoldOrWithConstants(I, Op0, A, B, C);
     if (Ret) return Ret;
   }
 
-  if (match(Op0, m_Not(m_Value(A)))) {   // ~A | Op1
+  if (match(Op0, m_Not(m_Value(A)), *Context)) {   // ~A | Op1
     if (A == Op1)   // ~A | A == -1
       return ReplaceInstUsesWith(I, Context->getAllOnesValue(I.getType()));
   } else {
     A = 0;
   }
   // Note, A is still live here!
-  if (match(Op1, m_Not(m_Value(B)))) {   // Op0 | ~B
+  if (match(Op1, m_Not(m_Value(B)), *Context)) {   // Op0 | ~B
     if (Op0 == B)
       return ReplaceInstUsesWith(I, Context->getAllOnesValue(I.getType()));
 
@@ -4940,8 +4954,10 @@
       } else {
         Value *Op0LHS, *Op0RHS, *Op1LHS, *Op1RHS;
         FCmpInst::Predicate Op0CC, Op1CC;
-        if (match(Op0, m_FCmp(Op0CC, m_Value(Op0LHS), m_Value(Op0RHS))) &&
-            match(Op1, m_FCmp(Op1CC, m_Value(Op1LHS), m_Value(Op1RHS)))) {
+        if (match(Op0, m_FCmp(Op0CC, m_Value(Op0LHS),
+                  m_Value(Op0RHS)), *Context) &&
+            match(Op1, m_FCmp(Op1CC, m_Value(Op1LHS),
+                  m_Value(Op1RHS)), *Context)) {
           if (Op0LHS == Op1RHS && Op0RHS == Op1LHS) {
             // Swap RHS operands to match LHS.
             Op1CC = FCmpInst::getSwappedPredicate(Op1CC);
@@ -5143,7 +5159,7 @@
   BinaryOperator *Op1I = dyn_cast<BinaryOperator>(Op1);
   if (Op1I) {
     Value *A, *B;
-    if (match(Op1I, m_Or(m_Value(A), m_Value(B)))) {
+    if (match(Op1I, m_Or(m_Value(A), m_Value(B)), *Context)) {
       if (A == Op0) {              // B^(B|A) == (A|B)^B
         Op1I->swapOperands();
         I.swapOperands();
@@ -5152,11 +5168,12 @@
         I.swapOperands();     // Simplified below.
         std::swap(Op0, Op1);
       }
-    } else if (match(Op1I, m_Xor(m_Specific(Op0), m_Value(B)))) {
+    } else if (match(Op1I, m_Xor(m_Specific(Op0), m_Value(B)), *Context)) {
       return ReplaceInstUsesWith(I, B);                      // A^(A^B) == B
-    } else if (match(Op1I, m_Xor(m_Value(A), m_Specific(Op0)))) {
+    } else if (match(Op1I, m_Xor(m_Value(A), m_Specific(Op0)), *Context)) {
       return ReplaceInstUsesWith(I, A);                      // A^(B^A) == B
-    } else if (match(Op1I, m_And(m_Value(A), m_Value(B))) && Op1I->hasOneUse()){
+    } else if (match(Op1I, m_And(m_Value(A), m_Value(B)), *Context) && 
+               Op1I->hasOneUse()){
       if (A == Op0) {                                      // A^(A&B) -> A^(B&A)
         Op1I->swapOperands();
         std::swap(A, B);
@@ -5171,7 +5188,8 @@
   BinaryOperator *Op0I = dyn_cast<BinaryOperator>(Op0);
   if (Op0I) {
     Value *A, *B;
-    if (match(Op0I, m_Or(m_Value(A), m_Value(B))) && Op0I->hasOneUse()) {
+    if (match(Op0I, m_Or(m_Value(A), m_Value(B)), *Context) &&
+        Op0I->hasOneUse()) {
       if (A == Op1)                                  // (B|A)^B == (A|B)^B
         std::swap(A, B);
       if (B == Op1) {                                // (A|B)^B == A & ~B
@@ -5179,11 +5197,12 @@
           InsertNewInstBefore(BinaryOperator::CreateNot(Op1, "tmp"), I);
         return BinaryOperator::CreateAnd(A, NotB);
       }
-    } else if (match(Op0I, m_Xor(m_Specific(Op1), m_Value(B)))) {
+    } else if (match(Op0I, m_Xor(m_Specific(Op1), m_Value(B)), *Context)) {
       return ReplaceInstUsesWith(I, B);                      // (A^B)^A == B
-    } else if (match(Op0I, m_Xor(m_Value(A), m_Specific(Op1)))) {
+    } else if (match(Op0I, m_Xor(m_Value(A), m_Specific(Op1)), *Context)) {
       return ReplaceInstUsesWith(I, A);                      // (B^A)^A == B
-    } else if (match(Op0I, m_And(m_Value(A), m_Value(B))) && Op0I->hasOneUse()){
+    } else if (match(Op0I, m_And(m_Value(A), m_Value(B)), *Context) && 
+               Op0I->hasOneUse()){
       if (A == Op1)                                        // (A&B)^A -> (B&A)^A
         std::swap(A, B);
       if (B == Op1 &&                                      // (B&A)^A == ~B & A
@@ -5211,22 +5230,22 @@
   if (Op0I && Op1I) {
     Value *A, *B, *C, *D;
     // (A & B)^(A | B) -> A ^ B
-    if (match(Op0I, m_And(m_Value(A), m_Value(B))) &&
-        match(Op1I, m_Or(m_Value(C), m_Value(D)))) {
+    if (match(Op0I, m_And(m_Value(A), m_Value(B)), *Context) &&
+        match(Op1I, m_Or(m_Value(C), m_Value(D)), *Context)) {
       if ((A == C && B == D) || (A == D && B == C)) 
         return BinaryOperator::CreateXor(A, B);
     }
     // (A | B)^(A & B) -> A ^ B
-    if (match(Op0I, m_Or(m_Value(A), m_Value(B))) &&
-        match(Op1I, m_And(m_Value(C), m_Value(D)))) {
+    if (match(Op0I, m_Or(m_Value(A), m_Value(B)), *Context) &&
+        match(Op1I, m_And(m_Value(C), m_Value(D)), *Context)) {
       if ((A == C && B == D) || (A == D && B == C)) 
         return BinaryOperator::CreateXor(A, B);
     }
     
     // (A & B)^(C & D)
     if ((Op0I->hasOneUse() || Op1I->hasOneUse()) &&
-        match(Op0I, m_And(m_Value(A), m_Value(B))) &&
-        match(Op1I, m_And(m_Value(C), m_Value(D)))) {
+        match(Op0I, m_And(m_Value(A), m_Value(B)), *Context) &&
+        match(Op1I, m_And(m_Value(C), m_Value(D)), *Context)) {
       // (X & Y)^(X & Y) -> (Y^Z) & X
       Value *X = 0, *Y = 0, *Z = 0;
       if (A == C)
@@ -6033,7 +6052,7 @@
     
     // (icmp ne/eq (sub A B) 0) -> (icmp ne/eq A, B)
     if (I.isEquality() && CI->isNullValue() &&
-        match(Op0, m_Sub(m_Value(A), m_Value(B)))) {
+        match(Op0, m_Sub(m_Value(A), m_Value(B)), *Context)) {
       // (icmp cond A B) if cond is equality
       return new ICmpInst(*Context, I.getPredicate(), A, B);
     }
@@ -6431,8 +6450,8 @@
   
   // ~x < ~y --> y < x
   { Value *A, *B;
-    if (match(Op0, m_Not(m_Value(A))) &&
-        match(Op1, m_Not(m_Value(B))))
+    if (match(Op0, m_Not(m_Value(A)), *Context) &&
+        match(Op1, m_Not(m_Value(B)), *Context))
       return new ICmpInst(*Context, I.getPredicate(), B, A);
   }
   
@@ -6440,22 +6459,22 @@
     Value *A, *B, *C, *D;
     
     // -x == -y --> x == y
-    if (match(Op0, m_Neg(m_Value(A))) &&
-        match(Op1, m_Neg(m_Value(B))))
+    if (match(Op0, m_Neg(m_Value(A)), *Context) &&
+        match(Op1, m_Neg(m_Value(B)), *Context))
       return new ICmpInst(*Context, I.getPredicate(), A, B);
     
-    if (match(Op0, m_Xor(m_Value(A), m_Value(B)))) {
+    if (match(Op0, m_Xor(m_Value(A), m_Value(B)), *Context)) {
       if (A == Op1 || B == Op1) {    // (A^B) == A  ->  B == 0
         Value *OtherVal = A == Op1 ? B : A;
         return new ICmpInst(*Context, I.getPredicate(), OtherVal,
                             Context->getNullValue(A->getType()));
       }
 
-      if (match(Op1, m_Xor(m_Value(C), m_Value(D)))) {
+      if (match(Op1, m_Xor(m_Value(C), m_Value(D)), *Context)) {
         // A^c1 == C^c2 --> A == C^(c1^c2)
         ConstantInt *C1, *C2;
-        if (match(B, m_ConstantInt(C1)) &&
-            match(D, m_ConstantInt(C2)) && Op1->hasOneUse()) {
+        if (match(B, m_ConstantInt(C1), *Context) &&
+            match(D, m_ConstantInt(C2), *Context) && Op1->hasOneUse()) {
           Constant *NC = 
                        Context->getConstantInt(C1->getValue() ^ C2->getValue());
           Instruction *Xor = BinaryOperator::CreateXor(C, NC, "tmp");
@@ -6471,7 +6490,7 @@
       }
     }
     
-    if (match(Op1, m_Xor(m_Value(A), m_Value(B))) &&
+    if (match(Op1, m_Xor(m_Value(A), m_Value(B)), *Context) &&
         (A == Op0 || B == Op0)) {
       // A == (A^B)  ->  B == 0
       Value *OtherVal = A == Op0 ? B : A;
@@ -6480,19 +6499,19 @@
     }
 
     // (A-B) == A  ->  B == 0
-    if (match(Op0, m_Sub(m_Specific(Op1), m_Value(B))))
+    if (match(Op0, m_Sub(m_Specific(Op1), m_Value(B)), *Context))
       return new ICmpInst(*Context, I.getPredicate(), B, 
                           Context->getNullValue(B->getType()));
 
     // A == (A-B)  ->  B == 0
-    if (match(Op1, m_Sub(m_Specific(Op0), m_Value(B))))
+    if (match(Op1, m_Sub(m_Specific(Op0), m_Value(B)), *Context))
       return new ICmpInst(*Context, I.getPredicate(), B,
                           Context->getNullValue(B->getType()));
     
     // (X&Z) == (Y&Z) -> (X^Y) & Z == 0
     if (Op0->hasOneUse() && Op1->hasOneUse() &&
-        match(Op0, m_And(m_Value(A), m_Value(B))) && 
-        match(Op1, m_And(m_Value(C), m_Value(D)))) {
+        match(Op0, m_And(m_Value(A), m_Value(B)), *Context) && 
+        match(Op1, m_And(m_Value(C), m_Value(D)), *Context)) {
       Value *X = 0, *Y = 0, *Z = 0;
       
       if (A == C) {
@@ -7458,7 +7477,8 @@
           // These operators commute.
           // Turn (Y + (X >> C)) << C  ->  (X + (Y << C)) & (~0 << C)
           if (isLeftShift && Op0BO->getOperand(1)->hasOneUse() &&
-              match(Op0BO->getOperand(1), m_Shr(m_Value(V1), m_Specific(Op1)))){
+              match(Op0BO->getOperand(1), m_Shr(m_Value(V1),
+                    m_Specific(Op1)), *Context)){
             Instruction *YS = BinaryOperator::CreateShl(
                                             Op0BO->getOperand(0), Op1,
                                             Op0BO->getName());
@@ -7477,7 +7497,7 @@
           if (isLeftShift && Op0BOOp1->hasOneUse() &&
               match(Op0BOOp1, 
                     m_And(m_Shr(m_Value(V1), m_Specific(Op1)),
-                          m_ConstantInt(CC))) &&
+                          m_ConstantInt(CC)), *Context) &&
               cast<BinaryOperator>(Op0BOOp1)->getOperand(0)->hasOneUse()) {
             Instruction *YS = BinaryOperator::CreateShl(
                                                      Op0BO->getOperand(0), Op1,
@@ -7497,7 +7517,8 @@
         case Instruction::Sub: {
           // Turn ((X >> C) + Y) << C  ->  (X + (Y << C)) & (~0 << C)
           if (isLeftShift && Op0BO->getOperand(0)->hasOneUse() &&
-              match(Op0BO->getOperand(0), m_Shr(m_Value(V1), m_Specific(Op1)))){
+              match(Op0BO->getOperand(0), m_Shr(m_Value(V1),
+                    m_Specific(Op1)), *Context)){
             Instruction *YS = BinaryOperator::CreateShl(
                                                      Op0BO->getOperand(1), Op1,
                                                      Op0BO->getName());
@@ -7515,7 +7536,7 @@
           if (isLeftShift && Op0BO->getOperand(0)->hasOneUse() &&
               match(Op0BO->getOperand(0),
                     m_And(m_Shr(m_Value(V1), m_Value(V2)),
-                          m_ConstantInt(CC))) && V2 == Op1 &&
+                          m_ConstantInt(CC)), *Context) && V2 == Op1 &&
               cast<BinaryOperator>(Op0BO->getOperand(0))
                   ->getOperand(0)->hasOneUse()) {
             Instruction *YS = BinaryOperator::CreateShl(
@@ -8476,7 +8497,7 @@
   ConstantInt *ShAmtV = 0;
   Value *ShiftOp = 0;
   if (Src->hasOneUse() &&
-      match(Src, m_LShr(m_Value(ShiftOp), m_ConstantInt(ShAmtV)))) {
+      match(Src, m_LShr(m_Value(ShiftOp), m_ConstantInt(ShAmtV)), *Context)) {
     uint32_t ShAmt = ShAmtV->getLimitedValue(SrcBitWidth);
     
     // Get a mask for the bits shifting in.
@@ -8736,7 +8757,7 @@
   Value *A = 0;
   ConstantInt *BA = 0, *CA = 0;
   if (match(Src, m_AShr(m_Shl(m_Value(A), m_ConstantInt(BA)),
-                        m_ConstantInt(CA))) &&
+                        m_ConstantInt(CA)), *Context) &&
       BA == CA && isa<TruncInst>(A)) {
     Value *I = cast<TruncInst>(A)->getOperand(0);
     if (I->getType() == CI.getType()) {
@@ -8923,7 +8944,7 @@
   ConstantInt *Cst;
   Value *X;
   if (match(CI.getOperand(0), m_Add(m_Cast<PtrToIntInst>(m_Value(X)),
-                                    m_ConstantInt(Cst)))) {
+                                    m_ConstantInt(Cst)), *Context)) {
     // If the source and destination operands have the same type, see if this
     // is a single-index GEP.
     if (X->getType() == CI.getType()) {
@@ -8943,7 +8964,8 @@
     // TODO: Could handle other cases, e.g. where add is indexing into field of
     // struct etc.
   } else if (CI.getOperand(0)->hasOneUse() &&
-             match(CI.getOperand(0), m_Add(m_Value(X), m_ConstantInt(Cst)))) {
+             match(CI.getOperand(0), m_Add(m_Value(X),
+                   m_ConstantInt(Cst)), *Context)) {
     // Otherwise, if this is inttoptr(add x, cst), try to turn this into an
     // "inttoptr+GEP" instead of "add+intptr".
     
@@ -9319,11 +9341,11 @@
       // (x <s 0) ? -1 : 0 -> ashr x, 31   -> all ones if signed
       // (x >s -1) ? -1 : 0 -> ashr x, 31  -> all ones if not signed
       CmpInst::Predicate Pred = CmpInst::BAD_ICMP_PREDICATE;
-      if (match(TrueVal, m_ConstantInt<-1>()) &&
-          match(FalseVal, m_ConstantInt<0>()))
+      if (match(TrueVal, m_ConstantInt<-1>(), *Context) &&
+          match(FalseVal, m_ConstantInt<0>(), *Context))
         Pred = ICI->getPredicate();
-      else if (match(TrueVal, m_ConstantInt<0>()) &&
-               match(FalseVal, m_ConstantInt<-1>()))
+      else if (match(TrueVal, m_ConstantInt<0>(), *Context) &&
+               match(FalseVal, m_ConstantInt<-1>(), *Context))
         Pred = CmpInst::getInversePredicate(ICI->getPredicate());
       
       if (Pred != CmpInst::BAD_ICMP_PREDICATE) {
@@ -12101,7 +12123,7 @@
   Value *X = 0;
   BasicBlock *TrueDest;
   BasicBlock *FalseDest;
-  if (match(&BI, m_Br(m_Not(m_Value(X)), TrueDest, FalseDest)) &&
+  if (match(&BI, m_Br(m_Not(m_Value(X)), TrueDest, FalseDest), *Context) &&
       !isa<Constant>(X)) {
     // Swap Destinations and condition...
     BI.setCondition(X);
@@ -12113,7 +12135,7 @@
   // Cannonicalize fcmp_one -> fcmp_oeq
   FCmpInst::Predicate FPred; Value *Y;
   if (match(&BI, m_Br(m_FCmp(FPred, m_Value(X), m_Value(Y)), 
-                             TrueDest, FalseDest)))
+                             TrueDest, FalseDest), *Context))
     if ((FPred == FCmpInst::FCMP_ONE || FPred == FCmpInst::FCMP_OLE ||
          FPred == FCmpInst::FCMP_OGE) && BI.getCondition()->hasOneUse()) {
       FCmpInst *I = cast<FCmpInst>(BI.getCondition());
@@ -12133,7 +12155,7 @@
   // Cannonicalize icmp_ne -> icmp_eq
   ICmpInst::Predicate IPred;
   if (match(&BI, m_Br(m_ICmp(IPred, m_Value(X), m_Value(Y)),
-                      TrueDest, FalseDest)))
+                      TrueDest, FalseDest), *Context))
     if ((IPred == ICmpInst::ICMP_NE  || IPred == ICmpInst::ICMP_ULE ||
          IPred == ICmpInst::ICMP_SLE || IPred == ICmpInst::ICMP_UGE ||
          IPred == ICmpInst::ICMP_SGE) && BI.getCondition()->hasOneUse()) {

Modified: llvm/trunk/lib/Transforms/Utils/AddrModeMatcher.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/AddrModeMatcher.cpp?rev=75255&r1=75254&r2=75255&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Utils/AddrModeMatcher.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/AddrModeMatcher.cpp Fri Jul 10 12:35:01 2009
@@ -96,7 +96,8 @@
   // X*Scale + C*Scale to addr mode.
   ConstantInt *CI = 0; Value *AddLHS = 0;
   if (isa<Instruction>(ScaleReg) &&  // not a constant expr.
-      match(ScaleReg, m_Add(m_Value(AddLHS), m_ConstantInt(CI)))) {
+      match(ScaleReg, m_Add(m_Value(AddLHS), m_ConstantInt(CI)),
+            *MemoryInst->getParent()->getContext())) {
     TestAddrMode.ScaledReg = AddLHS;
     TestAddrMode.BaseOffs += CI->getSExtValue()*TestAddrMode.Scale;
       





More information about the llvm-commits mailing list