aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms/Scalar
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2009-07-09 23:48:35 +0000
committerOwen Anderson <resistor@mac.com>2009-07-09 23:48:35 +0000
commit333c40096561218bc3597cf153c0a3895274414c (patch)
treebc6f5f739c43dec91104275aec30e16f30a7610e /lib/Transforms/Scalar
parent53674361efd42f9dd7c4d293132106839ab3b893 (diff)
downloadexternal_llvm-333c40096561218bc3597cf153c0a3895274414c.zip
external_llvm-333c40096561218bc3597cf153c0a3895274414c.tar.gz
external_llvm-333c40096561218bc3597cf153c0a3895274414c.tar.bz2
This started as a small change, I swear. Unfortunately, lots of things call the [I|F]CmpInst constructors. Who knew!?
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75200 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar')
-rw-r--r--lib/Transforms/Scalar/CodeGenPrepare.cpp3
-rw-r--r--lib/Transforms/Scalar/GVN.cpp2
-rw-r--r--lib/Transforms/Scalar/GVNPRE.cpp5
-rw-r--r--lib/Transforms/Scalar/IndVarSimplify.cpp8
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp292
-rw-r--r--lib/Transforms/Scalar/JumpThreading.cpp2
-rw-r--r--lib/Transforms/Scalar/LICM.cpp2
-rw-r--r--lib/Transforms/Scalar/LoopIndexSplit.cpp16
-rw-r--r--lib/Transforms/Scalar/LoopRotation.cpp2
-rw-r--r--lib/Transforms/Scalar/LoopStrengthReduce.cpp9
-rw-r--r--lib/Transforms/Scalar/LoopUnswitch.cpp2
-rw-r--r--lib/Transforms/Scalar/PredicateSimplifier.cpp4
-rw-r--r--lib/Transforms/Scalar/ScalarReplAggregates.cpp4
-rw-r--r--lib/Transforms/Scalar/TailDuplication.cpp2
14 files changed, 185 insertions, 168 deletions
diff --git a/lib/Transforms/Scalar/CodeGenPrepare.cpp b/lib/Transforms/Scalar/CodeGenPrepare.cpp
index 85e9243..b3a26ac 100644
--- a/lib/Transforms/Scalar/CodeGenPrepare.cpp
+++ b/lib/Transforms/Scalar/CodeGenPrepare.cpp
@@ -520,7 +520,8 @@ static bool OptimizeCmpExpression(CmpInst *CI) {
BasicBlock::iterator InsertPt = UserBB->getFirstNonPHI();
InsertedCmp =
- CmpInst::Create(CI->getOpcode(), CI->getPredicate(), CI->getOperand(0),
+ CmpInst::Create(*DefBB->getContext(), CI->getOpcode(),
+ CI->getPredicate(), CI->getOperand(0),
CI->getOperand(1), "", InsertPt);
MadeChange = true;
}
diff --git a/lib/Transforms/Scalar/GVN.cpp b/lib/Transforms/Scalar/GVN.cpp
index 962ba71..b2fdd24 100644
--- a/lib/Transforms/Scalar/GVN.cpp
+++ b/lib/Transforms/Scalar/GVN.cpp
@@ -1627,7 +1627,7 @@ bool GVN::performPRE(Function& F) {
// will be available in the predecessor by the time we need them. Any
// that weren't original present will have been instantiated earlier
// in this loop.
- Instruction* PREInstr = CurInst->clone();
+ Instruction* PREInstr = CurInst->clone(*Context);
bool success = true;
for (unsigned i = 0, e = CurInst->getNumOperands(); i != e; ++i) {
Value *Op = PREInstr->getOperand(i);
diff --git a/lib/Transforms/Scalar/GVNPRE.cpp b/lib/Transforms/Scalar/GVNPRE.cpp
index 0f3153f..af7e039 100644
--- a/lib/Transforms/Scalar/GVNPRE.cpp
+++ b/lib/Transforms/Scalar/GVNPRE.cpp
@@ -861,7 +861,7 @@ Value* GVNPRE::phi_translate(Value* V, BasicBlock* pred, BasicBlock* succ) {
newOp1, newOp2,
BO->getName()+".expr");
else if (CmpInst* C = dyn_cast<CmpInst>(U))
- newVal = CmpInst::Create(C->getOpcode(),
+ newVal = CmpInst::Create(*Context, C->getOpcode(),
C->getPredicate(),
newOp1, newOp2,
C->getName()+".expr");
@@ -1679,7 +1679,8 @@ void GVNPRE::insertion_pre(Value* e, BasicBlock* BB,
BO->getName()+".gvnpre",
(*PI)->getTerminator());
else if (CmpInst* C = dyn_cast<CmpInst>(U))
- newVal = CmpInst::Create(C->getOpcode(), C->getPredicate(), s1, s2,
+ newVal = CmpInst::Create(*Context, C->getOpcode(),
+ C->getPredicate(), s1, s2,
C->getName()+".gvnpre",
(*PI)->getTerminator());
else if (ShuffleVectorInst* S = dyn_cast<ShuffleVectorInst>(U))
diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp
index 03a17d6..365589d 100644
--- a/lib/Transforms/Scalar/IndVarSimplify.cpp
+++ b/lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -188,7 +188,7 @@ ICmpInst *IndVarSimplify::LinearFunctionTestReplace(Loop *L,
<< (Opcode == ICmpInst::ICMP_NE ? "!=" : "==") << "\n"
<< " RHS:\t" << *RHS << "\n";
- ICmpInst *Cond = new ICmpInst(Opcode, CmpIndVar, ExitCnt, "exitcond", BI);
+ ICmpInst *Cond = new ICmpInst(BI, Opcode, CmpIndVar, ExitCnt, "exitcond");
Instruction *OrigCond = cast<Instruction>(BI->getCondition());
// It's tempting to use replaceAllUsesWith here to fully replace the old
@@ -294,7 +294,7 @@ void IndVarSimplify::RewriteLoopExitValues(Loop *L,
if (ExitBlocks.size() != 1) {
// Clone the PHI and delete the original one. This lets IVUsers and
// any other maps purge the original user from their records.
- PHINode *NewPN = PN->clone();
+ PHINode *NewPN = PN->clone(*Context);
NewPN->takeName(PN);
NewPN->insertBefore(PN);
PN->replaceAllUsesWith(NewPN);
@@ -726,8 +726,8 @@ void IndVarSimplify::HandleFloatingPointIV(Loop *L, PHINode *PH) {
ConstantInt *NewEV = Context->getConstantInt(Type::Int32Ty, intEV);
Value *LHS = (EVIndex == 1 ? NewPHI->getIncomingValue(1) : NewEV);
Value *RHS = (EVIndex == 1 ? NewEV : NewPHI->getIncomingValue(1));
- ICmpInst *NewEC = new ICmpInst(NewPred, LHS, RHS, EC->getNameStart(),
- EC->getParent()->getTerminator());
+ ICmpInst *NewEC = new ICmpInst(EC->getParent()->getTerminator(),
+ NewPred, LHS, RHS, EC->getNameStart());
// In the following deltions, PH may become dead and may be deleted.
// Use a WeakVH to observe whether this happens.
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 8d36f74..89b4c65 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -1924,8 +1924,8 @@ static Value *FoldOperationIntoSelectOperand(Instruction &I, Value *SO,
if (BinaryOperator *BO = dyn_cast<BinaryOperator>(&I))
New = BinaryOperator::Create(BO->getOpcode(), Op0, Op1,SO->getName()+".op");
else if (CmpInst *CI = dyn_cast<CmpInst>(&I))
- New = CmpInst::Create(CI->getOpcode(), CI->getPredicate(), Op0, Op1,
- SO->getName()+".cmp");
+ New = CmpInst::Create(*Context, CI->getOpcode(), CI->getPredicate(),
+ Op0, Op1, SO->getName()+".cmp");
else {
assert(0 && "Unknown binary instruction type!");
abort();
@@ -2014,7 +2014,7 @@ Instruction *InstCombiner::FoldOpIntoPhi(Instruction &I) {
PN->getIncomingValue(i), C, "phitmp",
NonConstBB->getTerminator());
else if (CmpInst *CI = dyn_cast<CmpInst>(&I))
- InV = CmpInst::Create(CI->getOpcode(),
+ InV = CmpInst::Create(*Context, CI->getOpcode(),
CI->getPredicate(),
PN->getIncomingValue(i), C, "phitmp",
NonConstBB->getTerminator());
@@ -3042,7 +3042,8 @@ Instruction *InstCombiner::visitUDiv(BinaryOperator &I) {
// X udiv C, where C >= signbit
if (C->getValue().isNegative()) {
- Value *IC = InsertNewInstBefore(new ICmpInst(ICmpInst::ICMP_ULT, Op0, C),
+ Value *IC = InsertNewInstBefore(new ICmpInst(*Context,
+ ICmpInst::ICMP_ULT, Op0, C),
I);
return SelectInst::Create(IC, Context->getNullValue(I.getType()),
Context->getConstantInt(I.getType(), 1));
@@ -3395,26 +3396,26 @@ static Value *getICmpValue(bool sign, unsigned code, Value *LHS, Value *RHS,
case 0: return Context->getConstantIntFalse();
case 1:
if (sign)
- return new ICmpInst(ICmpInst::ICMP_SGT, LHS, RHS);
+ return new ICmpInst(*Context, ICmpInst::ICMP_SGT, LHS, RHS);
else
- return new ICmpInst(ICmpInst::ICMP_UGT, LHS, RHS);
- case 2: return new ICmpInst(ICmpInst::ICMP_EQ, LHS, RHS);
+ return new ICmpInst(*Context, ICmpInst::ICMP_UGT, LHS, RHS);
+ case 2: return new ICmpInst(*Context, ICmpInst::ICMP_EQ, LHS, RHS);
case 3:
if (sign)
- return new ICmpInst(ICmpInst::ICMP_SGE, LHS, RHS);
+ return new ICmpInst(*Context, ICmpInst::ICMP_SGE, LHS, RHS);
else
- return new ICmpInst(ICmpInst::ICMP_UGE, LHS, RHS);
+ return new ICmpInst(*Context, ICmpInst::ICMP_UGE, LHS, RHS);
case 4:
if (sign)
- return new ICmpInst(ICmpInst::ICMP_SLT, LHS, RHS);
+ return new ICmpInst(*Context, ICmpInst::ICMP_SLT, LHS, RHS);
else
- return new ICmpInst(ICmpInst::ICMP_ULT, LHS, RHS);
- case 5: return new ICmpInst(ICmpInst::ICMP_NE, LHS, RHS);
+ return new ICmpInst(*Context, ICmpInst::ICMP_ULT, LHS, RHS);
+ case 5: return new ICmpInst(*Context, ICmpInst::ICMP_NE, LHS, RHS);
case 6:
if (sign)
- return new ICmpInst(ICmpInst::ICMP_SLE, LHS, RHS);
+ return new ICmpInst(*Context, ICmpInst::ICMP_SLE, LHS, RHS);
else
- return new ICmpInst(ICmpInst::ICMP_ULE, LHS, RHS);
+ return new ICmpInst(*Context, ICmpInst::ICMP_ULE, LHS, RHS);
case 7: return Context->getConstantIntTrue();
}
}
@@ -3428,39 +3429,39 @@ static Value *getFCmpValue(bool isordered, unsigned code,
default: assert(0 && "Illegal FCmp code!");
case 0:
if (isordered)
- return new FCmpInst(FCmpInst::FCMP_ORD, LHS, RHS);
+ return new FCmpInst(*Context, FCmpInst::FCMP_ORD, LHS, RHS);
else
- return new FCmpInst(FCmpInst::FCMP_UNO, LHS, RHS);
+ return new FCmpInst(*Context, FCmpInst::FCMP_UNO, LHS, RHS);
case 1:
if (isordered)
- return new FCmpInst(FCmpInst::FCMP_OGT, LHS, RHS);
+ return new FCmpInst(*Context, FCmpInst::FCMP_OGT, LHS, RHS);
else
- return new FCmpInst(FCmpInst::FCMP_UGT, LHS, RHS);
+ return new FCmpInst(*Context, FCmpInst::FCMP_UGT, LHS, RHS);
case 2:
if (isordered)
- return new FCmpInst(FCmpInst::FCMP_OEQ, LHS, RHS);
+ return new FCmpInst(*Context, FCmpInst::FCMP_OEQ, LHS, RHS);
else
- return new FCmpInst(FCmpInst::FCMP_UEQ, LHS, RHS);
+ return new FCmpInst(*Context, FCmpInst::FCMP_UEQ, LHS, RHS);
case 3:
if (isordered)
- return new FCmpInst(FCmpInst::FCMP_OGE, LHS, RHS);
+ return new FCmpInst(*Context, FCmpInst::FCMP_OGE, LHS, RHS);
else
- return new FCmpInst(FCmpInst::FCMP_UGE, LHS, RHS);
+ return new FCmpInst(*Context, FCmpInst::FCMP_UGE, LHS, RHS);
case 4:
if (isordered)
- return new FCmpInst(FCmpInst::FCMP_OLT, LHS, RHS);
+ return new FCmpInst(*Context, FCmpInst::FCMP_OLT, LHS, RHS);
else
- return new FCmpInst(FCmpInst::FCMP_ULT, LHS, RHS);
+ return new FCmpInst(*Context, FCmpInst::FCMP_ULT, LHS, RHS);
case 5:
if (isordered)
- return new FCmpInst(FCmpInst::FCMP_ONE, LHS, RHS);
+ return new FCmpInst(*Context, FCmpInst::FCMP_ONE, LHS, RHS);
else
- return new FCmpInst(FCmpInst::FCMP_UNE, LHS, RHS);
+ return new FCmpInst(*Context, FCmpInst::FCMP_UNE, LHS, RHS);
case 6:
if (isordered)
- return new FCmpInst(FCmpInst::FCMP_OLE, LHS, RHS);
+ return new FCmpInst(*Context, FCmpInst::FCMP_OLE, LHS, RHS);
else
- return new FCmpInst(FCmpInst::FCMP_ULE, LHS, RHS);
+ return new FCmpInst(*Context, FCmpInst::FCMP_ULE, LHS, RHS);
case 7: return Context->getConstantIntTrue();
}
}
@@ -3665,13 +3666,13 @@ Instruction *InstCombiner::InsertRangeTest(Value *V, Constant *Lo, Constant *Hi,
if (Inside) {
if (Lo == Hi) // Trivially false.
- return new ICmpInst(ICmpInst::ICMP_NE, V, V);
+ return new ICmpInst(*Context, ICmpInst::ICMP_NE, V, V);
// V >= Min && V < Hi --> V < Hi
if (cast<ConstantInt>(Lo)->isMinValue(isSigned)) {
ICmpInst::Predicate pred = (isSigned ?
ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT);
- return new ICmpInst(pred, V, Hi);
+ return new ICmpInst(*Context, pred, V, Hi);
}
// Emit V-Lo <u Hi-Lo
@@ -3679,18 +3680,18 @@ Instruction *InstCombiner::InsertRangeTest(Value *V, Constant *Lo, Constant *Hi,
Instruction *Add = BinaryOperator::CreateAdd(V, NegLo, V->getName()+".off");
InsertNewInstBefore(Add, IB);
Constant *UpperBound = Context->getConstantExprAdd(NegLo, Hi);
- return new ICmpInst(ICmpInst::ICMP_ULT, Add, UpperBound);
+ return new ICmpInst(*Context, ICmpInst::ICMP_ULT, Add, UpperBound);
}
if (Lo == Hi) // Trivially true.
- return new ICmpInst(ICmpInst::ICMP_EQ, V, V);
+ return new ICmpInst(*Context, ICmpInst::ICMP_EQ, V, V);
// V < Min || V >= Hi -> V > Hi-1
Hi = SubOne(cast<ConstantInt>(Hi), Context);
if (cast<ConstantInt>(Lo)->isMinValue(isSigned)) {
ICmpInst::Predicate pred = (isSigned ?
ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT);
- return new ICmpInst(pred, V, Hi);
+ return new ICmpInst(*Context, pred, V, Hi);
}
// Emit V-Lo >u Hi-1-Lo
@@ -3699,7 +3700,7 @@ Instruction *InstCombiner::InsertRangeTest(Value *V, Constant *Lo, Constant *Hi,
Instruction *Add = BinaryOperator::CreateAdd(V, NegLo, V->getName()+".off");
InsertNewInstBefore(Add, IB);
Constant *LowerBound = Context->getConstantExprAdd(NegLo, Hi);
- return new ICmpInst(ICmpInst::ICMP_UGT, Add, LowerBound);
+ return new ICmpInst(*Context, ICmpInst::ICMP_UGT, Add, LowerBound);
}
// isRunOfOnes - Returns true iff Val consists of one contiguous run of 1s with
@@ -3795,7 +3796,7 @@ Instruction *InstCombiner::FoldAndOfICmps(Instruction &I,
LHSCst->getValue().isPowerOf2()) {
Instruction *NewOr = BinaryOperator::CreateOr(Val, Val2);
InsertNewInstBefore(NewOr, I);
- return new ICmpInst(LHSCC, NewOr, LHSCst);
+ return new ICmpInst(*Context, LHSCC, NewOr, LHSCst);
}
// From here on, we only handle:
@@ -3855,11 +3856,11 @@ Instruction *InstCombiner::FoldAndOfICmps(Instruction &I,
default: assert(0 && "Unknown integer condition code!");
case ICmpInst::ICMP_ULT:
if (LHSCst == SubOne(RHSCst, Context)) // (X != 13 & X u< 14) -> X < 13
- return new ICmpInst(ICmpInst::ICMP_ULT, Val, LHSCst);
+ return new ICmpInst(*Context, ICmpInst::ICMP_ULT, Val, LHSCst);
break; // (X != 13 & X u< 15) -> no change
case ICmpInst::ICMP_SLT:
if (LHSCst == SubOne(RHSCst, Context)) // (X != 13 & X s< 14) -> X < 13
- return new ICmpInst(ICmpInst::ICMP_SLT, Val, LHSCst);
+ return new ICmpInst(*Context, ICmpInst::ICMP_SLT, Val, LHSCst);
break; // (X != 13 & X s< 15) -> no change
case ICmpInst::ICMP_EQ: // (X != 13 & X == 15) -> X == 15
case ICmpInst::ICMP_UGT: // (X != 13 & X u> 15) -> X u> 15
@@ -3871,7 +3872,7 @@ Instruction *InstCombiner::FoldAndOfICmps(Instruction &I,
Instruction *Add = BinaryOperator::CreateAdd(Val, AddCST,
Val->getName()+".off");
InsertNewInstBefore(Add, I);
- return new ICmpInst(ICmpInst::ICMP_UGT, Add,
+ return new ICmpInst(*Context, ICmpInst::ICMP_UGT, Add,
Context->getConstantInt(Add->getType(), 1));
}
break; // (X != 13 & X != 15) -> no change
@@ -3917,7 +3918,7 @@ Instruction *InstCombiner::FoldAndOfICmps(Instruction &I,
break;
case ICmpInst::ICMP_NE:
if (RHSCst == AddOne(LHSCst, Context)) // (X u> 13 & X != 14) -> X u> 14
- return new ICmpInst(LHSCC, Val, RHSCst);
+ return new ICmpInst(*Context, LHSCC, Val, RHSCst);
break; // (X u> 13 & X != 15) -> no change
case ICmpInst::ICMP_ULT: // (X u> 13 & X u< 15) -> (X-14) <u 1
return InsertRangeTest(Val, AddOne(LHSCst, Context),
@@ -3936,7 +3937,7 @@ Instruction *InstCombiner::FoldAndOfICmps(Instruction &I,
break;
case ICmpInst::ICMP_NE:
if (RHSCst == AddOne(LHSCst, Context)) // (X s> 13 & X != 14) -> X s> 14
- return new ICmpInst(LHSCC, Val, RHSCst);
+ return new ICmpInst(*Context, LHSCC, Val, RHSCst);
break; // (X s> 13 & X != 15) -> no change
case ICmpInst::ICMP_SLT: // (X s> 13 & X s< 15) -> (X-14) s< 1
return InsertRangeTest(Val, AddOne(LHSCst, Context),
@@ -4048,8 +4049,8 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
// (1 << x) & 1 --> zext(x == 0)
// (1 >> x) & 1 --> zext(x == 0)
if (AndRHSMask == 1 && Op0LHS == AndRHS) {
- Instruction *NewICmp = new ICmpInst(ICmpInst::ICMP_EQ, Op0RHS,
- Context->getNullValue(I.getType()));
+ Instruction *NewICmp = new ICmpInst(*Context, ICmpInst::ICMP_EQ,
+ Op0RHS, Context->getNullValue(I.getType()));
InsertNewInstBefore(NewICmp, I);
return new ZExtInst(NewICmp, I.getType());
}
@@ -4231,8 +4232,8 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
// false.
if (LHSC->getValueAPF().isNaN() || RHSC->getValueAPF().isNaN())
return ReplaceInstUsesWith(I, Context->getConstantIntFalse());
- return new FCmpInst(FCmpInst::FCMP_ORD, LHS->getOperand(0),
- RHS->getOperand(0));
+ return new FCmpInst(*Context, FCmpInst::FCMP_ORD,
+ LHS->getOperand(0), RHS->getOperand(0));
}
} else {
Value *Op0LHS, *Op0RHS, *Op1LHS, *Op1RHS;
@@ -4247,7 +4248,8 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
if (Op0LHS == Op1LHS && Op0RHS == Op1RHS) {
// Simplify (fcmp cc0 x, y) & (fcmp cc1 x, y).
if (Op0CC == Op1CC)
- return new FCmpInst((FCmpInst::Predicate)Op0CC, Op0LHS, Op0RHS);
+ return new FCmpInst(*Context, (FCmpInst::Predicate)Op0CC,
+ Op0LHS, Op0RHS);
else if (Op0CC == FCmpInst::FCMP_FALSE ||
Op1CC == FCmpInst::FCMP_FALSE)
return ReplaceInstUsesWith(I, Context->getConstantIntFalse());
@@ -4532,7 +4534,7 @@ Instruction *InstCombiner::FoldOrOfICmps(Instruction &I,
Val->getName()+".off");
InsertNewInstBefore(Add, I);
AddCST = Context->getConstantExprSub(AddOne(RHSCst, Context), LHSCst);
- return new ICmpInst(ICmpInst::ICMP_ULT, Add, AddCST);
+ return new ICmpInst(*Context, ICmpInst::ICMP_ULT, Add, AddCST);
}
break; // (X == 13 | X == 15) -> no change
case ICmpInst::ICMP_UGT: // (X == 13 | X u> 14) -> no change
@@ -4932,8 +4934,8 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
// Otherwise, no need to compare the two constants, compare the
// rest.
- return new FCmpInst(FCmpInst::FCMP_UNO, LHS->getOperand(0),
- RHS->getOperand(0));
+ return new FCmpInst(*Context, FCmpInst::FCMP_UNO,
+ LHS->getOperand(0), RHS->getOperand(0));
}
} else {
Value *Op0LHS, *Op0RHS, *Op1LHS, *Op1RHS;
@@ -4948,7 +4950,8 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
if (Op0LHS == Op1LHS && Op0RHS == Op1RHS) {
// Simplify (fcmp cc0 x, y) | (fcmp cc1 x, y).
if (Op0CC == Op1CC)
- return new FCmpInst((FCmpInst::Predicate)Op0CC, Op0LHS, Op0RHS);
+ return new FCmpInst(*Context, (FCmpInst::Predicate)Op0CC,
+ Op0LHS, Op0RHS);
else if (Op0CC == FCmpInst::FCMP_TRUE ||
Op1CC == FCmpInst::FCMP_TRUE)
return ReplaceInstUsesWith(I, Context->getConstantIntTrue());
@@ -5046,11 +5049,11 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
if (RHS == Context->getConstantIntTrue() && Op0->hasOneUse()) {
// xor (cmp A, B), true = not (cmp A, B) = !cmp A, B
if (ICmpInst *ICI = dyn_cast<ICmpInst>(Op0))
- return new ICmpInst(ICI->getInversePredicate(),
+ return new ICmpInst(*Context, ICI->getInversePredicate(),
ICI->getOperand(0), ICI->getOperand(1));
if (FCmpInst *FCI = dyn_cast<FCmpInst>(Op0))
- return new FCmpInst(FCI->getInversePredicate(),
+ return new FCmpInst(*Context, FCI->getInversePredicate(),
FCI->getOperand(0), FCI->getOperand(1));
}
@@ -5064,6 +5067,7 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
Context->getConstantIntTrue(),
Op0C->getDestTy())) {
Instruction *NewCI = InsertNewInstBefore(CmpInst::Create(
+ *Context,
CI->getOpcode(), CI->getInversePredicate(),
CI->getOperand(0), CI->getOperand(1)), I);
NewCI->takeName(CI);
@@ -5554,7 +5558,7 @@ Instruction *InstCombiner::FoldGEPICmp(User *GEPLHS, Value *RHS,
// If not, synthesize the offset the hard way.
if (Offset == 0)
Offset = EmitGEPOffset(GEPLHS, I, *this);
- return new ICmpInst(ICmpInst::getSignedPredicate(Cond), Offset,
+ return new ICmpInst(*Context, ICmpInst::getSignedPredicate(Cond), Offset,
Context->getNullValue(Offset->getType()));
} else if (User *GEPRHS = dyn_castGetElementPtr(RHS)) {
// If the base pointers are different, but the indices are the same, just
@@ -5572,7 +5576,7 @@ Instruction *InstCombiner::FoldGEPICmp(User *GEPLHS, Value *RHS,
// If all indices are the same, just compare the base pointers.
if (IndicesTheSame)
- return new ICmpInst(ICmpInst::getSignedPredicate(Cond),
+ return new ICmpInst(*Context, ICmpInst::getSignedPredicate(Cond),
GEPLHS->getOperand(0), GEPRHS->getOperand(0));
// Otherwise, the base pointers are different and the indices are
@@ -5629,7 +5633,8 @@ Instruction *InstCombiner::FoldGEPICmp(User *GEPLHS, Value *RHS,
Value *LHSV = GEPLHS->getOperand(DiffOperand);
Value *RHSV = GEPRHS->getOperand(DiffOperand);
// Make sure we do a signed comparison here.
- return new ICmpInst(ICmpInst::getSignedPredicate(Cond), LHSV, RHSV);
+ return new ICmpInst(*Context,
+ ICmpInst::getSignedPredicate(Cond), LHSV, RHSV);
}
}
@@ -5640,7 +5645,7 @@ Instruction *InstCombiner::FoldGEPICmp(User *GEPLHS, Value *RHS,
// ((gep Ptr, OFFSET1) cmp (gep Ptr, OFFSET2) ---> (OFFSET1 cmp OFFSET2)
Value *L = EmitGEPOffset(GEPLHS, I, *this);
Value *R = EmitGEPOffset(GEPRHS, I, *this);
- return new ICmpInst(ICmpInst::getSignedPredicate(Cond), L, R);
+ return new ICmpInst(*Context, ICmpInst::getSignedPredicate(Cond), L, R);
}
}
return 0;
@@ -5835,7 +5840,7 @@ Instruction *InstCombiner::FoldFCmp_IntToFP_Cst(FCmpInst &I,
// Lower this FP comparison into an appropriate integer version of the
// comparison.
- return new ICmpInst(Pred, LHSI->getOperand(0), RHSInt);
+ return new ICmpInst(*Context, Pred, LHSI->getOperand(0), RHSInt);
}
Instruction *InstCombiner::visitFCmpInst(FCmpInst &I) {
@@ -5923,14 +5928,14 @@ Instruction *InstCombiner::visitFCmpInst(FCmpInst &I) {
// Fold the known value into the constant operand.
Op1 = Context->getConstantExprCompare(I.getPredicate(), C, RHSC);
// Insert a new FCmp of the other select operand.
- Op2 = InsertNewInstBefore(new FCmpInst(I.getPredicate(),
+ Op2 = InsertNewInstBefore(new FCmpInst(*Context, I.getPredicate(),
LHSI->getOperand(2), RHSC,
I.getName()), I);
} else if (Constant *C = dyn_cast<Constant>(LHSI->getOperand(2))) {
// Fold the known value into the constant operand.
Op2 = Context->getConstantExprCompare(I.getPredicate(), C, RHSC);
// Insert a new FCmp of the other select operand.
- Op1 = InsertNewInstBefore(new FCmpInst(I.getPredicate(),
+ Op1 = InsertNewInstBefore(new FCmpInst(*Context, I.getPredicate(),
LHSI->getOperand(1), RHSC,
I.getName()), I);
}
@@ -6030,7 +6035,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
if (I.isEquality() && CI->isNullValue() &&
match(Op0, m_Sub(m_Value(A), m_Value(B)))) {
// (icmp cond A B) if cond is equality
- return new ICmpInst(I.getPredicate(), A, B);
+ return new ICmpInst(*Context, I.getPredicate(), A, B);
}
// If we have an icmp le or icmp ge instruction, turn it into the
@@ -6041,19 +6046,23 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
case ICmpInst::ICMP_ULE:
if (CI->isMaxValue(false)) // A <=u MAX -> TRUE
return ReplaceInstUsesWith(I, Context->getConstantIntTrue());
- return new ICmpInst(ICmpInst::ICMP_ULT, Op0, AddOne(CI, Context));
+ return new ICmpInst(*Context, ICmpInst::ICMP_ULT, Op0,
+ AddOne(CI, Context));
case ICmpInst::ICMP_SLE:
if (CI->isMaxValue(true)) // A <=s MAX -> TRUE
return ReplaceInstUsesWith(I, Context->getConstantIntTrue());
- return new ICmpInst(ICmpInst::ICMP_SLT, Op0, AddOne(CI, Context));
+ return new ICmpInst(*Context, ICmpInst::ICMP_SLT, Op0,
+ AddOne(CI, Context));
case ICmpInst::ICMP_UGE:
if (CI->isMinValue(false)) // A >=u MIN -> TRUE
return ReplaceInstUsesWith(I, Context->getConstantIntTrue());
- return new ICmpInst( ICmpInst::ICMP_UGT, Op0, SubOne(CI, Context));
+ return new ICmpInst(*Context, ICmpInst::ICMP_UGT, Op0,
+ SubOne(CI, Context));
case ICmpInst::ICMP_SGE:
if (CI->isMinValue(true)) // A >=s MIN -> TRUE
return ReplaceInstUsesWith(I, Context->getConstantIntTrue());
- return new ICmpInst(ICmpInst::ICMP_SGT, Op0, SubOne(CI, Context));
+ return new ICmpInst(*Context, ICmpInst::ICMP_SGT, Op0,
+ SubOne(CI, Context));
}
// If this comparison is a normal comparison, it demands all
@@ -6099,10 +6108,10 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
// figured out that the LHS is a constant. Just constant fold this now so
// that code below can assume that Min != Max.
if (!isa<Constant>(Op0) && Op0Min == Op0Max)
- return new ICmpInst(I.getPredicate(),
+ return new ICmpInst(*Context, I.getPredicate(),
Context->getConstantInt(Op0Min), Op1);
if (!isa<Constant>(Op1) && Op1Min == Op1Max)
- return new ICmpInst(I.getPredicate(), Op0,
+ return new ICmpInst(*Context, I.getPredicate(), Op0,
Context->getConstantInt(Op1Min));
// Based on the range information we know about the LHS, see if we can
@@ -6123,14 +6132,15 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
if (Op0Min.uge(Op1Max)) // A <u B -> false if min(A) >= max(B)
return ReplaceInstUsesWith(I, Context->getConstantIntFalse());
if (Op1Min == Op0Max) // A <u B -> A != B if max(A) == min(B)
- return new ICmpInst(ICmpInst::ICMP_NE, Op0, Op1);
+ return new ICmpInst(*Context, ICmpInst::ICMP_NE, Op0, Op1);
if (ConstantInt *CI = dyn_cast<ConstantInt>(Op1)) {
if (Op1Max == Op0Min+1) // A <u C -> A == C-1 if min(A)+1 == C
- return new ICmpInst(ICmpInst::ICMP_EQ, Op0, SubOne(CI, Context));
+ return new ICmpInst(*Context, ICmpInst::ICMP_EQ, Op0,
+ SubOne(CI, Context));
// (x <u 2147483648) -> (x >s -1) -> true if sign bit clear
if (CI->isMinValue(true))
- return new ICmpInst(ICmpInst::ICMP_SGT, Op0,
+ return new ICmpInst(*Context, ICmpInst::ICMP_SGT, Op0,
Context->getConstantIntAllOnesValue(Op0->getType()));
}
break;
@@ -6141,14 +6151,15 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
return ReplaceInstUsesWith(I, Context->getConstantIntFalse());
if (Op1Max == Op0Min) // A >u B -> A != B if min(A) == max(B)
- return new ICmpInst(ICmpInst::ICMP_NE, Op0, Op1);
+ return new ICmpInst(*Context, ICmpInst::ICMP_NE, Op0, Op1);
if (ConstantInt *CI = dyn_cast<ConstantInt>(Op1)) {
if (Op1Min == Op0Max-1) // A >u C -> A == C+1 if max(a)-1 == C
- return new ICmpInst(ICmpInst::ICMP_EQ, Op0, AddOne(CI, Context));
+ return new ICmpInst(*Context, ICmpInst::ICMP_EQ, Op0,
+ AddOne(CI, Context));
// (x >u 2147483647) -> (x <s 0) -> true if sign bit set
if (CI->isMaxValue(true))
- return new ICmpInst(ICmpInst::ICMP_SLT, Op0,
+ return new ICmpInst(*Context, ICmpInst::ICMP_SLT, Op0,
Context->getNullValue(Op0->getType()));
}
break;
@@ -6158,10 +6169,11 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
if (Op0Min.sge(Op1Max)) // A <s B -> false if min(A) >= max(C)
return ReplaceInstUsesWith(I, Context->getConstantIntFalse());
if (Op1Min == Op0Max) // A <s B -> A != B if max(A) == min(B)
- return new ICmpInst(ICmpInst::ICMP_NE, Op0, Op1);
+ return new ICmpInst(*Context, ICmpInst::ICMP_NE, Op0, Op1);
if (ConstantInt *CI = dyn_cast<ConstantInt>(Op1)) {
if (Op1Max == Op0Min+1) // A <s C -> A == C-1 if min(A)+1 == C
- return new ICmpInst(ICmpInst::ICMP_EQ, Op0, SubOne(CI, Context));
+ return new ICmpInst(*Context, ICmpInst::ICMP_EQ, Op0,
+ SubOne(CI, Context));
}
break;
case ICmpInst::ICMP_SGT:
@@ -6171,10 +6183,11 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
return ReplaceInstUsesWith(I, Context->getConstantIntFalse());
if (Op1Max == Op0Min) // A >s B -> A != B if min(A) == max(B)
- return new ICmpInst(ICmpInst::ICMP_NE, Op0, Op1);
+ return new ICmpInst(*Context, ICmpInst::ICMP_NE, Op0, Op1);
if (ConstantInt *CI = dyn_cast<ConstantInt>(Op1)) {
if (Op1Min == Op0Max-1) // A >s C -> A == C+1 if max(A)-1 == C
- return new ICmpInst(ICmpInst::ICMP_EQ, Op0, AddOne(CI, Context));
+ return new ICmpInst(*Context, ICmpInst::ICMP_EQ, Op0,
+ AddOne(CI, Context));
}
break;
case ICmpInst::ICMP_SGE:
@@ -6212,7 +6225,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
if (I.isSignedPredicate() &&
((Op0KnownZero.isNegative() && Op1KnownZero.isNegative()) ||
(Op0KnownOne.isNegative() && Op1KnownOne.isNegative())))
- return new ICmpInst(I.getUnsignedPredicate(), Op0, Op1);
+ return new ICmpInst(*Context, I.getUnsignedPredicate(), Op0, Op1);
}
// Test if the ICmpInst instruction is used exclusively by a select as
@@ -6254,7 +6267,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
break;
}
if (isAllZeros)
- return new ICmpInst(I.getPredicate(), LHSI->getOperand(0),
+ return new ICmpInst(*Context, I.getPredicate(), LHSI->getOperand(0),
Context->getNullValue(LHSI->getOperand(0)->getType()));
}
break;
@@ -6277,14 +6290,14 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
// Fold the known value into the constant operand.
Op1 = Context->getConstantExprICmp(I.getPredicate(), C, RHSC);
// Insert a new ICmp of the other select operand.
- Op2 = InsertNewInstBefore(new ICmpInst(I.getPredicate(),
+ Op2 = InsertNewInstBefore(new ICmpInst(*Context, I.getPredicate(),
LHSI->getOperand(2), RHSC,
I.getName()), I);
} else if (Constant *C = dyn_cast<Constant>(LHSI->getOperand(2))) {
// Fold the known value into the constant operand.
Op2 = Context->getConstantExprICmp(I.getPredicate(), C, RHSC);
// Insert a new ICmp of the other select operand.
- Op1 = InsertNewInstBefore(new ICmpInst(I.getPredicate(),
+ Op1 = InsertNewInstBefore(new ICmpInst(*Context, I.getPredicate(),
LHSI->getOperand(1), RHSC,
I.getName()), I);
}
@@ -6339,7 +6352,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
Op1 = InsertBitCastBefore(Op1, Op0->getType(), I);
}
}
- return new ICmpInst(I.getPredicate(), Op0, Op1);
+ return new ICmpInst(*Context, I.getPredicate(), Op0, Op1);
}
}
@@ -6366,7 +6379,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
case Instruction::Sub:
case Instruction::Xor:
if (I.isEquality()) // a+x icmp eq/ne b+x --> a icmp b
- return new ICmpInst(I.getPredicate(), Op0I->getOperand(0),
+ return new ICmpInst(*Context, I.getPredicate(), Op0I->getOperand(0),
Op1I->getOperand(0));
// icmp u/s (a ^ signbit), (b ^ signbit) --> icmp s/u a, b
if (ConstantInt *CI = dyn_cast<ConstantInt>(Op0I->getOperand(1))) {
@@ -6374,7 +6387,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
ICmpInst::Predicate Pred = I.isSignedPredicate()
? I.getUnsignedPredicate()
: I.getSignedPredicate();
- return new ICmpInst(Pred, Op0I->getOperand(0),
+ return new ICmpInst(*Context, Pred, Op0I->getOperand(0),
Op1I->getOperand(0));
}
@@ -6383,7 +6396,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
? I.getUnsignedPredicate()
: I.getSignedPredicate();
Pred = I.getSwappedPredicate(Pred);
- return new ICmpInst(Pred, Op0I->getOperand(0),
+ return new ICmpInst(*Context, Pred, Op0I->getOperand(0),
Op1I->getOperand(0));
}
}
@@ -6407,7 +6420,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
Mask);
InsertNewInstBefore(And1, I);
InsertNewInstBefore(And2, I);
- return new ICmpInst(I.getPredicate(), And1, And2);
+ return new ICmpInst(*Context, I.getPredicate(), And1, And2);
}
}
break;
@@ -6420,7 +6433,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
{ Value *A, *B;
if (match(Op0, m_Not(m_Value(A))) &&
match(Op1, m_Not(m_Value(B))))
- return new ICmpInst(I.getPredicate(), B, A);
+ return new ICmpInst(*Context, I.getPredicate(), B, A);
}
if (I.isEquality()) {
@@ -6429,12 +6442,12 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
// -x == -y --> x == y
if (match(Op0, m_Neg(m_Value(A))) &&
match(Op1, m_Neg(m_Value(B))))
- return new ICmpInst(I.getPredicate(), A, B);
+ return new ICmpInst(*Context, I.getPredicate(), A, B);
if (match(Op0, m_Xor(m_Value(A), m_Value(B)))) {
if (A == Op1 || B == Op1) { // (A^B) == A -> B == 0
Value *OtherVal = A == Op1 ? B : A;
- return new ICmpInst(I.getPredicate(), OtherVal,
+ return new ICmpInst(*Context, I.getPredicate(), OtherVal,
Context->getNullValue(A->getType()));
}
@@ -6446,15 +6459,15 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
Constant *NC =
Context->getConstantInt(C1->getValue() ^ C2->getValue());
Instruction *Xor = BinaryOperator::CreateXor(C, NC, "tmp");
- return new ICmpInst(I.getPredicate(), A,
+ return new ICmpInst(*Context, I.getPredicate(), A,
InsertNewInstBefore(Xor, I));
}
// A^B == A^D -> B == D
- if (A == C) return new ICmpInst(I.getPredicate(), B, D);
- if (A == D) return new ICmpInst(I.getPredicate(), B, C);
- if (B == C) return new ICmpInst(I.getPredicate(), A, D);
- if (B == D) return new ICmpInst(I.getPredicate(), A, C);
+ if (A == C) return new ICmpInst(*Context, I.getPredicate(), B, D);
+ if (A == D) return new ICmpInst(*Context, I.getPredicate(), B, C);
+ if (B == C) return new ICmpInst(*Context, I.getPredicate(), A, D);
+ if (B == D) return new ICmpInst(*Context, I.getPredicate(), A, C);
}
}
@@ -6462,18 +6475,18 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
(A == Op0 || B == Op0)) {
// A == (A^B) -> B == 0
Value *OtherVal = A == Op0 ? B : A;
- return new ICmpInst(I.getPredicate(), OtherVal,
+ return new ICmpInst(*Context, I.getPredicate(), OtherVal,
Context->getNullValue(A->getType()));
}
// (A-B) == A -> B == 0
if (match(Op0, m_Sub(m_Specific(Op1), m_Value(B))))
- return new ICmpInst(I.getPredicate(), B,
+ 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))))
- return new ICmpInst(I.getPredicate(), B,
+ return new ICmpInst(*Context, I.getPredicate(), B,
Context->getNullValue(B->getType()));
// (X&Z) == (Y&Z) -> (X^Y) & Z == 0
@@ -6618,10 +6631,10 @@ Instruction *InstCombiner::FoldICmpDivCst(ICmpInst &ICI, BinaryOperator *DivI,
if (LoOverflow && HiOverflow)
return ReplaceInstUsesWith(ICI, Context->getConstantIntFalse());
else if (HiOverflow)
- return new ICmpInst(DivIsSigned ? ICmpInst::ICMP_SGE :
+ return new ICmpInst(*Context, DivIsSigned ? ICmpInst::ICMP_SGE :
ICmpInst::ICMP_UGE, X, LoBound);
else if (LoOverflow)
- return new ICmpInst(DivIsSigned ? ICmpInst::ICMP_SLT :
+ return new ICmpInst(*Context, DivIsSigned ? ICmpInst::ICMP_SLT :
ICmpInst::ICMP_ULT, X, HiBound);
else
return InsertRangeTest(X, LoBound, HiBound, DivIsSigned, true, ICI);
@@ -6629,10 +6642,10 @@ Instruction *InstCombiner::FoldICmpDivCst(ICmpInst &ICI, BinaryOperator *DivI,
if (LoOverflow && HiOverflow)
return ReplaceInstUsesWith(ICI, Context->getConstantIntTrue());
else if (HiOverflow)
- return new ICmpInst(DivIsSigned ? ICmpInst::ICMP_SLT :
+ return new ICmpInst(*Context, DivIsSigned ? ICmpInst::ICMP_SLT :
ICmpInst::ICMP_ULT, X, LoBound);
else if (LoOverflow)
- return new ICmpInst(DivIsSigned ? ICmpInst::ICMP_SGE :
+ return new ICmpInst(*Context, DivIsSigned ? ICmpInst::ICMP_SGE :
ICmpInst::ICMP_UGE, X, HiBound);
else
return InsertRangeTest(X, LoBound, HiBound, DivIsSigned, false, ICI);
@@ -6642,7 +6655,7 @@ Instruction *InstCombiner::FoldICmpDivCst(ICmpInst &ICI, BinaryOperator *DivI,
return ReplaceInstUsesWith(ICI, Context->getConstantIntTrue());
if (LoOverflow == -1) // Low bound is less than input range.
return ReplaceInstUsesWith(ICI, Context->getConstantIntFalse());
- return new ICmpInst(Pred, X, LoBound);
+ return new ICmpInst(*Context, Pred, X, LoBound);
case ICmpInst::ICMP_UGT:
case ICmpInst::ICMP_SGT:
if (HiOverflow == +1) // High bound greater than input range.
@@ -6650,9 +6663,9 @@ Instruction *InstCombiner::FoldICmpDivCst(ICmpInst &ICI, BinaryOperator *DivI,
else if (HiOverflow == -1) // High bound less than input range.
return ReplaceInstUsesWith(ICI, Context->getConstantIntTrue());
if (Pred == ICmpInst::ICMP_UGT)
- return new ICmpInst(ICmpInst::ICMP_UGE, X, HiBound);
+ return new ICmpInst(*Context, ICmpInst::ICMP_UGE, X, HiBound);
else
- return new ICmpInst(ICmpInst::ICMP_SGE, X, HiBound);
+ return new ICmpInst(*Context, ICmpInst::ICMP_SGE, X, HiBound);
}
}
@@ -6681,7 +6694,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
APInt NewRHS(RHS->getValue());
NewRHS.zext(SrcBits);
NewRHS |= KnownOne;
- return new ICmpInst(ICI.getPredicate(), LHSI->getOperand(0),
+ return new ICmpInst(*Context, ICI.getPredicate(), LHSI->getOperand(0),
Context->getConstantInt(NewRHS));
}
}
@@ -6710,10 +6723,10 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
isTrueIfPositive ^= true;
if (isTrueIfPositive)
- return new ICmpInst(ICmpInst::ICMP_SGT, CompareVal,
+ return new ICmpInst(*Context, ICmpInst::ICMP_SGT, CompareVal,
SubOne(RHS, Context));
else
- return new ICmpInst(ICmpInst::ICMP_SLT, CompareVal,
+ return new ICmpInst(*Context, ICmpInst::ICMP_SLT, CompareVal,
AddOne(RHS, Context));
}
@@ -6724,7 +6737,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
ICmpInst::Predicate Pred = ICI.isSignedPredicate()
? ICI.getUnsignedPredicate()
: ICI.getSignedPredicate();
- return new ICmpInst(Pred, LHSI->getOperand(0),
+ return new ICmpInst(*Context, Pred, LHSI->getOperand(0),
Context->getConstantInt(RHSV ^ SignBit));
}
@@ -6735,7 +6748,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
? ICI.getUnsignedPredicate()
: ICI.getSignedPredicate();
Pred = ICI.getSwappedPredicate(Pred);
- return new ICmpInst(Pred, LHSI->getOperand(0),
+ return new ICmpInst(*Context, Pred, LHSI->getOperand(0),
Context->getConstantInt(RHSV ^ NotSignBit));
}
}
@@ -6767,7 +6780,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
BinaryOperator::CreateAnd(Cast->getOperand(0),
Context->getConstantInt(NewCST),LHSI->getName());
InsertNewInstBefore(NewAnd, ICI);
- return new ICmpInst(ICI.getPredicate(), NewAnd,
+ return new ICmpInst(*Context, ICI.getPredicate(), NewAnd,
Context->getConstantInt(NewCI));
}
}
@@ -6900,7 +6913,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
BinaryOperator::CreateAnd(LHSI->getOperand(0),
Mask, LHSI->getName()+".mask");
Value *And = InsertNewInstBefore(AndI, ICI);
- return new ICmpInst(ICI.getPredicate(), And,
+ return new ICmpInst(*Context, ICI.getPredicate(), And,
Context->getConstantInt(RHSV.lshr(ShAmtVal)));
}
}
@@ -6917,7 +6930,8 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
Mask, LHSI->getName()+".mask");
Value *And = InsertNewInstBefore(AndI, ICI);
- return new ICmpInst(TrueIfSigned ? ICmpInst::ICMP_NE : ICmpInst::ICMP_EQ,
+ return new ICmpInst(*Context,
+ TrueIfSigned ? ICmpInst::ICMP_NE : ICmpInst::ICMP_EQ,
And, Context->getNullValue(And->getType()));
}
break;
@@ -6958,7 +6972,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
if (LHSI->hasOneUse() &&
MaskedValueIsZero(LHSI->getOperand(0),
APInt::getLowBitsSet(Comp.getBitWidth(), ShAmtVal))) {
- return new ICmpInst(ICI.getPredicate(), LHSI->getOperand(0),
+ return new ICmpInst(*Context, ICI.getPredicate(), LHSI->getOperand(0),
Context->getConstantExprShl(RHS, ShAmt));
}
@@ -6971,7 +6985,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
BinaryOperator::CreateAnd(LHSI->getOperand(0),
Mask, LHSI->getName()+".mask");
Value *And = InsertNewInstBefore(AndI, ICI);
- return new ICmpInst(ICI.getPredicate(), And,
+ return new ICmpInst(*Context, ICI.getPredicate(), And,
Context->getConstantExprShl(RHS, ShAmt));
}
break;
@@ -7004,18 +7018,18 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
if (ICI.isSignedPredicate()) {
if (CR.getLower().isSignBit()) {
- return new ICmpInst(ICmpInst::ICMP_SLT, LHSI->getOperand(0),
+ return new ICmpInst(*Context, ICmpInst::ICMP_SLT, LHSI->getOperand(0),
Context->getConstantInt(CR.getUpper()));
} else if (CR.getUpper().isSignBit()) {
- return new ICmpInst(ICmpInst::ICMP_SGE, LHSI->getOperand(0),
+ return new ICmpInst(*Context, ICmpInst::ICMP_SGE, LHSI->getOperand(0),
Context->getConstantInt(CR.getLower()));
}
} else {
if (CR.getLower().isMinValue()) {
- return new ICmpInst(ICmpInst::ICMP_ULT, LHSI->getOperand(0),
+ return new ICmpInst(*Context, ICmpInst::ICMP_ULT, LHSI->getOperand(0),
Context->getConstantInt(CR.getUpper()));
} else if (CR.getUpper().isMinValue()) {
- return new ICmpInst(ICmpInst::ICMP_UGE, LHSI->getOperand(0),
+ return new ICmpInst(*Context, ICmpInst::ICMP_UGE, LHSI->getOperand(0),
Context->getConstantInt(CR.getLower()));
}
}
@@ -7040,7 +7054,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
BinaryOperator::CreateURem(BO->getOperand(0), BO->getOperand(1),
BO->getName());
InsertNewInstBefore(NewRem, ICI);
- return new ICmpInst(ICI.getPredicate(), NewRem,
+ return new ICmpInst(*Context, ICI.getPredicate(), NewRem,
Context->getNullValue(BO->getType()));
}
}
@@ -7049,7 +7063,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
// Replace ((add A, B) != C) with (A != C-B) if B & C are constants.
if (ConstantInt *BOp1C = dyn_cast<ConstantInt>(BO->getOperand(1))) {
if (BO->hasOneUse())
- return new ICmpInst(ICI.getPredicate(), BO->getOperand(0),
+ return new ICmpInst(*Context, ICI.getPredicate(), BO->getOperand(0),
Context->getConstantExprSub(RHS, BOp1C));
} else if (RHSV == 0) {
// Replace ((add A, B) != 0) with (A != -B) if A or B is
@@ -7057,14 +7071,14 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
Value *BOp0 = BO->getOperand(0), *BOp1 = BO->getOperand(1);
if (Value *NegVal = dyn_castNegVal(BOp1, Context))
- return new ICmpInst(ICI.getPredicate(), BOp0, NegVal);
+ return new ICmpInst(*Context, ICI.getPredicate(), BOp0, NegVal);
else if (Value *NegVal = dyn_castNegVal(BOp0, Context))
- return new ICmpInst(ICI.getPredicate(), NegVal, BOp1);
+ return new ICmpInst(*Context, ICI.getPredicate(), NegVal, BOp1);
else if (BO->hasOneUse()) {
Instruction *Neg = BinaryOperator::CreateNeg(BOp1);
InsertNewInstBefore(Neg, ICI);
Neg->takeName(BO);
- return new ICmpInst(ICI.getPredicate(), BOp0, Neg);
+ return new ICmpInst(*Context, ICI.getPredicate(), BOp0, Neg);
}
}
break;
@@ -7072,14 +7086,14 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
// For the xor case, we can xor two constants together, eliminating
// the explicit xor.
if (Constant *BOC = dyn_cast<Constant>(BO->getOperand(1)))
- return new ICmpInst(ICI.getPredicate(), BO->getOperand(0),
+ return new ICmpInst(*Context, ICI.getPredicate(), BO->getOperand(0),
Context->getConstantExprXor(RHS, BOC));
// FALLTHROUGH
case Instruction::Sub:
// Replace (([sub|xor] A, B) != 0) with (A != B)
if (RHSV == 0)
- return new ICmpInst(ICI.getPredicate(), BO->getOperand(0),
+ return new ICmpInst(*Context, ICI.getPredicate(), BO->getOperand(0),
BO->getOperand(1));
break;
@@ -7106,7 +7120,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
// If we have ((X & C) == C), turn it into ((X & C) != 0).
if (RHS == BOC && RHSV.isPowerOf2())
- return new ICmpInst(isICMP_NE ? ICmpInst::ICMP_EQ :
+ return new ICmpInst(*Context, isICMP_NE ? ICmpInst::ICMP_EQ :
ICmpInst::ICMP_NE, LHSI,
Context->getNullValue(RHS->getType()));
@@ -7116,7 +7130,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
Constant *Zero = Context->getNullValue(X->getType());
ICmpInst::Predicate pred = isICMP_NE ?
ICmpInst::ICMP_SLT : ICmpInst::ICMP_SGE;
- return new ICmpInst(pred, X, Zero);
+ return new ICmpInst(*Context, pred, X, Zero);
}
// ((X & ~7) == 0) --> X < 8
@@ -7125,7 +7139,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
Constant *NegX = Context->getConstantExprNeg(BOC);
ICmpInst::Predicate pred = isICMP_NE ?
ICmpInst::ICMP_UGE : ICmpInst::ICMP_ULT;
- return new ICmpInst(pred, X, NegX);
+ return new ICmpInst(*Context, pred, X, NegX);
}
}
default: break;
@@ -7169,7 +7183,7 @@ Instruction *InstCombiner::visitICmpInstWithCastAndCast(ICmpInst &ICI) {
}
if (RHSOp)
- return new ICmpInst(ICI.getPredicate(), LHSCIOp, RHSOp);
+ return new ICmpInst(*Context, ICI.getPredicate(), LHSCIOp, RHSOp);
}
// The code below only handles extension cast instructions, so far.
@@ -7194,15 +7208,15 @@ Instruction *InstCombiner::visitICmpInstWithCastAndCast(ICmpInst &ICI) {
// Deal with equality cases early.
if (ICI.isEquality())
- return new ICmpInst(ICI.getPredicate(), LHSCIOp, RHSCIOp);
+ return new ICmpInst(*Context, ICI.getPredicate(), LHSCIOp, RHSCIOp);
// A signed comparison of sign extended values simplifies into a
// signed comparison.
if (isSignedCmp && isSignedExt)
- return new ICmpInst(ICI.getPredicate(), LHSCIOp, RHSCIOp);
+ return new ICmpInst(*Context, ICI.getPredicate(), LHSCIOp, RHSCIOp);
// The other three cases all fold into an unsigned comparison.
- return new ICmpInst(ICI.getUnsignedPredicate(), LHSCIOp, RHSCIOp);
+ return new ICmpInst(*Context, ICI.getUnsignedPredicate(), LHSCIOp, RHSCIOp);
}
// If we aren't dealing with a constant on the RHS, exit early
@@ -7229,7 +7243,7 @@ Instruction *InstCombiner::visitICmpInstWithCastAndCast(ICmpInst &ICI) {
// However, we allow this when the compare is EQ/NE, because they are
// signless.
if (isSignedExt == isSignedCmp || ICI.isEquality())
- return new ICmpInst(ICI.getPredicate(), LHSCIOp, Res1);
+ return new ICmpInst(*Context, ICI.getPredicate(), LHSCIOp, Res1);
return 0;
}
@@ -7258,8 +7272,8 @@ Instruction *InstCombiner::visitICmpInstWithCastAndCast(ICmpInst &ICI) {
// We're performing an unsigned comp with a sign extended value.
// This is true if the input is >= 0. [aka >s -1]
Constant *NegOne = Context->getConstantIntAllOnesValue(SrcTy);
- Result = InsertNewInstBefore(new ICmpInst(ICmpInst::ICMP_SGT, LHSCIOp,
- NegOne, ICI.getName()), ICI);
+ Result = InsertNewInstBefore(new ICmpInst(*Context, ICmpInst::ICMP_SGT,
+ LHSCIOp, NegOne, ICI.getName()), ICI);
} else {
// Unsigned extend & unsigned compare -> always true.
Result = Context->getConstantIntTrue();
@@ -8455,7 +8469,7 @@ Instruction *InstCombiner::visitTrunc(TruncInst &CI) {
Constant *One = Context->getConstantInt(Src->getType(), 1);
Src = InsertNewInstBefore(BinaryOperator::CreateAnd(Src, One, "tmp"), CI);
Value *Zero = Context->getNullValue(Src->getType());
- return new ICmpInst(ICmpInst::ICMP_NE, Src, Zero);
+ return new ICmpInst(*Context, ICmpInst::ICMP_NE, Src, Zero);
}
// Optimize trunc(lshr(), c) to pull the shift through the truncate.
@@ -10591,8 +10605,8 @@ Instruction *InstCombiner::FoldPHIArgBinOpIntoPHI(PHINode &PN) {
if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(FirstInst))
return BinaryOperator::Create(BinOp->getOpcode(), LHSVal, RHSVal);
CmpInst *CIOp = cast<CmpInst>(FirstInst);
- return CmpInst::Create(CIOp->getOpcode(), CIOp->getPredicate(), LHSVal,
- RHSVal);
+ return CmpInst::Create(*Context, CIOp->getOpcode(), CIOp->getPredicate(),
+ LHSVal, RHSVal);
}
Instruction *InstCombiner::FoldPHIArgGEPIntoPHI(PHINode &PN) {
@@ -10838,7 +10852,7 @@ Instruction *InstCombiner::FoldPHIArgOpIntoPHI(PHINode &PN) {
if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(FirstInst))
return BinaryOperator::Create(BinOp->getOpcode(), PhiVal, ConstantOp);
if (CmpInst *CIOp = dyn_cast<CmpInst>(FirstInst))
- return CmpInst::Create(CIOp->getOpcode(), CIOp->getPredicate(),
+ return CmpInst::Create(*Context, CIOp->getOpcode(), CIOp->getPredicate(),
PhiVal, ConstantOp);
assert(isa<LoadInst>(FirstInst) && "Unknown operation");
@@ -12104,7 +12118,7 @@ Instruction *InstCombiner::visitBranchInst(BranchInst &BI) {
FPred == FCmpInst::FCMP_OGE) && BI.getCondition()->hasOneUse()) {
FCmpInst *I = cast<FCmpInst>(BI.getCondition());
FCmpInst::Predicate NewPred = FCmpInst::getInversePredicate(FPred);
- Instruction *NewSCC = new FCmpInst(NewPred, X, Y, "", I);
+ Instruction *NewSCC = new FCmpInst(I, NewPred, X, Y, "");
NewSCC->takeName(I);
// Swap Destinations and condition...
BI.setCondition(NewSCC);
@@ -12125,7 +12139,7 @@ Instruction *InstCombiner::visitBranchInst(BranchInst &BI) {
IPred == ICmpInst::ICMP_SGE) && BI.getCondition()->hasOneUse()) {
ICmpInst *I = cast<ICmpInst>(BI.getCondition());
ICmpInst::Predicate NewPred = ICmpInst::getInversePredicate(IPred);
- Instruction *NewSCC = new ICmpInst(NewPred, X, Y, "", I);
+ Instruction *NewSCC = new ICmpInst(I, NewPred, X, Y, "");
NewSCC->takeName(I);
// Swap Destinations and condition...
BI.setCondition(NewSCC);
diff --git a/lib/Transforms/Scalar/JumpThreading.cpp b/lib/Transforms/Scalar/JumpThreading.cpp
index 7b9615b..f3536c1 100644
--- a/lib/Transforms/Scalar/JumpThreading.cpp
+++ b/lib/Transforms/Scalar/JumpThreading.cpp
@@ -931,7 +931,7 @@ bool JumpThreading::ThreadEdge(BasicBlock *BB, BasicBlock *PredBB,
// Clone the non-phi instructions of BB into NewBB, keeping track of the
// mapping and using it to remap operands in the cloned instructions.
for (; !isa<TerminatorInst>(BI); ++BI) {
- Instruction *New = BI->clone();
+ Instruction *New = BI->clone(*Context);
New->setName(BI->getNameStart());
NewBB->getInstList().push_back(New);
ValueMapping[BI] = New;
diff --git a/lib/Transforms/Scalar/LICM.cpp b/lib/Transforms/Scalar/LICM.cpp
index 2e5864b..52dd06a 100644
--- a/lib/Transforms/Scalar/LICM.cpp
+++ b/lib/Transforms/Scalar/LICM.cpp
@@ -570,7 +570,7 @@ void LICM::sink(Instruction &I) {
ExitBlock->getInstList().insert(InsertPt, &I);
New = &I;
} else {
- New = I.clone();
+ New = I.clone(*Context);
CurAST->copyValue(&I, New);
if (!I.getName().empty())
New->setName(I.getName()+".le");
diff --git a/lib/Transforms/Scalar/LoopIndexSplit.cpp b/lib/Transforms/Scalar/LoopIndexSplit.cpp
index e58eeee..4c6689d 100644
--- a/lib/Transforms/Scalar/LoopIndexSplit.cpp
+++ b/lib/Transforms/Scalar/LoopIndexSplit.cpp
@@ -309,16 +309,18 @@ static Value *getMinusOne(Value *V, bool Sign, Instruction *InsertPt,
// Return min(V1, V1)
static Value *getMin(Value *V1, Value *V2, bool Sign, Instruction *InsertPt) {
- Value *C = new ICmpInst(Sign ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
- V1, V2, "lsp", InsertPt);
+ Value *C = new ICmpInst(InsertPt,
+ Sign ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
+ V1, V2, "lsp");
return SelectInst::Create(C, V1, V2, "lsp", InsertPt);
}
// Return max(V1, V2)
static Value *getMax(Value *V1, Value *V2, bool Sign, Instruction *InsertPt) {
- Value *C = new ICmpInst(Sign ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
- V1, V2, "lsp", InsertPt);
+ Value *C = new ICmpInst(InsertPt,
+ Sign ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
+ V1, V2, "lsp");
return SelectInst::Create(C, V2, V1, "lsp", InsertPt);
}
@@ -427,15 +429,15 @@ bool LoopIndexSplit::processOneIterationLoop() {
// c1 = icmp uge i32 SplitValue, StartValue
// c2 = icmp ult i32 SplitValue, ExitValue
// and i32 c1, c2
- Instruction *C1 = new ICmpInst(ExitCondition->isSignedPredicate() ?
+ Instruction *C1 = new ICmpInst(BR, ExitCondition->isSignedPredicate() ?
ICmpInst::ICMP_SGE : ICmpInst::ICMP_UGE,
- SplitValue, StartValue, "lisplit", BR);
+ SplitValue, StartValue, "lisplit");
CmpInst::Predicate C2P = ExitCondition->getPredicate();
BranchInst *LatchBR = cast<BranchInst>(Latch->getTerminator());
if (LatchBR->getOperand(0) != Header)
C2P = CmpInst::getInversePredicate(C2P);
- Instruction *C2 = new ICmpInst(C2P, SplitValue, ExitValue, "lisplit", BR);
+ Instruction *C2 = new ICmpInst(BR, C2P, SplitValue, ExitValue, "lisplit");
Instruction *NSplitCond = BinaryOperator::CreateAnd(C1, C2, "lisplit", BR);
SplitCondition->replaceAllUsesWith(NSplitCond);
diff --git a/lib/Transforms/Scalar/LoopRotation.cpp b/lib/Transforms/Scalar/LoopRotation.cpp
index 1f7892a..6d80365 100644
--- a/lib/Transforms/Scalar/LoopRotation.cpp
+++ b/lib/Transforms/Scalar/LoopRotation.cpp
@@ -238,7 +238,7 @@ bool LoopRotate::rotateLoop(Loop *Lp, LPPassManager &LPM) {
// This is not a PHI instruction. Insert its clone into original pre-header.
// If this instruction is using a value from same basic block then
// update it to use value from cloned instruction.
- Instruction *C = In->clone();
+ Instruction *C = In->clone(*Context);
C->setName(In->getName());
OrigPreHeader->getInstList().push_back(C);
diff --git a/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/lib/Transforms/Scalar/LoopStrengthReduce.cpp
index 76985da..454cc93 100644
--- a/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ b/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -2019,9 +2019,8 @@ ICmpInst *LoopStrengthReduce::ChangeCompareStride(Loop *L, ICmpInst *Cond,
// Create a new compare instruction using new stride / iv.
ICmpInst *OldCond = Cond;
// Insert new compare instruction.
- Cond = new ICmpInst(Predicate, NewCmpLHS, NewCmpRHS,
- L->getHeader()->getName() + ".termcond",
- OldCond);
+ Cond = new ICmpInst(OldCond, Predicate, NewCmpLHS, NewCmpRHS,
+ L->getHeader()->getName() + ".termcond");
// Remove the old compare instruction. The old indvar is probably dead too.
DeadInsts.push_back(CondUse->getOperandValToReplace());
@@ -2152,7 +2151,7 @@ ICmpInst *LoopStrengthReduce::OptimizeMax(Loop *L, ICmpInst *Cond,
// Ok, everything looks ok to change the condition into an SLT or SGE and
// delete the max calculation.
ICmpInst *NewCond =
- new ICmpInst(Pred, Cond->getOperand(0), NewRHS, "scmp", Cond);
+ new ICmpInst(Cond, Pred, Cond->getOperand(0), NewRHS, "scmp");
// Delete the max calculation instructions.
Cond->replaceAllUsesWith(NewCond);
@@ -2383,7 +2382,7 @@ void LoopStrengthReduce::OptimizeLoopTermCond(Loop *L) {
Cond->moveBefore(TermBr);
} else {
// Otherwise, clone the terminating condition and insert into the loopend.
- Cond = cast<ICmpInst>(Cond->clone());
+ Cond = cast<ICmpInst>(Cond->clone(*Context));
Cond->setName(L->getHeader()->getName() + ".termcond");
LatchBlock->getInstList().insert(TermBr, Cond);
diff --git a/lib/Transforms/Scalar/LoopUnswitch.cpp b/lib/Transforms/Scalar/LoopUnswitch.cpp
index b8e4479..0a3659c 100644
--- a/lib/Transforms/Scalar/LoopUnswitch.cpp
+++ b/lib/Transforms/Scalar/LoopUnswitch.cpp
@@ -507,7 +507,7 @@ void LoopUnswitch::EmitPreheaderBranchOnCondition(Value *LIC, Constant *Val,
// code is the true version and the new code is the false version.
Value *BranchVal = LIC;
if (!isa<ConstantInt>(Val) || Val->getType() != Type::Int1Ty)
- BranchVal = new ICmpInst(ICmpInst::ICMP_EQ, LIC, Val, "tmp", InsertPt);
+ BranchVal = new ICmpInst(InsertPt, ICmpInst::ICMP_EQ, LIC, Val, "tmp");
else if (Val != Context->getConstantIntTrue())
// We want to enter the new loop when the condition is true.
std::swap(TrueDest, FalseDest);
diff --git a/lib/Transforms/Scalar/PredicateSimplifier.cpp b/lib/Transforms/Scalar/PredicateSimplifier.cpp
index a3cb751..24707bd 100644
--- a/lib/Transforms/Scalar/PredicateSimplifier.cpp
+++ b/lib/Transforms/Scalar/PredicateSimplifier.cpp
@@ -2693,8 +2693,8 @@ namespace {
VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, &IC);
if (VRP.isRelatedBy(IC.getOperand(0), NextVal,
ICmpInst::getInversePredicate(Pred))) {
- ICmpInst *NewIC = new ICmpInst(ICmpInst::ICMP_EQ, IC.getOperand(0),
- NextVal, "", &IC);
+ ICmpInst *NewIC = new ICmpInst(&IC, ICmpInst::ICMP_EQ,
+ IC.getOperand(0), NextVal, "");
NewIC->takeName(&IC);
IC.replaceAllUsesWith(NewIC);
diff --git a/lib/Transforms/Scalar/ScalarReplAggregates.cpp b/lib/Transforms/Scalar/ScalarReplAggregates.cpp
index cdb0628..61fc9ee 100644
--- a/lib/Transforms/Scalar/ScalarReplAggregates.cpp
+++ b/lib/Transforms/Scalar/ScalarReplAggregates.cpp
@@ -1193,9 +1193,9 @@ void SROA::CleanupGEP(GetElementPtrInst *GEPI) {
assert(NumElements == 2 && "Unhandled case!");
// All users of the GEP must be loads. At each use of the GEP, insert
// two loads of the appropriate indexed GEP and select between them.
- Value *IsOne = new ICmpInst(ICmpInst::ICMP_NE, I.getOperand(),
+ Value *IsOne = new ICmpInst(GEPI, ICmpInst::ICMP_NE, I.getOperand(),
Context->getNullValue(I.getOperand()->getType()),
- "isone", GEPI);
+ "isone");
// Insert the new GEP instructions, which are properly indexed.
SmallVector<Value*, 8> Indices(GEPI->op_begin()+1, GEPI->op_end());
Indices[1] = Context->getNullValue(Type::Int32Ty);
diff --git a/lib/Transforms/Scalar/TailDuplication.cpp b/lib/Transforms/Scalar/TailDuplication.cpp
index 06815d2..684b0963 100644
--- a/lib/Transforms/Scalar/TailDuplication.cpp
+++ b/lib/Transforms/Scalar/TailDuplication.cpp
@@ -304,7 +304,7 @@ void TailDup::eliminateUnconditionalBranch(BranchInst *Branch) {
// keeping track of the mapping...
//
for (; BI != DestBlock->end(); ++BI) {
- Instruction *New = BI->clone();
+ Instruction *New = BI->clone(*Context);
New->setName(BI->getName());
SourceBlock->getInstList().push_back(New);
ValueMapping[BI] = New;