summaryrefslogtreecommitdiff
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
parent53674361efd42f9dd7c4d293132106839ab3b893 (diff)
downloadllvm-333c40096561218bc3597cf153c0a3895274414c.tar.gz
llvm-333c40096561218bc3597cf153c0a3895274414c.tar.bz2
llvm-333c40096561218bc3597cf153c0a3895274414c.tar.xz
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
-rw-r--r--examples/BrainF/BrainF.cpp5
-rw-r--r--examples/Fibonacci/fibonacci.cpp2
-rw-r--r--examples/ParallelJIT/ParallelJIT.cpp2
-rw-r--r--include/llvm/InstrTypes.h16
-rw-r--r--include/llvm/Instruction.h4
-rw-r--r--include/llvm/Instructions.h149
-rw-r--r--include/llvm/LLVMContext.h4
-rw-r--r--include/llvm/Support/IRBuilder.h4
-rw-r--r--lib/AsmParser/LLParser.cpp4
-rw-r--r--lib/Bitcode/Reader/BitcodeReader.cpp4
-rw-r--r--lib/CodeGen/StackProtector.cpp2
-rw-r--r--lib/Transforms/IPO/GlobalOpt.cpp14
-rw-r--r--lib/Transforms/Instrumentation/RSProfiling.cpp14
-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
-rw-r--r--lib/Transforms/Utils/BasicBlockUtils.cpp2
-rw-r--r--lib/Transforms/Utils/CloneFunction.cpp6
-rw-r--r--lib/Transforms/Utils/InlineFunction.cpp2
-rw-r--r--lib/Transforms/Utils/Local.cpp4
-rw-r--r--lib/Transforms/Utils/LowerInvoke.cpp9
-rw-r--r--lib/Transforms/Utils/LowerSwitch.cpp19
-rw-r--r--lib/Transforms/Utils/SimplifyCFG.cpp8
-rw-r--r--lib/VMCore/Instructions.cpp175
-rw-r--r--lib/VMCore/LLVMContext.cpp7
-rw-r--r--tools/bugpoint/Miscompilation.cpp4
37 files changed, 481 insertions, 332 deletions
diff --git a/examples/BrainF/BrainF.cpp b/examples/BrainF/BrainF.cpp
index 058ef8c72d..cd9e850728 100644
--- a/examples/BrainF/BrainF.cpp
+++ b/examples/BrainF/BrainF.cpp
@@ -427,9 +427,8 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb) {
LoadInst *tape_0 = new LoadInst(head_0, tapereg, testbb);
//%test.%d = icmp eq i8 %tape.%d, 0
- ICmpInst *test_0 = new ICmpInst(ICmpInst::ICMP_EQ, tape_0,
- ConstantInt::get(APInt(8, 0)), testreg,
- testbb);
+ ICmpInst *test_0 = new ICmpInst(*testbb, ICmpInst::ICMP_EQ, tape_0,
+ ConstantInt::get(APInt(8, 0)), testreg);
//br i1 %test.%d, label %main.%d, label %main.%d
BasicBlock *bb_0 = BasicBlock::Create(label, brainf_func);
diff --git a/examples/Fibonacci/fibonacci.cpp b/examples/Fibonacci/fibonacci.cpp
index c3431fc352..89f3ef2d75 100644
--- a/examples/Fibonacci/fibonacci.cpp
+++ b/examples/Fibonacci/fibonacci.cpp
@@ -60,7 +60,7 @@ static Function *CreateFibFunction(Module *M) {
BasicBlock* RecurseBB = BasicBlock::Create("recurse", FibF);
// Create the "if (arg <= 2) goto exitbb"
- Value *CondInst = new ICmpInst(ICmpInst::ICMP_SLE, ArgX, Two, "cond", BB);
+ Value *CondInst = new ICmpInst(*BB, ICmpInst::ICMP_SLE, ArgX, Two, "cond");
BranchInst::Create(RetBB, RecurseBB, CondInst, BB);
// Create: ret int 1
diff --git a/examples/ParallelJIT/ParallelJIT.cpp b/examples/ParallelJIT/ParallelJIT.cpp
index eadd0f58e5..e80dc4986a 100644
--- a/examples/ParallelJIT/ParallelJIT.cpp
+++ b/examples/ParallelJIT/ParallelJIT.cpp
@@ -85,7 +85,7 @@ static Function *CreateFibFunction(Module *M) {
BasicBlock* RecurseBB = BasicBlock::Create("recurse", FibF);
// Create the "if (arg < 2) goto exitbb"
- Value *CondInst = new ICmpInst(ICmpInst::ICMP_SLE, ArgX, Two, "cond", BB);
+ Value *CondInst = new ICmpInst(*BB, ICmpInst::ICMP_SLE, ArgX, Two, "cond");
BranchInst::Create(RetBB, RecurseBB, CondInst, BB);
// Create: ret int 1
diff --git a/include/llvm/InstrTypes.h b/include/llvm/InstrTypes.h
index 0a018de5e9..76827191f1 100644
--- a/include/llvm/InstrTypes.h
+++ b/include/llvm/InstrTypes.h
@@ -22,6 +22,8 @@
namespace llvm {
+class LLVMContext;
+
//===----------------------------------------------------------------------===//
// TerminatorInst Class
//===----------------------------------------------------------------------===//
@@ -50,7 +52,7 @@ protected:
virtual void setSuccessorV(unsigned idx, BasicBlock *B) = 0;
public:
- virtual Instruction *clone() const = 0;
+ virtual Instruction *clone(LLVMContext &Context) const = 0;
/// getNumSuccessors - Return the number of successors that this terminator
/// has.
@@ -235,7 +237,7 @@ public:
return static_cast<BinaryOps>(Instruction::getOpcode());
}
- virtual BinaryOperator *clone() const;
+ virtual BinaryOperator *clone(LLVMContext &Context) const;
/// swapOperands - Exchange the two operands to this instruction.
/// This instruction is safe to use on any binary instruction and
@@ -569,7 +571,8 @@ public:
/// instruction into a BasicBlock right before the specified instruction.
/// The specified Instruction is allowed to be a dereferenced end iterator.
/// @brief Create a CmpInst
- static CmpInst *Create(OtherOps Op, unsigned short predicate, Value *S1,
+ static CmpInst *Create(LLVMContext &Context, OtherOps Op,
+ unsigned short predicate, Value *S1,
Value *S2, const std::string &Name = "",
Instruction *InsertBefore = 0);
@@ -660,13 +663,6 @@ public:
static inline bool classof(const Value *V) {
return isa<Instruction>(V) && classof(cast<Instruction>(V));
}
- /// @brief Create a result type for fcmp/icmp
- static const Type* makeCmpResultType(const Type* opnd_type) {
- if (const VectorType* vt = dyn_cast<const VectorType>(opnd_type)) {
- return VectorType::get(Type::Int1Ty, vt->getNumElements());
- }
- return Type::Int1Ty;
- }
};
diff --git a/include/llvm/Instruction.h b/include/llvm/Instruction.h
index 7d946e85a6..e06ae2d711 100644
--- a/include/llvm/Instruction.h
+++ b/include/llvm/Instruction.h
@@ -20,6 +20,8 @@
namespace llvm {
+class LLVMContext;
+
template<typename ValueSubClass, typename ItemParentClass>
class SymbolTableListTraits;
@@ -45,7 +47,7 @@ public:
/// * The instruction has no parent
/// * The instruction has no name
///
- virtual Instruction *clone() const = 0;
+ virtual Instruction *clone(LLVMContext &Context) const = 0;
/// isIdenticalTo - Return true if the specified instruction is exactly
/// identical to the current one. This means that all operands match and any
diff --git a/include/llvm/Instructions.h b/include/llvm/Instructions.h
index aef77f0a93..5bd3066ef9 100644
--- a/include/llvm/Instructions.h
+++ b/include/llvm/Instructions.h
@@ -20,6 +20,7 @@
#include "llvm/DerivedTypes.h"
#include "llvm/Attributes.h"
#include "llvm/BasicBlock.h"
+#include "llvm/LLVMContext.h"
#include "llvm/ADT/SmallVector.h"
#include <iterator>
@@ -74,7 +75,7 @@ public:
unsigned getAlignment() const { return (1u << SubclassData) >> 1; }
void setAlignment(unsigned Align);
- virtual Instruction *clone() const = 0;
+ virtual Instruction *clone(LLVMContext &Context) const = 0;
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const AllocationInst *) { return true; }
@@ -120,7 +121,7 @@ public:
Instruction *InsertBefore = 0)
: AllocationInst(Ty, ArraySize, Malloc, Align, NameStr, InsertBefore) {}
- virtual MallocInst *clone() const;
+ virtual MallocInst *clone(LLVMContext &Context) const;
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const MallocInst *) { return true; }
@@ -164,7 +165,7 @@ public:
const std::string &NameStr, BasicBlock *InsertAtEnd)
: AllocationInst(Ty, ArraySize, Alloca, Align, NameStr, InsertAtEnd) {}
- virtual AllocaInst *clone() const;
+ virtual AllocaInst *clone(LLVMContext &Context) const;
/// isStaticAlloca - Return true if this alloca is in the entry block of the
/// function and is a constant size. If so, the code generator will fold it
@@ -194,7 +195,7 @@ public:
explicit FreeInst(Value *Ptr, Instruction *InsertBefore = 0);
FreeInst(Value *Ptr, BasicBlock *InsertAfter);
- virtual FreeInst *clone() const;
+ virtual FreeInst *clone(LLVMContext &Context) const;
// Accessor methods for consistency with other memory operations
Value *getPointerOperand() { return getOperand(0); }
@@ -260,7 +261,7 @@ public:
SubclassData = (SubclassData & ~1) | (V ? 1 : 0);
}
- virtual LoadInst *clone() const;
+ virtual LoadInst *clone(LLVMContext &Context) const;
/// getAlignment - Return the alignment of the access that is being performed
///
@@ -344,7 +345,7 @@ public:
void setAlignment(unsigned Align);
- virtual StoreInst *clone() const;
+ virtual StoreInst *clone(LLVMContext &Context) const;
Value *getPointerOperand() { return getOperand(1); }
const Value *getPointerOperand() const { return getOperand(1); }
@@ -485,7 +486,7 @@ public:
return new(2) GetElementPtrInst(Ptr, Idx, NameStr, InsertAtEnd);
}
- virtual GetElementPtrInst *clone() const;
+ virtual GetElementPtrInst *clone(LLVMContext &Context) const;
/// Transparently provide more efficient getOperand methods.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
@@ -626,12 +627,13 @@ class ICmpInst: public CmpInst {
public:
/// @brief Constructor with insert-before-instruction semantics.
ICmpInst(
+ Instruction *InsertBefore, ///< Where to insert
Predicate pred, ///< The predicate to use for the comparison
Value *LHS, ///< The left-hand-side of the expression
Value *RHS, ///< The right-hand-side of the expression
- const std::string &NameStr = "", ///< Name of the instruction
- Instruction *InsertBefore = 0 ///< Where to insert
- ) : CmpInst(makeCmpResultType(LHS->getType()),
+ const std::string &NameStr = "" ///< Name of the instruction
+ ) : CmpInst(InsertBefore->getParent()->getContext()->
+ makeCmpResultType(LHS->getType()),
Instruction::ICmp, pred, LHS, RHS, NameStr,
InsertBefore) {
assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
@@ -645,16 +647,36 @@ public:
"Invalid operand types for ICmp instruction");
}
- /// @brief Constructor with insert-at-block-end semantics.
+ /// @brief Constructor with insert-at-end semantics.
+ ICmpInst(
+ BasicBlock &InsertAtEnd, ///< Block to insert into.
+ Predicate pred, ///< The predicate to use for the comparison
+ Value *LHS, ///< The left-hand-side of the expression
+ Value *RHS, ///< The right-hand-side of the expression
+ const std::string &NameStr = "" ///< Name of the instruction
+ ) : CmpInst(InsertAtEnd.getContext()->makeCmpResultType(LHS->getType()),
+ Instruction::ICmp, pred, LHS, RHS, NameStr,
+ &InsertAtEnd) {
+ assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
+ pred <= CmpInst::LAST_ICMP_PREDICATE &&
+ "Invalid ICmp predicate value");
+ assert(getOperand(0)->getType() == getOperand(1)->getType() &&
+ "Both operands to ICmp instruction are not of the same type!");
+ // Check that the operands are the right type
+ assert((getOperand(0)->getType()->isIntOrIntVector() ||
+ isa<PointerType>(getOperand(0)->getType())) &&
+ "Invalid operand types for ICmp instruction");
+ }
+
+ /// @brief Constructor with no-insertion semantics
ICmpInst(
+ LLVMContext &Context, ///< Context to construct within
Predicate pred, ///< The predicate to use for the comparison
Value *LHS, ///< The left-hand-side of the expression
Value *RHS, ///< The right-hand-side of the expression
- const std::string &NameStr, ///< Name of the instruction
- BasicBlock *InsertAtEnd ///< Block to insert into.
- ) : CmpInst(makeCmpResultType(LHS->getType()),
- Instruction::ICmp, pred, LHS, RHS, NameStr,
- InsertAtEnd) {
+ const std::string &NameStr = "" ///< Name of the instruction
+ ) : CmpInst(Context.makeCmpResultType(LHS->getType()),
+ Instruction::ICmp, pred, LHS, RHS, NameStr) {
assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
pred <= CmpInst::LAST_ICMP_PREDICATE &&
"Invalid ICmp predicate value");
@@ -756,7 +778,7 @@ public:
Op<0>().swap(Op<1>());
}
- virtual ICmpInst *clone() const;
+ virtual ICmpInst *clone(LLVMContext &Context) const;
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const ICmpInst *) { return true; }
@@ -781,12 +803,13 @@ class FCmpInst: public CmpInst {
public:
/// @brief Constructor with insert-before-instruction semantics.
FCmpInst(
+ Instruction *InsertBefore, ///< Where to insert
Predicate pred, ///< The predicate to use for the comparison
Value *LHS, ///< The left-hand-side of the expression
Value *RHS, ///< The right-hand-side of the expression
- const std::string &NameStr = "", ///< Name of the instruction
- Instruction *InsertBefore = 0 ///< Where to insert
- ) : CmpInst(makeCmpResultType(LHS->getType()),
+ const std::string &NameStr = "" ///< Name of the instruction
+ ) : CmpInst(InsertBefore->getParent()->getContext()->
+ makeCmpResultType(LHS->getType()),
Instruction::FCmp, pred, LHS, RHS, NameStr,
InsertBefore) {
assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
@@ -797,17 +820,35 @@ public:
assert(getOperand(0)->getType()->isFPOrFPVector() &&
"Invalid operand types for FCmp instruction");
}
+
+ /// @brief Constructor with insert-at-end semantics.
+ FCmpInst(
+ BasicBlock &InsertAtEnd, ///< Block to insert into.
+ Predicate pred, ///< The predicate to use for the comparison
+ Value *LHS, ///< The left-hand-side of the expression
+ Value *RHS, ///< The right-hand-side of the expression
+ const std::string &NameStr = "" ///< Name of the instruction
+ ) : CmpInst(InsertAtEnd.getContext()->makeCmpResultType(LHS->getType()),
+ Instruction::FCmp, pred, LHS, RHS, NameStr,
+ &InsertAtEnd) {
+ assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
+ "Invalid FCmp predicate value");
+ assert(getOperand(0)->getType() == getOperand(1)->getType() &&
+ "Both operands to FCmp instruction are not of the same type!");
+ // Check that the operands are the right type
+ assert(getOperand(0)->getType()->isFPOrFPVector() &&
+ "Invalid operand types for FCmp instruction");
+ }
- /// @brief Constructor with insert-at-block-end semantics.
+ /// @brief Constructor with no-insertion semantics
FCmpInst(
+ LLVMContext &Context, ///< Context to build in
Predicate pred, ///< The predicate to use for the comparison
Value *LHS, ///< The left-hand-side of the expression
Value *RHS, ///< The right-hand-side of the expression
- const std::string &NameStr, ///< Name of the instruction
- BasicBlock *InsertAtEnd ///< Block to insert into.
- ) : CmpInst(makeCmpResultType(LHS->getType()),
- Instruction::FCmp, pred, LHS, RHS, NameStr,
- InsertAtEnd) {
+ const std::string &NameStr = "" ///< Name of the instruction
+ ) : CmpInst(Context.makeCmpResultType(LHS->getType()),
+ Instruction::FCmp, pred, LHS, RHS, NameStr) {
assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
"Invalid FCmp predicate value");
assert(getOperand(0)->getType() == getOperand(1)->getType() &&
@@ -848,7 +889,7 @@ public:
Op<0>().swap(Op<1>());
}
- virtual FCmpInst *clone() const;
+ virtual FCmpInst *clone(LLVMContext &Context) const;
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const FCmpInst *) { return true; }
@@ -959,7 +1000,7 @@ public:
SubclassData = (SubclassData & ~1) | unsigned(isTC);
}
- virtual CallInst *clone() const;
+ virtual CallInst *clone(LLVMContext &Context) const;
/// Provide fast operand accessors
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
@@ -1152,7 +1193,7 @@ public:
return static_cast<OtherOps>(Instruction::getOpcode());
}
- virtual SelectInst *clone() const;
+ virtual SelectInst *clone(LLVMContext &Context) const;
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const SelectInst *) { return true; }
@@ -1192,7 +1233,7 @@ public:
setName(NameStr);
}
- virtual VAArgInst *clone() const;
+ virtual VAArgInst *clone(LLVMContext &Context) const;
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const VAArgInst *) { return true; }
@@ -1236,7 +1277,7 @@ public:
/// formed with the specified operands.
static bool isValidOperands(const Value *Vec, const Value *Idx);
- virtual ExtractElementInst *clone() const;
+ virtual ExtractElementInst *clone(LLVMContext &Context) const;
/// Transparently provide more efficient getOperand methods.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
@@ -1306,7 +1347,7 @@ public:
static bool isValidOperands(const Value *Vec, const Value *NewElt,
const Value *Idx);
- virtual InsertElementInst *clone() const;
+ virtual InsertElementInst *clone(LLVMContext &Context) const;
/// getType - Overload to return most specific vector type.
///
@@ -1358,7 +1399,7 @@ public:
static bool isValidOperands(const Value *V1, const Value *V2,
const Value *Mask);
- virtual ShuffleVectorInst *clone() const;
+ virtual ShuffleVectorInst *clone(LLVMContext &Context) const;
/// getType - Overload to return most specific vector type.
///
@@ -1502,7 +1543,7 @@ public:
return new ExtractValueInst(Agg, Idxs, Idxs + 1, NameStr, InsertAtEnd);
}
- virtual ExtractValueInst *clone() const;
+ virtual ExtractValueInst *clone(LLVMContext &Context) const;
/// getIndexedType - Returns the type of the element that would be extracted
/// with an extractvalue instruction with the specified parameters.
@@ -1672,7 +1713,7 @@ public:
return new InsertValueInst(Agg, Val, Idx, NameStr, InsertAtEnd);
}
- virtual InsertValueInst *clone() const;
+ virtual InsertValueInst *clone(LLVMContext &Context) const;
/// Transparently provide more efficient getOperand methods.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
@@ -1801,7 +1842,7 @@ public:
resizeOperands(NumValues*2);
}
- virtual PHINode *clone() const;
+ virtual PHINode *clone(LLVMContext &Context) const;
/// Provide fast operand accessors
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
@@ -1960,7 +2001,7 @@ public:
}
virtual ~ReturnInst();
- virtual ReturnInst *clone() const;
+ virtual ReturnInst *clone(LLVMContext &Context) const;
/// Provide fast operand accessors
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
@@ -2042,7 +2083,7 @@ public:
/// Transparently provide more efficient getOperand methods.
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
- virtual BranchInst *clone() const;
+ virtual BranchInst *clone(LLVMContext &Context) const;
bool isUnconditional() const { return getNumOperands() == 1; }
bool isConditional() const { return getNumOperands() == 3; }
@@ -2212,7 +2253,7 @@ public:
///
void removeCase(unsigned idx);
- virtual SwitchInst *clone() const;
+ virtual SwitchInst *clone(LLVMContext &Context) const;
unsigned getNumSuccessors() const { return getNumOperands()/2; }
BasicBlock *getSuccessor(unsigned idx) const {
@@ -2326,7 +2367,7 @@ public:
Values, NameStr, InsertAtEnd);
}
- virtual InvokeInst *clone() const;
+ virtual InvokeInst *clone(LLVMContext &Context) const;
/// Provide fast operand accessors
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
@@ -2514,7 +2555,7 @@ public:
explicit UnwindInst(Instruction *InsertBefore = 0);
explicit UnwindInst(BasicBlock *InsertAtEnd);
- virtual UnwindInst *clone() const;
+ virtual UnwindInst *clone(LLVMContext &Context) const;
unsigned getNumSuccessors() const { return 0; }
@@ -2551,7 +2592,7 @@ public:
explicit UnreachableInst(Instruction *InsertBefore = 0);
explicit UnreachableInst(BasicBlock *InsertAtEnd);
- virtual UnreachableInst *clone() const;
+ virtual UnreachableInst *clone(LLVMContext &Context) const;
unsigned getNumSuccessors() const { return 0; }
@@ -2597,7 +2638,7 @@ public:
);
/// @brief Clone an identical TruncInst
- virtual CastInst *clone() const;
+ virtual CastInst *clone(LLVMContext &Context) const;
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const TruncInst *) { return true; }
@@ -2637,7 +2678,7 @@ public:
);
/// @brief Clone an identical ZExtInst
- virtual CastInst *clone() const;
+ virtual CastInst *clone(LLVMContext &Context) const;
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const ZExtInst *) { return true; }
@@ -2677,7 +2718,7 @@ public:
);
/// @brief Clone an identical SExtInst
- virtual CastInst *clone() const;
+ virtual CastInst *clone(LLVMContext &Context) const;
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const SExtInst *) { return true; }
@@ -2716,7 +2757,7 @@ public:
);
/// @brief Clone an identical FPTruncInst
- virtual CastInst *clone() const;
+ virtual CastInst *clone(LLVMContext &Context) const;
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const FPTruncInst *) { return true; }
@@ -2755,7 +2796,7 @@ public:
);
/// @brief Clone an identical FPExtInst
- virtual CastInst *clone() const;
+ virtual CastInst *clone(LLVMContext &Context) const;
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const FPExtInst *) { return true; }
@@ -2794,7 +2835,7 @@ public:
);
/// @brief Clone an identical UIToFPInst
- virtual CastInst *clone() const;
+ virtual CastInst *clone(LLVMContext &Context) const;
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const UIToFPInst *) { return true; }
@@ -2833,7 +2874,7 @@ public:
);
/// @brief Clone an identical SIToFPInst
- virtual CastInst *clone() const;
+ virtual CastInst *clone(LLVMContext &Context) const;
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const SIToFPInst *) { return true; }
@@ -2872,7 +2913,7 @@ public:
);
/// @brief Clone an identical FPToUIInst
- virtual CastInst *clone() const;
+ virtual CastInst *clone(LLVMContext &Context) const;
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const FPToUIInst *) { return true; }
@@ -2911,7 +2952,7 @@ public:
);
/// @brief Clone an identical FPToSIInst
- virtual CastInst *clone() const;
+ virtual CastInst *clone(LLVMContext &Context) const;
/// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const FPToSIInst *) { return true; }
@@ -2950,7 +2991,7 @@ public:
);
/// @brief Clone an identical IntToPtrInst
- virtual CastInst *clone() const;
+ virtual CastInst *clone(LLVMContext &Context) const;
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const IntToPtrInst *) { return true; }
@@ -2989,7 +3030,7 @@ public:
);
/// @brief Clone an identical PtrToIntInst
- virtual CastInst *clone() const;
+ virtual CastInst *clone(LLVMContext &Context) const;
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const PtrToIntInst *) { return true; }
@@ -3028,7 +3069,7 @@ public:
);
/// @brief Clone an identical BitCastInst
- virtual CastInst *clone() const;
+ virtual CastInst *clone(LLVMContext &Context) const;
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const BitCastInst *) { return true; }
diff --git a/include/llvm/LLVMContext.h b/include/llvm/LLVMContext.h
index 60da89eb4a..75b7e59ceb 100644
--- a/include/llvm/LLVMContext.h
+++ b/include/llvm/LLVMContext.h
@@ -213,6 +213,10 @@ public:
VectorType* getVectorTypeInteger(const VectorType* VTy);
VectorType* getVectorTypeExtendedElement(const VectorType* VTy);
VectorType* getVectorTypeTruncatedElement(const VectorType* VTy);
+
+ // Other helpers
+ /// @brief Create a result type for fcmp/icmp
+ const Type* makeCmpResultType(const Type* opnd_type);
};
/// FOR BACKWARDS COMPATIBILITY - Returns a global context.
diff --git a/include/llvm/Support/IRBuilder.h b/include/llvm/Support/IRBuilder.h
index 0fe0c3ce1f..fe794c65ef 100644
--- a/include/llvm/Support/IRBuilder.h
+++ b/include/llvm/Support/IRBuilder.h
@@ -565,14 +565,14 @@ public:
if (Constant *LC = dyn_cast<Constant>(LHS))
if (Constant *RC = dyn_cast<Constant>(RHS))
return Folder.CreateICmp(P, LC, RC);
- return Insert(new ICmpInst(P, LHS, RHS), Name);
+ return Insert(new ICmpInst(Context, P, LHS, RHS), Name);
}
Value *CreateFCmp(CmpInst::Predicate P, Value *LHS, Value *RHS,
const char *Name = "") {
if (Constant *LC = dyn_cast<Constant>(LHS))
if (Constant *RC = dyn_cast<Constant>(RHS))
return Folder.CreateFCmp(P, LC, RC);
- return Insert(new FCmpInst(P, LHS, RHS), Name);
+ return Insert(new FCmpInst(Context, P, LHS, RHS), Name);
}
//===--------------------------------------------------------------------===//
diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp
index 826c64fc89..64212f6193 100644
--- a/lib/AsmParser/LLParser.cpp
+++ b/lib/AsmParser/LLParser.cpp
@@ -2887,13 +2887,13 @@ bool LLParser::ParseCompare(Instruction *&Inst, PerFunctionState &PFS,
if (Opc == Instruction::FCmp) {
if (!LHS->getType()->isFPOrFPVector())
return Error(Loc, "fcmp requires floating point operands");
- Inst = new FCmpInst(CmpInst::Predicate(Pred), LHS, RHS);
+ Inst = new FCmpInst(Context, CmpInst::Predicate(Pred), LHS, RHS);
} else {
assert(Opc == Instruction::ICmp && "Unknown opcode for CmpInst!");
if (!LHS->getType()->isIntOrIntVector() &&
!isa<PointerType>(LHS->getType()))
return Error(Loc, "icmp requires integer operands");
- Inst = new ICmpInst(CmpInst::Predicate(Pred), LHS, RHS);
+ Inst = new ICmpInst(Context, CmpInst::Predicate(Pred), LHS, RHS);
}
return false;
}
diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp
index d69895e0cc..e4d3c5e1ad 100644
--- a/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -1643,9 +1643,9 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
return Error("Invalid CMP record");
if (LHS->getType()->isFPOrFPVector())
- I = new FCmpInst((FCmpInst::Predicate)Record[OpNum], LHS, RHS);
+ I = new FCmpInst(Context, (FCmpInst::Predicate)Record[OpNum], LHS, RHS);
else
- I = new ICmpInst((ICmpInst::Predicate)Record[OpNum], LHS, RHS);
+ I = new ICmpInst(Context, (ICmpInst::Predicate)Record[OpNum], LHS, RHS);
break;
}
diff --git a/lib/CodeGen/StackProtector.cpp b/lib/CodeGen/StackProtector.cpp
index c179f1e3df..9043b89e35 100644
--- a/lib/CodeGen/StackProtector.cpp
+++ b/lib/CodeGen/StackProtector.cpp
@@ -201,7 +201,7 @@ bool StackProtector::InsertStackProtectors() {
// Generate the stack protector instructions in the old basic block.
LoadInst *LI1 = new LoadInst(StackGuardVar, "", false, BB);
LoadInst *LI2 = new LoadInst(AI, "", true, BB);
- ICmpInst *Cmp = new ICmpInst(CmpInst::ICMP_EQ, LI1, LI2, "", BB);
+ ICmpInst *Cmp = new ICmpInst(*BB, CmpInst::ICMP_EQ, LI1, LI2, "");
BranchInst::Create(NewBB, FailBB, Cmp, BB);
}
diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp
index 2cd8b6b79a..366005bb13 100644
--- a/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/lib/Transforms/IPO/GlobalOpt.cpp
@@ -1185,9 +1185,9 @@ static void RewriteHeapSROALoadUser(Instruction *LoadUser,
InsertedScalarizedValues, PHIsToRewrite,
Context);
- Value *New = new ICmpInst(SCI->getPredicate(), NPtr,
- Context->getNullValue(NPtr->getType()),
- SCI->getName(), SCI);
+ Value *New = new ICmpInst(SCI, SCI->getPredicate(), NPtr,
+ Context->getNullValue(NPtr->getType()),
+ SCI->getName());
SCI->replaceAllUsesWith(New);
SCI->eraseFromParent();
return;
@@ -1310,9 +1310,9 @@ static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, MallocInst *MI,
// }
Value *RunningOr = 0;
for (unsigned i = 0, e = FieldMallocs.size(); i != e; ++i) {
- Value *Cond = new ICmpInst(ICmpInst::ICMP_EQ, FieldMallocs[i],
+ Value *Cond = new ICmpInst(MI, ICmpInst::ICMP_EQ, FieldMallocs[i],
Context->getNullValue(FieldMallocs[i]->getType()),
- "isnull", MI);
+ "isnull");
if (!RunningOr)
RunningOr = Cond; // First seteq
else
@@ -1337,9 +1337,9 @@ static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, MallocInst *MI,
// pointer, because some may be null while others are not.
for (unsigned i = 0, e = FieldGlobals.size(); i != e; ++i) {
Value *GVVal = new LoadInst(FieldGlobals[i], "tmp", NullPtrBlock);
- Value *Cmp = new ICmpInst(ICmpInst::ICMP_NE, GVVal,
+ Value *Cmp = new ICmpInst(*NullPtrBlock, ICmpInst::ICMP_NE, GVVal,
Context->getNullValue(GVVal->getType()),
- "tmp", NullPtrBlock);
+ "tmp");
BasicBlock *FreeBlock = BasicBlock::Create("free_it", OrigBB->getParent());
BasicBlock *NextBlock = BasicBlock::Create("next", OrigBB->getParent());
BranchInst::Create(FreeBlock, NextBlock, Cmp, NullPtrBlock);
diff --git a/lib/Transforms/Instrumentation/RSProfiling.cpp b/lib/Transforms/Instrumentation/RSProfiling.cpp
index 5101220953..c1f29fec55 100644
--- a/lib/Transforms/Instrumentation/RSProfiling.cpp
+++ b/lib/Transforms/Instrumentation/RSProfiling.cpp
@@ -213,9 +213,9 @@ void GlobalRandomCounter::ProcessChoicePoint(BasicBlock* bb) {
//decrement counter
LoadInst* l = new LoadInst(Counter, "counter", t);
- ICmpInst* s = new ICmpInst(ICmpInst::ICMP_EQ, l,
+ ICmpInst* s = new ICmpInst(t, ICmpInst::ICMP_EQ, l,
Context->getConstantInt(T, 0),
- "countercc", t);
+ "countercc");
Value* nv = BinaryOperator::CreateSub(l, Context->getConstantInt(T, 1),
"counternew", t);
@@ -287,9 +287,9 @@ void GlobalRandomCounterOpt::ProcessChoicePoint(BasicBlock* bb) {
//decrement counter
LoadInst* l = new LoadInst(AI, "counter", t);
- ICmpInst* s = new ICmpInst(ICmpInst::ICMP_EQ, l,
+ ICmpInst* s = new ICmpInst(t, ICmpInst::ICMP_EQ, l,
Context->getConstantInt(T, 0),
- "countercc", t);
+ "countercc");
Value* nv = BinaryOperator::CreateSub(l, Context->getConstantInt(T, 1),
"counternew", t);
@@ -324,9 +324,9 @@ void CycleCounter::ProcessChoicePoint(BasicBlock* bb) {
BinaryOperator::CreateAnd(c, Context->getConstantInt(Type::Int64Ty, rm),
"mrdcc", t);
- ICmpInst *s = new ICmpInst(ICmpInst::ICMP_EQ, b,
+ ICmpInst *s = new ICmpInst(t, ICmpInst::ICMP_EQ, b,
Context->getConstantInt(Type::Int64Ty, 0),
- "mrdccc", t);
+ "mrdccc");
t->setCondition(s);
}
@@ -394,7 +394,7 @@ Value* ProfilerRS::Translate(Value* v) {
return i;
} else {
//translate this
- Instruction* i2 = i->clone();
+ Instruction* i2 = i->clone(*Context);
if (i->hasName())
i2->setName("dup_" + i->getName());
TransCache[i] = i2;
diff --git a/lib/Transforms/Scalar/CodeGenPrepare.cpp b/lib/Transforms/Scalar/CodeGenPrepare.cpp
index 85e9243e3c..b3a26acc5e 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 962ba71dc7..b2fdd24c2c 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 0f3153f2a7..af7e039eb9 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 03a17d673d..365589dc0d 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 8d36f74372..89b4c6569b 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 7b9615b109..f3536c10c5 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 2e5864b3a1..52dd06affe 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 e58eeee1bd..4c6689d6b5 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 1f7892ad10..6d80365182 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 76985da067..454cc93d31 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 b8e44799ba..0a3659c71d 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 a3cb751921..24707bd4d8 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 cdb06285e0..61fc9eed01 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 06815d29b2..684b096345 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;
diff --git a/lib/Transforms/Utils/BasicBlockUtils.cpp b/lib/Transforms/Utils/BasicBlockUtils.cpp
index 32eecb37aa..f52546ccc4 100644
--- a/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -618,7 +618,7 @@ void llvm::CopyPrecedingStopPoint(Instruction *I,
if (I != I->getParent()->begin()) {
BasicBlock::iterator BBI = I; --BBI;
if (DbgStopPointInst *DSPI = dyn_cast<DbgStopPointInst>(BBI)) {
- CallInst *newDSPI = DSPI->clone();
+ CallInst *newDSPI = DSPI->clone(*I->getParent()->getContext());
newDSPI->insertBefore(InsertPos);
}
}
diff --git a/lib/Transforms/Utils/CloneFunction.cpp b/lib/Transforms/Utils/CloneFunction.cpp
index a820c9d3f5..f05c5dc8a7 100644
--- a/lib/Transforms/Utils/CloneFunction.cpp
+++ b/lib/Transforms/Utils/CloneFunction.cpp
@@ -43,7 +43,7 @@ BasicBlock *llvm::CloneBasicBlock(const BasicBlock *BB,
// Loop over all instructions, and copy them over.
for (BasicBlock::const_iterator II = BB->begin(), IE = BB->end();
II != IE; ++II) {
- Instruction *NewInst = II->clone();
+ Instruction *NewInst = II->clone(*BB->getContext());
if (II->hasName())
NewInst->setName(II->getName()+NameSuffix);
NewBB->getInstList().push_back(NewInst);
@@ -249,7 +249,7 @@ void PruningFunctionCloner::CloneBlock(const BasicBlock *BB,
continue;
}
- Instruction *NewInst = II->clone();
+ Instruction *NewInst = II->clone(*BB->getContext());
if (II->hasName())
NewInst->setName(II->getName()+NameSuffix);
NewBB->getInstList().push_back(NewInst);
@@ -297,7 +297,7 @@ void PruningFunctionCloner::CloneBlock(const BasicBlock *BB,
}
if (!TerminatorDone) {
- Instruction *NewInst = OldTI->clone();
+ Instruction *NewInst = OldTI->clone(*BB->getContext());
if (OldTI->hasName())
NewInst->setName(OldTI->getName()+NameSuffix);
NewBB->getInstList().push_back(NewInst);
diff --git a/lib/Transforms/Utils/InlineFunction.cpp b/lib/Transforms/Utils/InlineFunction.cpp
index 06008b6349..0e50cd11de 100644
--- a/lib/Transforms/Utils/InlineFunction.cpp
+++ b/lib/Transforms/Utils/InlineFunction.cpp
@@ -361,7 +361,7 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) {
BE = TheCall->getParent()->end(); BI != BE; ++BI) {
if (DbgStopPointInst *DSPI = dyn_cast<DbgStopPointInst>(BI)) {
if (DbgRegionEndInst *NewDREI =
- dyn_cast<DbgRegionEndInst>(DREI->clone()))
+ dyn_cast<DbgRegionEndInst>(DREI->clone(*Context)))
NewDREI->insertAfter(DSPI);
break;
}
diff --git a/lib/Transforms/Utils/Local.cpp b/lib/Transforms/Utils/Local.cpp
index 583b26ad87..0bb9614557 100644
--- a/lib/Transforms/Utils/Local.cpp
+++ b/lib/Transforms/Utils/Local.cpp
@@ -184,8 +184,8 @@ bool llvm::ConstantFoldTerminator(BasicBlock *BB) {
} else if (SI->getNumSuccessors() == 2) {
// Otherwise, we can fold this switch into a conditional branch
// instruction if it has only one non-default destination.
- Value *Cond = new ICmpInst(ICmpInst::ICMP_EQ, SI->getCondition(),
- SI->getSuccessorValue(1), "cond", SI);
+ Value *Cond = new ICmpInst(SI, ICmpInst::ICMP_EQ, SI->getCondition(),
+ SI->getSuccessorValue(1), "cond");
// Insert the new branch...
BranchInst::Create(SI->getSuccessor(1), SI->getSuccessor(0), Cond, SI);
diff --git a/lib/Transforms/Utils/LowerInvoke.cpp b/lib/Transforms/Utils/LowerInvoke.cpp
index 8ef060a1f4..b8e0fd88f0 100644
--- a/lib/Transforms/Utils/LowerInvoke.cpp
+++ b/lib/Transforms/Utils/LowerInvoke.cpp
@@ -523,9 +523,10 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
EntryBB->getTerminator());
// Compare the return value to zero.
- Value *IsNormal = new ICmpInst(ICmpInst::ICMP_EQ, SJRet,
+ Value *IsNormal = new ICmpInst(EntryBB->getTerminator(),
+ ICmpInst::ICMP_EQ, SJRet,
Constant::getNullValue(SJRet->getType()),
- "notunwind", EntryBB->getTerminator());
+ "notunwind");
// Nuke the uncond branch.
EntryBB->getTerminator()->eraseFromParent();
@@ -557,9 +558,9 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
}
// Load the JBList, if it's null, then there was no catch!
- Value *NotNull = new ICmpInst(ICmpInst::ICMP_NE, BufPtr,
+ Value *NotNull = new ICmpInst(*UnwindHandler, ICmpInst::ICMP_NE, BufPtr,
Constant::getNullValue(BufPtr->getType()),
- "notnull", UnwindHandler);
+ "notnull");
BranchInst::Create(UnwindBlock, TermBlock, NotNull, UnwindHandler);
// Create the block to do the longjmp.
diff --git a/lib/Transforms/Utils/LowerSwitch.cpp b/lib/Transforms/Utils/LowerSwitch.cpp
index ed6eca6c15..2a7124c9aa 100644
--- a/lib/Transforms/Utils/LowerSwitch.cpp
+++ b/lib/Transforms/Utils/LowerSwitch.cpp
@@ -162,7 +162,8 @@ BasicBlock* LowerSwitch::switchConvert(CaseItr Begin, CaseItr End,
Function::iterator FI = OrigBlock;
F->getBasicBlockList().insert(++FI, NewNode);
- ICmpInst* Comp = new ICmpInst(ICmpInst::ICMP_SLT, Val, Pivot.Low, "Pivot");
+ ICmpInst* Comp = new ICmpInst(*Default->getContext(), ICmpInst::ICMP_SLT,
+ Val, Pivot.Low, "Pivot");
NewNode->getInstList().push_back(Comp);
BranchInst::Create(LBranch, RBranch, Comp, NewNode);
return NewNode;
@@ -187,18 +188,18 @@ BasicBlock* LowerSwitch::newLeafBlock(CaseRange& Leaf, Value* Val,
ICmpInst* Comp = NULL;
if (Leaf.Low == Leaf.High) {
// Make the seteq instruction...
- Comp = new ICmpInst(ICmpInst::ICMP_EQ, Val, Leaf.Low,
- "SwitchLeaf", NewLeaf);
+ Comp = new ICmpInst(*NewLeaf, ICmpInst::ICMP_EQ, Val,
+ Leaf.Low, "SwitchLeaf");
} else {
// Make range comparison
if (cast<ConstantInt>(Leaf.Low)->isMinValue(true /*isSigned*/)) {
// Val >= Min && Val <= Hi --> Val <= Hi
- Comp = new ICmpInst(ICmpInst::ICMP_SLE, Val, Leaf.High,
- "SwitchLeaf", NewLeaf);
+ Comp = new ICmpInst(*NewLeaf, ICmpInst::ICMP_SLE, Val, Leaf.High,
+ "SwitchLeaf");
} else if (cast<ConstantInt>(Leaf.Low)->isZero()) {
// Val >= 0 && Val <= Hi --> Val <=u Hi
- Comp = new ICmpInst(ICmpInst::ICMP_ULE, Val, Leaf.High,
- "SwitchLeaf", NewLeaf);
+ Comp = new ICmpInst(*NewLeaf, ICmpInst::ICMP_ULE, Val, Leaf.High,
+ "SwitchLeaf");
} else {
// Emit V-Lo <=u Hi-Lo
Constant* NegLo = Context->getConstantExprNeg(Leaf.Low);
@@ -206,8 +207,8 @@ BasicBlock* LowerSwitch::newLeafBlock(CaseRange& Leaf, Value* Val,
Val->getName()+".off",
NewLeaf);
Constant *UpperBound = Context->getConstantExprAdd(NegLo, Leaf.High);
- Comp = new ICmpInst(ICmpInst::ICMP_ULE, Add, UpperBound,
- "SwitchLeaf", NewLeaf);
+ Comp = new ICmpInst(*NewLeaf, ICmpInst::ICMP_ULE, Add, UpperBound,
+ "SwitchLeaf");
}
}
diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp
index 9dccfe86f7..a898d2df2b 100644
--- a/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -938,7 +938,7 @@ HoistTerminator:
return true;
// Okay, it is safe to hoist the terminator.
- Instruction *NT = I1->clone();
+ Instruction *NT = I1->clone(*BB1->getContext());
BIParent->getInstList().insert(BI, NT);
if (NT->getType() != Type::VoidTy) {
I1->replaceAllUsesWith(NT);
@@ -1231,7 +1231,7 @@ static bool FoldCondBranchOnPHI(BranchInst *BI) {
TranslateMap[PN] = PN->getIncomingValueForBlock(PredBB);
} else {
// Clone the instruction.
- Instruction *N = BBI->clone();
+ Instruction *N = BBI->clone(*Context);
if (BBI->hasName()) N->setName(BBI->getName()+".c");
// Update operands due to translation.
@@ -1581,7 +1581,7 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI) {
// Clone Cond into the predecessor basic block, and or/and the
// two conditions together.
- Instruction *New = Cond->clone();
+ Instruction *New = Cond->clone(*BB->getContext());
PredBlock->getInstList().insert(PBI, New);
New->takeName(Cond);
Cond->setName(New->getName()+".old");
@@ -1841,7 +1841,7 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
<< "INTO UNCOND BRANCH PRED: " << *Pred;
Instruction *UncondBranch = Pred->getTerminator();
// Clone the return and add it to the end of the predecessor.
- Instruction *NewRet = RI->clone();
+ Instruction *NewRet = RI->clone(*BB->getContext());
Pred->getInstList().push_back(NewRet);
BasicBlock::iterator BBI = RI;
diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp
index bbb22c5a64..b56168a969 100644
--- a/lib/VMCore/Instructions.cpp
+++ b/lib/VMCore/Instructions.cpp
@@ -2576,25 +2576,35 @@ CmpInst::CmpInst(const Type *ty, OtherOps op, unsigned short predicate,
}
CmpInst *
-CmpInst::Create(OtherOps Op, unsigned short predicate, Value *S1, Value *S2,
+CmpInst::Create(LLVMContext &Context, OtherOps Op, unsigned short predicate,
+ Value *S1, Value *S2,
const std::string &Name, Instruction *InsertBefore) {
if (Op == Instruction::ICmp) {
- return new ICmpInst(CmpInst::Predicate(predicate), S1, S2, Name,
- InsertBefore);
+ if (InsertBefore)
+ return new ICmpInst(InsertBefore, CmpInst::Predicate(predicate),
+ S1, S2, Name);
+ else
+ return new ICmpInst(Context, CmpInst::Predicate(predicate),
+ S1, S2, Name);
}
- return new FCmpInst(CmpInst::Predicate(predicate), S1, S2, Name,
- InsertBefore);
+
+ if (InsertBefore)
+ return new FCmpInst(InsertBefore, CmpInst::Predicate(predicate),
+ S1, S2, Name);
+ else
+ return new FCmpInst(Context, CmpInst::Predicate(predicate),
+ S1, S2, Name);
}
CmpInst *
CmpInst::Create(OtherOps Op, unsigned short predicate, Value *S1, Value *S2,
const std::string &Name, BasicBlock *InsertAtEnd) {
if (Op == Instruction::ICmp) {
- return new ICmpInst(CmpInst::Predicate(predicate), S1, S2, Name,
- InsertAtEnd);
+ return new ICmpInst(*InsertAtEnd, CmpInst::Predicate(predicate),
+ S1, S2, Name);
}
- return new FCmpInst(CmpInst::Predicate(predicate), S1, S2, Name,
- InsertAtEnd);
+ return new FCmpInst(*InsertAtEnd, CmpInst::Predicate(predicate),
+ S1, S2, Name);
}
void CmpInst::swapOperands() {
@@ -2919,74 +2929,145 @@ void SwitchInst::setSuccessorV(unsigned idx, BasicBlock *B) {
// Define these methods here so vtables don't get emitted into every translation
// unit that uses these classes.
-GetElementPtrInst *GetElementPtrInst::clone() const {
+GetElementPtrInst *GetElementPtrInst::clone(LLVMContext&) const {
return new(getNumOperands()) GetElementPtrInst(*this);
}
-BinaryOperator *BinaryOperator::clone() const {
+BinaryOperator *BinaryOperator::clone(LLVMContext&) const {
return Create(getOpcode(), Op<0>(), Op<1>());
}
-FCmpInst* FCmpInst::clone() const {
- return new FCmpInst(getPredicate(), Op<0>(), Op<1>());
+FCmpInst* FCmpInst::clone(LLVMContext &Context) const {
+ return new FCmpInst(Context, getPredicate(), Op<0>(), Op<1>());
}
-ICmpInst* ICmpInst::clone() const {
- return new ICmpInst(getPredicate(), Op<0>(), Op<1>());
+ICmpInst* ICmpInst::clone(LLVMContext &Context) const {
+ return new ICmpInst(Context, getPredicate(), Op<0>(), Op<1>());
}
-ExtractValueInst *ExtractValueInst::clone() const {
+ExtractValueInst *ExtractValueInst::clone(LLVMContext&) const {
return new ExtractValueInst(*this);
}
-InsertValueInst *InsertValueInst::clone() const {
+InsertValueInst *InsertValueInst::clone(LLVMContext&) const {
return new InsertValueInst(*this);
}
+MallocInst *MallocInst::clone(LLVMContext&) const {
+ return new MallocInst(*this);
+}
+
+AllocaInst *AllocaInst::clone(LLVMContext&) const {
+ return new AllocaInst(*this);
+}
+
+FreeInst *FreeInst::clone(LLVMContext&) const {
+ return new FreeInst(getOperand(0));
+}
+
+LoadInst *LoadInst::clone(LLVMContext&) const {
+ return new LoadInst(*this);
+}
+
+StoreInst *StoreInst::clone(LLVMContext&) const {
+ return new StoreInst(*this);
+}
+
+CastInst *TruncInst::clone(LLVMContext&) const {
+ return new TruncInst(*this);
+}
+
+CastInst *ZExtInst::clone(LLVMContext&) const {
+ return new ZExtInst(*this);
+}
+
+CastInst *SExtInst::clone(LLVMContext&) const {
+ return new SExtInst(*this);
+}
+
+CastInst *FPTruncInst::clone(LLVMContext&) const {
+ return new FPTruncInst(*this);
+}
+
+CastInst *FPExtInst::clone(LLVMContext&) const {
+ return new FPExtInst(*this);
+}
+
+CastInst *UIToFPInst::clone(LLVMContext&) const {
+ return new UIToFPInst(*this);
+}
+
+CastInst *SIToFPInst::clone(LLVMContext&) const {
+ return new SIToFPInst(*this);
+}
-MallocInst *MallocInst::clone() const { return new MallocInst(*this); }
-AllocaInst *AllocaInst::clone() const { return new AllocaInst(*this); }
-FreeInst *FreeInst::clone() const { return new FreeInst(getOperand(0)); }
-LoadInst *LoadInst::clone() const { return new LoadInst(*this); }
-StoreInst *StoreInst::clone() const { return new StoreInst(*this); }
-CastInst *TruncInst::clone() const { return new TruncInst(*this); }
-CastInst *ZExtInst::clone() const { return new ZExtInst(*this); }
-CastInst *SExtInst::clone() const { return new SExtInst(*this); }
-CastInst *FPTruncInst::clone() const { return new FPTruncInst(*this); }
-CastInst *FPExtInst::clone() const { return new FPExtInst(*this); }
-CastInst *UIToFPInst::clone() const { return new UIToFPInst(*this); }
-CastInst *SIToFPInst::clone() const { return new SIToFPInst(*this); }
-CastInst *FPToUIInst::clone() const { return new FPToUIInst(*this); }
-CastInst *FPToSIInst::clone() const { return new FPToSIInst(*this); }
-CastInst *PtrToIntInst::clone() const { return new PtrToIntInst(*this); }
-CastInst *IntToPtrInst::clone() const { return new IntToPtrInst(*this); }
-CastInst *BitCastInst::clone() const { return new BitCastInst(*this); }
-CallInst *CallInst::clone() const {
+CastInst *FPToUIInst::clone(LLVMContext&) const {
+ return new FPToUIInst(*this);
+}
+
+CastInst *FPToSIInst::clone(LLVMContext&) const {
+ return new FPToSIInst(*this);
+}
+
+CastInst *PtrToIntInst::clone(LLVMContext&) const {
+ return new PtrToIntInst(*this);
+}
+
+CastInst *IntToPtrInst::clone(LLVMContext&) const {
+ return new IntToPtrInst(*this);
+}
+
+CastInst *BitCastInst::clone(LLVMContext&) const {
+ return new BitCastInst(*this);
+}
+
+CallInst *CallInst::clone(LLVMContext&) const {
return new(getNumOperands()) CallInst(*this);
}
-SelectInst *SelectInst::clone() const {
+
+SelectInst *SelectInst::clone(LLVMContext&) const {
return new(getNumOperands()) SelectInst(*this);
}
-VAArgInst *VAArgInst::clone() const { return new VAArgInst(*this); }
-ExtractElementInst *ExtractElementInst::clone() const {
+VAArgInst *VAArgInst::clone(LLVMContext&) const {
+ return new VAArgInst(*this);
+}
+
+ExtractElementInst *ExtractElementInst::clone(LLVMContext&) const {
return new ExtractElementInst(*this);
}
-InsertElementInst *InsertElementInst::clone() const {
+
+InsertElementInst *InsertElementInst::clone(LLVMContext&) const {
return InsertElementInst::Create(*this);
}
-ShuffleVectorInst *ShuffleVectorInst::clone() const {
+
+ShuffleVectorInst *ShuffleVectorInst::clone(LLVMContext&) const {
return new ShuffleVectorInst(*this);
}
-PHINode *PHINode::clone() const { return new PHINode(*this); }
-ReturnInst *ReturnInst::clone() const {
+
+PHINode *PHINode::clone(LLVMContext&) const {
+ return new PHINode(*this);
+}
+
+ReturnInst *ReturnInst::clone(LLVMContext&) const {
return new(getNumOperands()) ReturnInst(*this);
}
-BranchInst *BranchInst::clone() const {
+
+BranchInst *BranchInst::clone(LLVMContext&) const {
unsigned Ops(getNumOperands());
return new(Ops, Ops == 1) BranchInst(*this);
}
-SwitchInst *SwitchInst::clone() const { return new SwitchInst(*this); }
-InvokeInst *InvokeInst::clone() const {
+
+SwitchInst *SwitchInst::clone(LLVMContext&) const {
+ return new SwitchInst(*this);
+}
+
+InvokeInst *InvokeInst::clone(LLVMContext&) const {
return new(getNumOperands()) InvokeInst(*this);
}
-UnwindInst *UnwindInst::clone() const { return new UnwindInst(); }
-UnreachableInst *UnreachableInst::clone() const { return new UnreachableInst();}
+
+UnwindInst *UnwindInst::clone(LLVMContext&) const {
+ return new UnwindInst();
+}
+
+UnreachableInst *UnreachableInst::clone(LLVMContext&) const {
+ return new UnreachableInst();
+}
diff --git a/lib/VMCore/LLVMContext.cpp b/lib/VMCore/LLVMContext.cpp
index 422798d220..4a9953a4f1 100644
--- a/lib/VMCore/LLVMContext.cpp
+++ b/lib/VMCore/LLVMContext.cpp
@@ -485,3 +485,10 @@ VectorType* LLVMContext::getVectorTypeExtendedElement(const VectorType* VTy) {
VectorType* LLVMContext::getVectorTypeTruncatedElement(const VectorType* VTy) {
return VectorType::getTruncatedElementVectorType(VTy);
}
+
+const Type* LLVMContext::makeCmpResultType(const Type* opnd_type) {
+ if (const VectorType* vt = dyn_cast<const VectorType>(opnd_type)) {
+ return getVectorType(Type::Int1Ty, vt->getNumElements());
+ }
+ return Type::Int1Ty;
+}
diff --git a/tools/bugpoint/Miscompilation.cpp b/tools/bugpoint/Miscompilation.cpp
index a24ea77781..21e141243b 100644
--- a/tools/bugpoint/Miscompilation.cpp
+++ b/tools/bugpoint/Miscompilation.cpp
@@ -738,8 +738,8 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
// Check to see if we already looked up the value.
Value *CachedVal = new LoadInst(Cache, "fpcache", EntryBB);
- Value *IsNull = new ICmpInst(ICmpInst::ICMP_EQ, CachedVal,
- NullPtr, "isNull", EntryBB);
+ Value *IsNull = new ICmpInst(*EntryBB, ICmpInst::ICMP_EQ, CachedVal,
+ NullPtr, "isNull");
BranchInst::Create(LookupBB, DoCallBB, IsNull, EntryBB);
// Resolve the call to function F via the JIT API: