aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/llvm/InstrTypes.h18
-rw-r--r--include/llvm/Support/IRBuilder.h6
-rw-r--r--include/llvm/Support/PatternMatch.h105
-rw-r--r--lib/Transforms/IPO/GlobalOpt.cpp2
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp280
-rw-r--r--lib/Transforms/Scalar/Reassociate.cpp2
-rw-r--r--lib/Transforms/Utils/AddrModeMatcher.cpp3
-rw-r--r--lib/Transforms/Utils/SimplifyCFG.cpp10
-rw-r--r--lib/VMCore/Instructions.cpp18
9 files changed, 210 insertions, 234 deletions
diff --git a/include/llvm/InstrTypes.h b/include/llvm/InstrTypes.h
index ce37521937..faff7986ec 100644
--- a/include/llvm/InstrTypes.h
+++ b/include/llvm/InstrTypes.h
@@ -244,23 +244,17 @@ public:
/// CreateNeg, CreateNot - Create the NEG and NOT
/// instructions out of SUB and XOR instructions.
///
- static BinaryOperator *CreateNeg(LLVMContext &Context,
- Value *Op, const Twine &Name = "",
+ static BinaryOperator *CreateNeg(Value *Op, const Twine &Name = "",
Instruction *InsertBefore = 0);
- static BinaryOperator *CreateNeg(LLVMContext &Context,
- Value *Op, const Twine &Name,
+ static BinaryOperator *CreateNeg(Value *Op, const Twine &Name,
BasicBlock *InsertAtEnd);
- static BinaryOperator *CreateFNeg(LLVMContext &Context,
- Value *Op, const Twine &Name = "",
+ static BinaryOperator *CreateFNeg(Value *Op, const Twine &Name = "",
Instruction *InsertBefore = 0);
- static BinaryOperator *CreateFNeg(LLVMContext &Context,
- Value *Op, const Twine &Name,
+ static BinaryOperator *CreateFNeg(Value *Op, const Twine &Name,
BasicBlock *InsertAtEnd);
- static BinaryOperator *CreateNot(LLVMContext &Context,
- Value *Op, const Twine &Name = "",
+ static BinaryOperator *CreateNot(Value *Op, const Twine &Name = "",
Instruction *InsertBefore = 0);
- static BinaryOperator *CreateNot(LLVMContext &Context,
- Value *Op, const Twine &Name,
+ static BinaryOperator *CreateNot(Value *Op, const Twine &Name,
BasicBlock *InsertAtEnd);
/// isNeg, isFNeg, isNot - Check if the given Value is a
diff --git a/include/llvm/Support/IRBuilder.h b/include/llvm/Support/IRBuilder.h
index 2e24d5ec1d..9e0073a378 100644
--- a/include/llvm/Support/IRBuilder.h
+++ b/include/llvm/Support/IRBuilder.h
@@ -325,17 +325,17 @@ public:
Value *CreateNeg(Value *V, const char *Name = "") {
if (Constant *VC = dyn_cast<Constant>(V))
return Folder.CreateNeg(VC);
- return Insert(BinaryOperator::CreateNeg(Context, V), Name);
+ return Insert(BinaryOperator::CreateNeg(V), Name);
}
Value *CreateFNeg(Value *V, const char *Name = "") {
if (Constant *VC = dyn_cast<Constant>(V))
return Folder.CreateFNeg(VC);
- return Insert(BinaryOperator::CreateFNeg(Context, V), Name);
+ return Insert(BinaryOperator::CreateFNeg(V), Name);
}
Value *CreateNot(Value *V, const char *Name = "") {
if (Constant *VC = dyn_cast<Constant>(V))
return Folder.CreateNot(VC);
- return Insert(BinaryOperator::CreateNot(Context, V), Name);
+ return Insert(BinaryOperator::CreateNot(V), Name);
}
//===--------------------------------------------------------------------===//
diff --git a/include/llvm/Support/PatternMatch.h b/include/llvm/Support/PatternMatch.h
index 5243d4d24e..f085b0ff51 100644
--- a/include/llvm/Support/PatternMatch.h
+++ b/include/llvm/Support/PatternMatch.h
@@ -31,20 +31,19 @@
#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, LLVMContext &Context) {
- return const_cast<Pattern&>(P).match(V, Context);
+bool match(Val *V, const Pattern &P) {
+ return const_cast<Pattern&>(P).match(V);
}
template<typename Class>
struct leaf_ty {
template<typename ITy>
- bool match(ITy *V, LLVMContext&) { return isa<Class>(V); }
+ bool match(ITy *V) { return isa<Class>(V); }
};
/// m_Value() - Match an arbitrary value and ignore it.
@@ -55,7 +54,7 @@ inline leaf_ty<ConstantInt> m_ConstantInt() { return leaf_ty<ConstantInt>(); }
template<int64_t Val>
struct constantint_ty {
template<typename ITy>
- bool match(ITy *V, LLVMContext&) {
+ bool match(ITy *V) {
if (const ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
const APInt &CIV = CI->getValue();
if (Val >= 0)
@@ -78,7 +77,7 @@ inline constantint_ty<Val> m_ConstantInt() {
struct zero_ty {
template<typename ITy>
- bool match(ITy *V, LLVMContext&) {
+ bool match(ITy *V) {
if (const Constant *C = dyn_cast<Constant>(V))
return C->isNullValue();
return false;
@@ -95,7 +94,7 @@ struct bind_ty {
bind_ty(Class *&V) : VR(V) {}
template<typename ITy>
- bool match(ITy *V, LLVMContext&) {
+ bool match(ITy *V) {
if (Class *CV = dyn_cast<Class>(V)) {
VR = CV;
return true;
@@ -116,7 +115,7 @@ struct specificval_ty {
specificval_ty(const Value *V) : Val(V) {}
template<typename ITy>
- bool match(ITy *V, LLVMContext&) {
+ bool match(ITy *V) {
return V == Val;
}
};
@@ -138,15 +137,15 @@ struct BinaryOp_match {
BinaryOp_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
template<typename OpTy>
- bool match(OpTy *V, LLVMContext &Context) {
+ bool match(OpTy *V) {
if (V->getValueID() == Value::InstructionVal + Opcode) {
ConcreteTy *I = cast<ConcreteTy>(V);
- return I->getOpcode() == Opcode && L.match(I->getOperand(0), Context) &&
- R.match(I->getOperand(1), Context);
+ return I->getOpcode() == Opcode && L.match(I->getOperand(0)) &&
+ R.match(I->getOperand(1));
}
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V))
- return CE->getOpcode() == Opcode && L.match(CE->getOperand(0), Context) &&
- R.match(CE->getOperand(1), Context);
+ return CE->getOpcode() == Opcode && L.match(CE->getOperand(0)) &&
+ R.match(CE->getOperand(1));
return false;
}
};
@@ -270,20 +269,20 @@ struct Shr_match {
Shr_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
template<typename OpTy>
- bool match(OpTy *V, LLVMContext &Context) {
+ bool match(OpTy *V) {
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), Context) &&
- R.match(I->getOperand(1), Context);
+ L.match(I->getOperand(0)) &&
+ R.match(I->getOperand(1));
}
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V))
return (CE->getOpcode() == Instruction::LShr ||
CE->getOpcode() == Instruction::AShr) &&
- L.match(CE->getOperand(0), Context) &&
- R.match(CE->getOperand(1), Context);
+ L.match(CE->getOperand(0)) &&
+ R.match(CE->getOperand(1));
return false;
}
};
@@ -310,10 +309,10 @@ struct BinaryOpClass_match {
: Opcode(0), L(LHS), R(RHS) {}
template<typename OpTy>
- bool match(OpTy *V, LLVMContext &Context) {
+ bool match(OpTy *V) {
if (Class *I = dyn_cast<Class>(V))
- if (L.match(I->getOperand(0), Context) &&
- R.match(I->getOperand(1), Context)) {
+ if (L.match(I->getOperand(0)) &&
+ R.match(I->getOperand(1))) {
if (Opcode)
*Opcode = I->getOpcode();
return true;
@@ -356,10 +355,10 @@ struct CmpClass_match {
: Predicate(Pred), L(LHS), R(RHS) {}
template<typename OpTy>
- bool match(OpTy *V, LLVMContext &Context) {
+ bool match(OpTy *V) {
if (Class *I = dyn_cast<Class>(V))
- if (L.match(I->getOperand(0), Context) &&
- R.match(I->getOperand(1), Context)) {
+ if (L.match(I->getOperand(0)) &&
+ R.match(I->getOperand(1))) {
Predicate = I->getPredicate();
return true;
}
@@ -396,11 +395,11 @@ struct SelectClass_match {
: C(Cond), L(LHS), R(RHS) {}
template<typename OpTy>
- bool match(OpTy *V, LLVMContext &Context) {
+ bool match(OpTy *V) {
if (SelectInst *I = dyn_cast<SelectInst>(V))
- return C.match(I->getOperand(0), Context) &&
- L.match(I->getOperand(1), Context) &&
- R.match(I->getOperand(2), Context);
+ return C.match(I->getOperand(0)) &&
+ L.match(I->getOperand(1)) &&
+ R.match(I->getOperand(2));
return false;
}
};
@@ -433,9 +432,9 @@ struct CastClass_match {
CastClass_match(const Op_t &OpMatch) : Op(OpMatch) {}
template<typename OpTy>
- bool match(OpTy *V, LLVMContext &Context) {
+ bool match(OpTy *V) {
if (Class *I = dyn_cast<Class>(V))
- return Op.match(I->getOperand(0), Context);
+ return Op.match(I->getOperand(0));
return false;
}
};
@@ -457,27 +456,27 @@ struct not_match {
not_match(const LHS_t &LHS) : L(LHS) {}
template<typename OpTy>
- bool match(OpTy *V, LLVMContext &Context) {
+ bool match(OpTy *V) {
if (Instruction *I = dyn_cast<Instruction>(V))
if (I->getOpcode() == Instruction::Xor)
- return matchIfNot(I->getOperand(0), I->getOperand(1), Context);
+ return matchIfNot(I->getOperand(0), I->getOperand(1));
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V))
if (CE->getOpcode() == Instruction::Xor)
- return matchIfNot(CE->getOperand(0), CE->getOperand(1), Context);
+ return matchIfNot(CE->getOperand(0), CE->getOperand(1));
if (ConstantInt *CI = dyn_cast<ConstantInt>(V))
- return L.match(ConstantExpr::getNot(CI), Context);
+ return L.match(ConstantExpr::getNot(CI));
return false;
}
private:
- bool matchIfNot(Value *LHS, Value *RHS, LLVMContext &Context) {
+ bool matchIfNot(Value *LHS, Value *RHS) {
if (ConstantInt *CI = dyn_cast<ConstantInt>(RHS))
- return CI->isAllOnesValue() && L.match(LHS, Context);
+ return CI->isAllOnesValue() && L.match(LHS);
if (ConstantInt *CI = dyn_cast<ConstantInt>(LHS))
- return CI->isAllOnesValue() && L.match(RHS, Context);
+ return CI->isAllOnesValue() && L.match(RHS);
if (ConstantVector *CV = dyn_cast<ConstantVector>(RHS))
- return CV->isAllOnesValue() && L.match(LHS, Context);
+ return CV->isAllOnesValue() && L.match(LHS);
if (ConstantVector *CV = dyn_cast<ConstantVector>(LHS))
- return CV->isAllOnesValue() && L.match(RHS, Context);
+ return CV->isAllOnesValue() && L.match(RHS);
return false;
}
};
@@ -493,21 +492,21 @@ struct neg_match {
neg_match(const LHS_t &LHS) : L(LHS) {}
template<typename OpTy>
- bool match(OpTy *V, LLVMContext &Context) {
+ bool match(OpTy *V) {
if (Instruction *I = dyn_cast<Instruction>(V))
if (I->getOpcode() == Instruction::Sub)
- return matchIfNeg(I->getOperand(0), I->getOperand(1), Context);
+ return matchIfNeg(I->getOperand(0), I->getOperand(1));
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V))
if (CE->getOpcode() == Instruction::Sub)
- return matchIfNeg(CE->getOperand(0), CE->getOperand(1), Context);
+ return matchIfNeg(CE->getOperand(0), CE->getOperand(1));
if (ConstantInt *CI = dyn_cast<ConstantInt>(V))
- return L.match(ConstantExpr::getNeg(CI), Context);
+ return L.match(ConstantExpr::getNeg(CI));
return false;
}
private:
- bool matchIfNeg(Value *LHS, Value *RHS, LLVMContext &Context) {
+ bool matchIfNeg(Value *LHS, Value *RHS) {
return LHS == ConstantFP::getZeroValueForNegation(LHS->getType()) &&
- L.match(RHS, Context);
+ L.match(RHS);
}
};
@@ -522,21 +521,21 @@ struct fneg_match {
fneg_match(const LHS_t &LHS) : L(LHS) {}
template<typename OpTy>
- bool match(OpTy *V, LLVMContext &Context) {
+ bool match(OpTy *V) {
if (Instruction *I = dyn_cast<Instruction>(V))
if (I->getOpcode() == Instruction::FSub)
- return matchIfFNeg(I->getOperand(0), I->getOperand(1), Context);
+ return matchIfFNeg(I->getOperand(0), I->getOperand(1));
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V))
if (CE->getOpcode() == Instruction::FSub)
- return matchIfFNeg(CE->getOperand(0), CE->getOperand(1), Context);
+ return matchIfFNeg(CE->getOperand(0), CE->getOperand(1));
if (ConstantFP *CF = dyn_cast<ConstantFP>(V))
- return L.match(ConstantExpr::getFNeg(CF), Context);
+ return L.match(ConstantExpr::getFNeg(CF));
return false;
}
private:
- bool matchIfFNeg(Value *LHS, Value *RHS, LLVMContext &Context) {
+ bool matchIfFNeg(Value *LHS, Value *RHS) {
return LHS == ConstantFP::getZeroValueForNegation(LHS->getType()) &&
- L.match(RHS, Context);
+ L.match(RHS);
}
};
@@ -557,10 +556,10 @@ struct brc_match {
}
template<typename OpTy>
- bool match(OpTy *V, LLVMContext &Context) {
+ bool match(OpTy *V) {
if (BranchInst *BI = dyn_cast<BranchInst>(V))
if (BI->isConditional()) {
- if (Cond.match(BI->getCondition(), Context)) {
+ if (Cond.match(BI->getCondition())) {
T = BI->getSuccessor(0);
F = BI->getSuccessor(1);
return true;
diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp
index 0048b097a8..82af99a7f9 100644
--- a/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/lib/Transforms/IPO/GlobalOpt.cpp
@@ -891,7 +891,7 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV,
case ICmpInst::ICMP_ULE:
case ICmpInst::ICMP_SLE:
case ICmpInst::ICMP_EQ:
- LV = BinaryOperator::CreateNot(Context, LV, "notinit", CI);
+ LV = BinaryOperator::CreateNot(LV, "notinit", CI);
break;
case ICmpInst::ICMP_NE:
case ICmpInst::ICMP_UGE:
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index de9db8c713..a62bbe92c7 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -1841,8 +1841,7 @@ namespace {
// AddRHS - Implements: X + X --> X << 1
struct AddRHS {
Value *RHS;
- LLVMContext *Context;
- AddRHS(Value *rhs, LLVMContext *C) : RHS(rhs), Context(C) {}
+ explicit AddRHS(Value *rhs) : RHS(rhs) {}
bool shouldApply(Value *LHS) const { return LHS == RHS; }
Instruction *apply(BinaryOperator &Add) const {
return BinaryOperator::CreateShl(Add.getOperand(0),
@@ -1854,11 +1853,10 @@ struct AddRHS {
// iff C1&C2 == 0
struct AddMaskingAnd {
Constant *C2;
- LLVMContext *Context;
- AddMaskingAnd(Constant *c, LLVMContext *C) : C2(c), Context(C) {}
+ explicit AddMaskingAnd(Constant *c) : C2(c) {}
bool shouldApply(Value *LHS) const {
ConstantInt *C1;
- return match(LHS, m_And(m_Value(), m_ConstantInt(C1)), *Context) &&
+ return match(LHS, m_And(m_Value(), m_ConstantInt(C1))) &&
ConstantExpr::getAnd(C1, C2)->isNullValue();
}
Instruction *apply(BinaryOperator &Add) const {
@@ -2079,7 +2077,7 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
ConstantInt *XorRHS = 0;
Value *XorLHS = 0;
if (isa<ConstantInt>(RHSC) &&
- match(LHS, m_Xor(m_Value(XorLHS), m_ConstantInt(XorRHS)), *Context)) {
+ match(LHS, m_Xor(m_Value(XorLHS), m_ConstantInt(XorRHS)))) {
uint32_t TySizeBits = I.getType()->getScalarSizeInBits();
const APInt& RHSVal = cast<ConstantInt>(RHSC)->getValue();
@@ -2128,7 +2126,7 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
// X + X --> X << 1
if (I.getType()->isInteger()) {
- if (Instruction *Result = AssociativeOpt(I, AddRHS(RHS, Context)))
+ if (Instruction *Result = AssociativeOpt(I, AddRHS(RHS)))
return Result;
if (Instruction *RHSI = dyn_cast<Instruction>(RHS)) {
@@ -2150,7 +2148,7 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
if (Value *RHSV = dyn_castNegVal(RHS)) {
Instruction *NewAdd = BinaryOperator::CreateAdd(LHSV, RHSV, "sum");
InsertNewInstBefore(NewAdd, I);
- return BinaryOperator::CreateNeg(*Context, NewAdd);
+ return BinaryOperator::CreateNeg(NewAdd);
}
}
@@ -2185,8 +2183,8 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
// (A & C1)+(B & C2) --> (A & C1)|(B & C2) iff C1&C2 == 0
- if (match(RHS, m_And(m_Value(), m_ConstantInt(C2)), *Context))
- if (Instruction *R = AssociativeOpt(I, AddMaskingAnd(C2, Context)))
+ if (match(RHS, m_And(m_Value(), m_ConstantInt(C2))))
+ if (Instruction *R = AssociativeOpt(I, AddMaskingAnd(C2)))
return R;
// A+B --> A|B iff A and B have no bits set in common.
@@ -2209,8 +2207,8 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
// 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)), *Context) &&
- match(RHS, m_Mul(m_Value(Y), m_Value(Z)), *Context)) {
+ if (match(LHS, m_Mul(m_Value(W), m_Value(X))) &&
+ match(RHS, m_Mul(m_Value(Y), m_Value(Z)))) {
if (W != Y) {
if (W == Z) {
std::swap(Y, Z);
@@ -2232,12 +2230,12 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
if (ConstantInt *CRHS = dyn_cast<ConstantInt>(RHS)) {
Value *X = 0;
- if (match(LHS, m_Not(m_Value(X)), *Context)) // ~X + C --> (C-1) - X
+ if (match(LHS, m_Not(m_Value(X)))) // ~X + C --> (C-1) - X
return BinaryOperator::CreateSub(SubOne(CRHS), X);
// (X & FF00) + xx00 -> (X+xx00) & FF00
if (LHS->hasOneUse() &&
- match(LHS, m_And(m_Value(X), m_ConstantInt(C2)), *Context)) {
+ match(LHS, m_And(m_Value(X), m_ConstantInt(C2)))) {
Constant *Anded = ConstantExpr::getAnd(CRHS, C2);
if (Anded == CRHS) {
// See if all bits from the first bit set in the Add RHS up are included
@@ -2280,12 +2278,12 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
// 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(), *Context) &&
- match(TV, m_Sub(m_Value(N), m_Specific(A)), *Context))
+ if (match(FV, m_Zero()) &&
+ match(TV, m_Sub(m_Value(N), m_Specific(A))))
// Fold the add into the true select value.
return SelectInst::Create(SI->getCondition(), N, A);
- if (match(TV, m_Zero(), *Context) &&
- match(FV, m_Sub(m_Value(N), m_Specific(A)), *Context))
+ if (match(TV, m_Zero()) &&
+ match(FV, m_Sub(m_Value(N), m_Specific(A))))
// Fold the add into the false select value.
return SelectInst::Create(SI->getCondition(), A, N);
}
@@ -2425,11 +2423,11 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
if (ConstantInt *C = dyn_cast<ConstantInt>(Op0)) {
// Replace (-1 - A) with (~A)...
if (C->isAllOnesValue())
- return BinaryOperator::CreateNot(*Context, Op1);
+ return BinaryOperator::CreateNot(Op1);
// C - ~X == X + (1+C)
Value *X = 0;
- if (match(Op1, m_Not(m_Value(X)), *Context))
+ if (match(Op1, m_Not(m_Value(X))))
return BinaryOperator::CreateAdd(X, AddOne(C));
// -(X >>u 31) -> (X >>s 31)
@@ -2478,10 +2476,10 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
if (BinaryOperator *Op1I = dyn_cast<BinaryOperator>(Op1)) {
if (Op1I->getOpcode() == Instruction::Add) {
if (Op1I->getOperand(0) == Op0) // X-(X+Y) == -Y
- return BinaryOperator::CreateNeg(*Context, Op1I->getOperand(1),
+ return BinaryOperator::CreateNeg(Op1I->getOperand(1),
I.getName());
else if (Op1I->getOperand(1) == Op0) // X-(Y+X) == -Y
- return BinaryOperator::CreateNeg(*Context, Op1I->getOperand(0),
+ return BinaryOperator::CreateNeg(Op1I->getOperand(0),
I.getName());
else if (ConstantInt *CI1 = dyn_cast<ConstantInt>(I.getOperand(0))) {
if (ConstantInt *CI2 = dyn_cast<ConstantInt>(Op1I->getOperand(1)))
@@ -2512,8 +2510,7 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
Value *OtherOp = Op1I->getOperand(Op1I->getOperand(0) == Op0);
Value *NewNot =
- InsertNewInstBefore(BinaryOperator::CreateNot(*Context,
- OtherOp, "B.not"), I);
+ InsertNewInstBefore(BinaryOperator::CreateNot(OtherOp, "B.not"), I);
return BinaryOperator::CreateAnd(Op0, NewNot);
}
@@ -2544,7 +2541,7 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
return ReplaceInstUsesWith(I, Op0I->getOperand(0));
} else if (Op0I->getOpcode() == Instruction::Sub) {
if (Op0I->getOperand(0) == Op1) // (X-Y)-X == -Y
- return BinaryOperator::CreateNeg(*Context, Op0I->getOperand(1),
+ return BinaryOperator::CreateNeg(Op0I->getOperand(1),
I.getName());
}
}
@@ -2571,10 +2568,10 @@ Instruction *InstCombiner::visitFSub(BinaryOperator &I) {
if (BinaryOperator *Op1I = dyn_cast<BinaryOperator>(Op1)) {
if (Op1I->getOpcode() == Instruction::FAdd) {
if (Op1I->getOperand(0) == Op0) // X-(X+Y) == -Y
- return BinaryOperator::CreateFNeg(*Context, Op1I->getOperand(1),
+ return BinaryOperator::CreateFNeg(Op1I->getOperand(1),
I.getName());
else if (Op1I->getOperand(1) == Op0) // X-(Y+X) == -Y
- return BinaryOperator::CreateFNeg(*Context, Op1I->getOperand(0),
+ return BinaryOperator::CreateFNeg(Op1I->getOperand(0),
I.getName());
}
}
@@ -2635,7 +2632,7 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) {
if (CI->equalsInt(1)) // X * 1 == X
return ReplaceInstUsesWith(I, Op0);
if (CI->isAllOnesValue()) // X * -1 == 0 - X
- return BinaryOperator::CreateNeg(*Context, Op0, I.getName());
+ return BinaryOperator::CreateNeg(Op0, I.getName());
const APInt& Val = cast<ConstantInt>(CI)->getValue();
if (Val.isPowerOf2()) { // Replace X*(2^C) with X << C
@@ -2648,7 +2645,7 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) {
if (ConstantVector *Op1V = dyn_cast<ConstantVector>(Op1)) {
if (Op1V->isAllOnesValue()) // X * -1 == 0 - X
- return BinaryOperator::CreateNeg(*Context, Op0, I.getName());
+ return BinaryOperator::CreateNeg(Op0, I.getName());
// As above, vector X*splat(1.0) -> X in all defined cases.
if (Constant *Splat = Op1V->getSplatValue()) {
@@ -3061,7 +3058,7 @@ Instruction *InstCombiner::visitSDiv(BinaryOperator &I) {
if (ConstantInt *RHS = dyn_cast<ConstantInt>(Op1)) {
// sdiv X, -1 == -X
if (RHS->isAllOnesValue())
- return BinaryOperator::CreateNeg(*Context, Op0);
+ return BinaryOperator::CreateNeg(Op0);
// sdiv X, C --> ashr X, log2(C)
if (cast<SDivOperator>(&I)->isExact() &&
@@ -3083,7 +3080,7 @@ Instruction *InstCombiner::visitSDiv(BinaryOperator &I) {
return BinaryOperator::CreateUDiv(Op0, Op1, I.getName());
}
ConstantInt *ShiftedInt;
- if (match(Op1, m_Shl(m_ConstantInt(ShiftedInt), m_Value()), *Context) &&
+ if (match(Op1, m_Shl(m_ConstantInt(ShiftedInt), m_Value())) &&
ShiftedInt->getValue().isPowerOf2()) {
// X sdiv (1 << Y) -> X udiv (1 << Y) ( -> X u>> Y)
// Safe because the only negative value (1 << Y) can take on is
@@ -3763,9 +3760,9 @@ Instruction *InstCombiner::FoldAndOfICmps(Instruction &I,
// This only handles icmp of constants: (icmp1 A, C1) & (icmp2 B, C2).
if (!match(LHS, m_ICmp(LHSCC, m_Value(Val),
- m_ConstantInt(LHSCst)), *Context) ||
+ m_ConstantInt(LHSCst))) ||
!match(RHS, m_ICmp(RHSCC, m_Value(Val2),
- m_ConstantInt(RHSCst)), *Context))
+ m_ConstantInt(RHSCst))))
return 0;
// (icmp ult A, C) & (icmp ult B, C) --> (icmp ult (A|B), C)
@@ -4091,7 +4088,7 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
ConstantInt *A = dyn_cast<ConstantInt>(Op0LHS);
if (!(A && A->isZero()) && // avoid infinite recursion.
MaskedValueIsZero(Op0LHS, Mask)) {
- Instruction *NewNeg = BinaryOperator::CreateNeg(*Context, Op0RHS);
+ Instruction *NewNeg = BinaryOperator::CreateNeg(Op0RHS);
InsertNewInstBefore(NewNeg, I);
return BinaryOperator::CreateAnd(NewNeg, AndRHS);
}
@@ -4169,35 +4166,35 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
Instruction *Or = BinaryOperator::CreateOr(Op0NotVal, Op1NotVal,
I.getName()+".demorgan");
InsertNewInstBefore(Or, I);
- return BinaryOperator::CreateNot(*Context, Or);
+ return BinaryOperator::CreateNot(Or);
}
{
Value *A = 0, *B = 0, *C = 0, *D = 0;
- if (match(Op0, m_Or(m_Value(A), m_Value(B)), *Context)) {
+ if (match(Op0, m_Or(m_Value(A), m_Value(B)))) {
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))), *Context)) {
+ if (match(Op1, m_Not(m_And(m_Value(C), m_Value(D))))) {
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)), *Context)) {
+ if (match(Op1, m_Or(m_Value(A), m_Value(B)))) {
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))), *Context)) {
+ if (match(Op0, m_Not(m_And(m_Value(C), m_Value(D))))) {
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)), *Context)) {
+ match(Op0, m_Xor(m_Value(A), m_Value(B)))) {
if (A == Op1) { // (A^B)&A -> A&(A^B)
I.swapOperands(); // Simplify below
std::swap(Op0, Op1);
@@ -4209,24 +4206,24 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
}
if (Op1->hasOneUse() &&
- match(Op1, m_Xor(m_Value(A), m_Value(B)), *Context)) {
+ match(Op1, m_Xor(m_Value(A), m_Value(B)))) {
if (B == Op0) { // B&(A^B) -> B&(B^A)
cast<BinaryOperator>(Op1)->swapOperands();
std::swap(A, B);
}
if (A == Op0) { // A&(A^B) -> A & ~B
- Instruction *NotB = BinaryOperator::CreateNot(*Context, B, "tmp");
+ Instruction *NotB = BinaryOperator::CreateNot(B, "tmp");
InsertNewInstBefore(NotB, I);
return BinaryOperator::CreateAnd(A, NotB);
}
}
// (A&((~A)|B)) -> A&B
- 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))
+ 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)))))
return BinaryOperator::CreateAnd(A, Op1);
- 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))
+ 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)))))
return BinaryOperator::CreateAnd(A, Op0);
}
@@ -4453,18 +4450,18 @@ static Instruction *MatchSelectFromAndOr(Value *A, Value *B,
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)), *Context))
+ if (!match(A, m_SelectCst<-1, 0>(m_Value(Cond))))
return 0;
// ((cond?-1:0)&C) | (B&(cond?0:-1)) -> cond ? C : B.
- if (match(D, m_SelectCst<0, -1>(m_Specific(Cond)), *Context))
+ if (match(D, m_SelectCst<0, -1>(m_Specific(Cond))))
return SelectInst::Create(Cond, C, B);
- if (match(D, m_Not(m_SelectCst<-1, 0>(m_Specific(Cond))), *Context))
+ if (match(D, m_Not(m_SelectCst<-1, 0>(m_Specific(Cond)))))
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)), *Context))
+ if (match(B, m_SelectCst<0, -1>(m_Specific(Cond))))
return SelectInst::Create(Cond, C, D);
- if (match(B, m_Not(m_SelectCst<-1, 0>(m_Specific(Cond))), *Context))
+ if (match(B, m_Not(m_SelectCst<-1, 0>(m_Specific(Cond)))))
return SelectInst::Create(Cond, C, D);
return 0;
}
@@ -4478,9 +4475,9 @@ Instruction *InstCombiner::FoldOrOfICmps(Instruction &I,
// This only handles icmp of constants: (icmp1 A, C1) | (icmp2 B, C2).
if (!match(LHS, m_ICmp(LHSCC, m_Value(Val),
- m_ConstantInt(LHSCst)), *Context) ||
+ m_ConstantInt(LHSCst))) ||
!match(RHS, m_ICmp(RHSCC, m_Value(Val2),
- m_ConstantInt(RHSCst)), *Context))
+ m_ConstantInt(RHSCst))))
return 0;
// From here on, we only handle:
@@ -4717,7 +4714,7 @@ Instruction *InstCombiner::FoldOrWithConstants(BinaryOperator &I, Value *Op,
Value *V1 = 0;
ConstantInt *CI2 = 0;
- if (!match(Op, m_And(m_Value(V1), m_ConstantInt(CI2)), *Context)) return 0;
+ if (!match(Op, m_And(m_Value(V1), m_ConstantInt(CI2)))) return 0;
APInt Xor = CI1->getValue() ^ CI2->getValue();
if (!Xor.isAllOnesValue()) return 0;
@@ -4759,7 +4756,7 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
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)), *Context) &&
+ if (match(Op0, m_And(m_Value(X), m_ConstantInt(C1))) &&
isOnlyUse(Op0)) {
Instruction *Or = BinaryOperator::CreateOr(X, RHS);
InsertNewInstBefore(Or, I);
@@ -4769,7 +4766,7 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
}
// (X ^ C1) | C2 --> (X | C2) ^ (C1&~C2)
- if (match(Op0, m_Xor(m_Value(X), m_ConstantInt(C1)), *Context) &&
+ if (match(Op0, m_Xor(m_Value(X), m_ConstantInt(C1))) &&
isOnlyUse(Op0)) {
Instruction *Or = BinaryOperator::CreateOr(X, RHS);
InsertNewInstBefore(Or, I);
@@ -4790,26 +4787,26 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
Value *A = 0, *B = 0;
ConstantInt *C1 = 0, *C2 = 0;
- if (match(Op0, m_And(m_Value(A), m_Value(B)), *Context))
+ if (match(Op0, m_And(m_Value(A), m_Value(B))))
if (A == Op1 || B == Op1) // (A & ?) | A --> A
return ReplaceInstUsesWith(I, Op1);
- if (match(Op1, m_And(m_Value(A), m_Value(B)), *Context))
+ if (match(Op1, m_And(m_Value(A), m_Value(B))))
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()), *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 (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 (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)), *Context) &&
+ match(Op0, m_Xor(m_Value(A), m_ConstantInt(C1))) &&
MaskedValueIsZero(Op1, C1->getValue())) {
Instruction *NOr = BinaryOperator::CreateOr(A, Op1);
InsertNewInstBefore(NOr, I);
@@ -4819,7 +4816,7 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
// Y|(X^C) -> (X|Y)^C iff Y&C == 0
if (Op1->hasOneUse() &&
- match(Op1, m_Xor(m_Value(A), m_ConstantInt(C1)), *Context) &&
+ match(Op1, m_Xor(m_Value(A), m_ConstantInt(C1))) &&
MaskedValueIsZero(Op0, C1->getValue())) {
Instruction *NOr = BinaryOperator::CreateOr(A, Op0);
InsertNewInstBefore(NOr, I);
@@ -4829,8 +4826,8 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
// (A & C)|(B & D)
Value *C = 0, *D = 0;
- if (match(Op0, m_And(m_Value(A), m_Value(C)), *Context) &&
- match(Op1, m_And(m_Value(B), m_Value(D)), *Context)) {
+ if (match(Op0, m_And(m_Value(A), m_Value(C))) &&
+ match(Op1, m_And(m_Value(B), m_Value(D)))) {
Value *V1 = 0, *V2 = 0, *V3 = 0;
C1 = dyn_cast<ConstantInt>(C);
C2 = dyn_cast<ConstantInt>(D);
@@ -4840,7 +4837,7 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
// 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)), *Context)) {
+ match(A, m_Add(m_Value(V1), m_Value(V2)))) {
// Add commutes, try both ways.
if (V1 == B && MaskedValueIsZero(V2, C2->getValue()))
return ReplaceInstUsesWith(I, A);
@@ -4849,7 +4846,7 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
}
// Or commutes, try both ways.
if ((C1->getValue() & (C1->getValue()+1)) == 0 &&
- match(B, m_Add(m_Value(V1), m_Value(V2)), *Context)) {
+ match(B, m_Add(m_Value(V1), m_Value(V2)))) {
// Add commutes, try both ways.
if (V1 == A && MaskedValueIsZero(V2, C1->getValue()))
return ReplaceInstUsesWith(I, B);
@@ -4890,20 +4887,20 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
return Match;
// ((A&~B)|(~A&B)) -> A^B
- if ((match(C, m_Not(m_Specific(D)), *Context) &&
- match(B, m_Not(m_Specific(A)), *Context)))
+ if ((match(C, m_Not(m_Specific(D))) &&
+ match(B, m_Not(m_Specific(A)))))
return BinaryOperator::CreateXor(A, D);
// ((~B&A)|(~A&B)) -> A^B
- if ((match(A, m_Not(m_Specific(D)), *Context) &&
- match(B, m_Not(m_Specific(C)), *Context)))
+ if ((match(A, m_Not(m_Specific(D))) &&
+ match(B, m_Not(m_Specific(C)))))
return BinaryOperator::CreateXor(C, D);
// ((A&~B)|(B&~A)) -> A^B
- if ((match(C, m_Not(m_Specific(B)), *Context) &&
- match(D, m_Not(m_Specific(A)), *Context)))
+ if ((match(C, m_Not(m_Specific(B))) &&
+ match(D, m_Not(m_Specific(A)))))
return BinaryOperator::CreateXor(A, B);
// ((~B&A)|(B&~A)) -> A^B
- if ((match(A, m_Not(m_Specific(B)), *Context) &&
- m