llvm.org GIT mirror llvm / 333c400
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 Owen Anderson 10 years ago
37 changed file(s) with 489 addition(s) and 340 deletion(s). Raw diff Collapse all Expand all
426426 LoadInst *tape_0 = new LoadInst(head_0, tapereg, testbb);
427427
428428 //%test.%d = icmp eq i8 %tape.%d, 0
429 ICmpInst *test_0 = new ICmpInst(ICmpInst::ICMP_EQ, tape_0,
430 ConstantInt::get(APInt(8, 0)), testreg,
431 testbb);
429 ICmpInst *test_0 = new ICmpInst(*testbb, ICmpInst::ICMP_EQ, tape_0,
430 ConstantInt::get(APInt(8, 0)), testreg);
432431
433432 //br i1 %test.%d, label %main.%d, label %main.%d
434433 BasicBlock *bb_0 = BasicBlock::Create(label, brainf_func);
5959 BasicBlock* RecurseBB = BasicBlock::Create("recurse", FibF);
6060
6161 // Create the "if (arg <= 2) goto exitbb"
62 Value *CondInst = new ICmpInst(ICmpInst::ICMP_SLE, ArgX, Two, "cond", BB);
62 Value *CondInst = new ICmpInst(*BB, ICmpInst::ICMP_SLE, ArgX, Two, "cond");
6363 BranchInst::Create(RetBB, RecurseBB, CondInst, BB);
6464
6565 // Create: ret int 1
8484 BasicBlock* RecurseBB = BasicBlock::Create("recurse", FibF);
8585
8686 // Create the "if (arg < 2) goto exitbb"
87 Value *CondInst = new ICmpInst(ICmpInst::ICMP_SLE, ArgX, Two, "cond", BB);
87 Value *CondInst = new ICmpInst(*BB, ICmpInst::ICMP_SLE, ArgX, Two, "cond");
8888 BranchInst::Create(RetBB, RecurseBB, CondInst, BB);
8989
9090 // Create: ret int 1
2020 #include "llvm/DerivedTypes.h"
2121
2222 namespace llvm {
23
24 class LLVMContext;
2325
2426 //===----------------------------------------------------------------------===//
2527 // TerminatorInst Class
4951 virtual void setSuccessorV(unsigned idx, BasicBlock *B) = 0;
5052 public:
5153
52 virtual Instruction *clone() const = 0;
54 virtual Instruction *clone(LLVMContext &Context) const = 0;
5355
5456 /// getNumSuccessors - Return the number of successors that this terminator
5557 /// has.
234236 return static_cast(Instruction::getOpcode());
235237 }
236238
237 virtual BinaryOperator *clone() const;
239 virtual BinaryOperator *clone(LLVMContext &Context) const;
238240
239241 /// swapOperands - Exchange the two operands to this instruction.
240242 /// This instruction is safe to use on any binary instruction and
568570 /// instruction into a BasicBlock right before the specified instruction.
569571 /// The specified Instruction is allowed to be a dereferenced end iterator.
570572 /// @brief Create a CmpInst
571 static CmpInst *Create(OtherOps Op, unsigned short predicate, Value *S1,
573 static CmpInst *Create(LLVMContext &Context, OtherOps Op,
574 unsigned short predicate, Value *S1,
572575 Value *S2, const std::string &Name = "",
573576 Instruction *InsertBefore = 0);
574577
659662 static inline bool classof(const Value *V) {
660663 return isa(V) && classof(cast(V));
661664 }
662 /// @brief Create a result type for fcmp/icmp
663 static const Type* makeCmpResultType(const Type* opnd_type) {
664 if (const VectorType* vt = dyn_cast(opnd_type)) {
665 return VectorType::get(Type::Int1Ty, vt->getNumElements());
666 }
667 return Type::Int1Ty;
668 }
669665 };
670666
671667
1818 #include "llvm/ADT/ilist_node.h"
1919
2020 namespace llvm {
21
22 class LLVMContext;
2123
2224 template
2325 class SymbolTableListTraits;
4446 /// * The instruction has no parent
4547 /// * The instruction has no name
4648 ///
47 virtual Instruction *clone() const = 0;
49 virtual Instruction *clone(LLVMContext &Context) const = 0;
4850
4951 /// isIdenticalTo - Return true if the specified instruction is exactly
5052 /// identical to the current one. This means that all operands match and any
1919 #include "llvm/DerivedTypes.h"
2020 #include "llvm/Attributes.h"
2121 #include "llvm/BasicBlock.h"
22 #include "llvm/LLVMContext.h"
2223 #include "llvm/ADT/SmallVector.h"
2324 #include
2425
7374 unsigned getAlignment() const { return (1u << SubclassData) >> 1; }
7475 void setAlignment(unsigned Align);
7576
76 virtual Instruction *clone() const = 0;
77 virtual Instruction *clone(LLVMContext &Context) const = 0;
7778
7879 // Methods for support type inquiry through isa, cast, and dyn_cast:
7980 static inline bool classof(const AllocationInst *) { return true; }
119120 Instruction *InsertBefore = 0)
120121 : AllocationInst(Ty, ArraySize, Malloc, Align, NameStr, InsertBefore) {}
121122
122 virtual MallocInst *clone() const;
123 virtual MallocInst *clone(LLVMContext &Context) const;
123124
124125 // Methods for support type inquiry through isa, cast, and dyn_cast:
125126 static inline bool classof(const MallocInst *) { return true; }
163164 const std::string &NameStr, BasicBlock *InsertAtEnd)
164165 : AllocationInst(Ty, ArraySize, Alloca, Align, NameStr, InsertAtEnd) {}
165166
166 virtual AllocaInst *clone() const;
167 virtual AllocaInst *clone(LLVMContext &Context) const;
167168
168169 /// isStaticAlloca - Return true if this alloca is in the entry block of the
169170 /// function and is a constant size. If so, the code generator will fold it
193194 explicit FreeInst(Value *Ptr, Instruction *InsertBefore = 0);
194195 FreeInst(Value *Ptr, BasicBlock *InsertAfter);
195196
196 virtual FreeInst *clone() const;
197 virtual FreeInst *clone(LLVMContext &Context) const;
197198
198199 // Accessor methods for consistency with other memory operations
199200 Value *getPointerOperand() { return getOperand(0); }
259260 SubclassData = (SubclassData & ~1) | (V ? 1 : 0);
260261 }
261262
262 virtual LoadInst *clone() const;
263 virtual LoadInst *clone(LLVMContext &Context) const;
263264
264265 /// getAlignment - Return the alignment of the access that is being performed
265266 ///
343344
344345 void setAlignment(unsigned Align);
345346
346 virtual StoreInst *clone() const;
347 virtual StoreInst *clone(LLVMContext &Context) const;
347348
348349 Value *getPointerOperand() { return getOperand(1); }
349350 const Value *getPointerOperand() const { return getOperand(1); }
484485 return new(2) GetElementPtrInst(Ptr, Idx, NameStr, InsertAtEnd);
485486 }
486487
487 virtual GetElementPtrInst *clone() const;
488 virtual GetElementPtrInst *clone(LLVMContext &Context) const;
488489
489490 /// Transparently provide more efficient getOperand methods.
490491 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
625626 public:
626627 /// @brief Constructor with insert-before-instruction semantics.
627628 ICmpInst(
629 Instruction *InsertBefore, ///< Where to insert
628630 Predicate pred, ///< The predicate to use for the comparison
629631 Value *LHS, ///< The left-hand-side of the expression
630632 Value *RHS, ///< The right-hand-side of the expression
631 const std::string &NameStr = "", ///< Name of the instruction
632 Instruction *InsertBefore = 0 ///< Where to insert
633 ) : CmpInst(makeCmpResultType(LHS->getType()),
633 const std::string &NameStr = "" ///< Name of the instruction
634 ) : CmpInst(InsertBefore->getParent()->getContext()->
635 makeCmpResultType(LHS->getType()),
634636 Instruction::ICmp, pred, LHS, RHS, NameStr,
635637 InsertBefore) {
636638 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
644646 "Invalid operand types for ICmp instruction");
645647 }
646648
647 /// @brief Constructor with insert-at-block-end semantics.
649 /// @brief Constructor with insert-at-end semantics.
648650 ICmpInst(
651 BasicBlock &InsertAtEnd, ///< Block to insert into.
652 Predicate pred, ///< The predicate to use for the comparison
653 Value *LHS, ///< The left-hand-side of the expression
654 Value *RHS, ///< The right-hand-side of the expression
655 const std::string &NameStr = "" ///< Name of the instruction
656 ) : CmpInst(InsertAtEnd.getContext()->makeCmpResultType(LHS->getType()),
657 Instruction::ICmp, pred, LHS, RHS, NameStr,
658 &InsertAtEnd) {
659 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
660 pred <= CmpInst::LAST_ICMP_PREDICATE &&
661 "Invalid ICmp predicate value");
662 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
663 "Both operands to ICmp instruction are not of the same type!");
664 // Check that the operands are the right type
665 assert((getOperand(0)->getType()->isIntOrIntVector() ||
666 isa(getOperand(0)->getType())) &&
667 "Invalid operand types for ICmp instruction");
668 }
669
670 /// @brief Constructor with no-insertion semantics
671 ICmpInst(
672 LLVMContext &Context, ///< Context to construct within
649673 Predicate pred, ///< The predicate to use for the comparison
650674 Value *LHS, ///< The left-hand-side of the expression
651675 Value *RHS, ///< The right-hand-side of the expression
652 const std::string &NameStr, ///< Name of the instruction
653 BasicBlock *InsertAtEnd ///< Block to insert into.
654 ) : CmpInst(makeCmpResultType(LHS->getType()),
655 Instruction::ICmp, pred, LHS, RHS, NameStr,
656 InsertAtEnd) {
676 const std::string &NameStr = "" ///< Name of the instruction
677 ) : CmpInst(Context.makeCmpResultType(LHS->getType()),
678 Instruction::ICmp, pred, LHS, RHS, NameStr) {
657679 assert(pred >= CmpInst::FIRST_ICMP_PREDICATE &&
658680 pred <= CmpInst::LAST_ICMP_PREDICATE &&
659681 "Invalid ICmp predicate value");
755777 Op<0>().swap(Op<1>());
756778 }
757779
758 virtual ICmpInst *clone() const;
780 virtual ICmpInst *clone(LLVMContext &Context) const;
759781
760782 // Methods for support type inquiry through isa, cast, and dyn_cast:
761783 static inline bool classof(const ICmpInst *) { return true; }
780802 public:
781803 /// @brief Constructor with insert-before-instruction semantics.
782804 FCmpInst(
805 Instruction *InsertBefore, ///< Where to insert
783806 Predicate pred, ///< The predicate to use for the comparison
784807 Value *LHS, ///< The left-hand-side of the expression
785808 Value *RHS, ///< The right-hand-side of the expression
786 const std::string &NameStr = "", ///< Name of the instruction
787 Instruction *InsertBefore = 0 ///< Where to insert
788 ) : CmpInst(makeCmpResultType(LHS->getType()),
809 const std::string &NameStr = "" ///< Name of the instruction
810 ) : CmpInst(InsertBefore->getParent()->getContext()->
811 makeCmpResultType(LHS->getType()),
789812 Instruction::FCmp, pred, LHS, RHS, NameStr,
790813 InsertBefore) {
791814 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
796819 assert(getOperand(0)->getType()->isFPOrFPVector() &&
797820 "Invalid operand types for FCmp instruction");
798821 }
799
800 /// @brief Constructor with insert-at-block-end semantics.
822
823 /// @brief Constructor with insert-at-end semantics.
801824 FCmpInst(
825 BasicBlock &InsertAtEnd, ///< Block to insert into.
826 Predicate pred, ///< The predicate to use for the comparison
827 Value *LHS, ///< The left-hand-side of the expression
828 Value *RHS, ///< The right-hand-side of the expression
829 const std::string &NameStr = "" ///< Name of the instruction
830 ) : CmpInst(InsertAtEnd.getContext()->makeCmpResultType(LHS->getType()),
831 Instruction::FCmp, pred, LHS, RHS, NameStr,
832 &InsertAtEnd) {
833 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
834 "Invalid FCmp predicate value");
835 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
836 "Both operands to FCmp instruction are not of the same type!");
837 // Check that the operands are the right type
838 assert(getOperand(0)->getType()->isFPOrFPVector() &&
839 "Invalid operand types for FCmp instruction");
840 }
841
842 /// @brief Constructor with no-insertion semantics
843 FCmpInst(
844 LLVMContext &Context, ///< Context to build in
802845 Predicate pred, ///< The predicate to use for the comparison
803846 Value *LHS, ///< The left-hand-side of the expression
804847 Value *RHS, ///< The right-hand-side of the expression
805 const std::string &NameStr, ///< Name of the instruction
806 BasicBlock *InsertAtEnd ///< Block to insert into.
807 ) : CmpInst(makeCmpResultType(LHS->getType()),
808 Instruction::FCmp, pred, LHS, RHS, NameStr,
809 InsertAtEnd) {
848 const std::string &NameStr = "" ///< Name of the instruction
849 ) : CmpInst(Context.makeCmpResultType(LHS->getType()),
850 Instruction::FCmp, pred, LHS, RHS, NameStr) {
810851 assert(pred <= FCmpInst::LAST_FCMP_PREDICATE &&
811852 "Invalid FCmp predicate value");
812853 assert(getOperand(0)->getType() == getOperand(1)->getType() &&
847888 Op<0>().swap(Op<1>());
848889 }
849890
850 virtual FCmpInst *clone() const;
891 virtual FCmpInst *clone(LLVMContext &Context) const;
851892
852893 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
853894 static inline bool classof(const FCmpInst *) { return true; }
958999 SubclassData = (SubclassData & ~1) | unsigned(isTC);
9591000 }
9601001
961 virtual CallInst *clone() const;
1002 virtual CallInst *clone(LLVMContext &Context) const;
9621003
9631004 /// Provide fast operand accessors
9641005 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
11511192 return static_cast(Instruction::getOpcode());
11521193 }
11531194
1154 virtual SelectInst *clone() const;
1195 virtual SelectInst *clone(LLVMContext &Context) const;
11551196
11561197 // Methods for support type inquiry through isa, cast, and dyn_cast:
11571198 static inline bool classof(const SelectInst *) { return true; }
11911232 setName(NameStr);
11921233 }
11931234
1194 virtual VAArgInst *clone() const;
1235 virtual VAArgInst *clone(LLVMContext &Context) const;
11951236
11961237 // Methods for support type inquiry through isa, cast, and dyn_cast:
11971238 static inline bool classof(const VAArgInst *) { return true; }
12351276 /// formed with the specified operands.
12361277 static bool isValidOperands(const Value *Vec, const Value *Idx);
12371278
1238 virtual ExtractElementInst *clone() const;
1279 virtual ExtractElementInst *clone(LLVMContext &Context) const;
12391280
12401281 /// Transparently provide more efficient getOperand methods.
12411282 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
13051346 static bool isValidOperands(const Value *Vec, const Value *NewElt,
13061347 const Value *Idx);
13071348
1308 virtual InsertElementInst *clone() const;
1349 virtual InsertElementInst *clone(LLVMContext &Context) const;
13091350
13101351 /// getType - Overload to return most specific vector type.
13111352 ///
13571398 static bool isValidOperands(const Value *V1, const Value *V2,
13581399 const Value *Mask);
13591400
1360 virtual ShuffleVectorInst *clone() const;
1401 virtual ShuffleVectorInst *clone(LLVMContext &Context) const;
13611402
13621403 /// getType - Overload to return most specific vector type.
13631404 ///
15011542 return new ExtractValueInst(Agg, Idxs, Idxs + 1, NameStr, InsertAtEnd);
15021543 }
15031544
1504 virtual ExtractValueInst *clone() const;
1545 virtual ExtractValueInst *clone(LLVMContext &Context) const;
15051546
15061547 /// getIndexedType - Returns the type of the element that would be extracted
15071548 /// with an extractvalue instruction with the specified parameters.
16711712 return new InsertValueInst(Agg, Val, Idx, NameStr, InsertAtEnd);
16721713 }
16731714
1674 virtual InsertValueInst *clone() const;
1715 virtual InsertValueInst *clone(LLVMContext &Context) const;
16751716
16761717 /// Transparently provide more efficient getOperand methods.
16771718 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
18001841 resizeOperands(NumValues*2);
18011842 }
18021843
1803 virtual PHINode *clone() const;
1844 virtual PHINode *clone(LLVMContext &Context) const;
18041845
18051846 /// Provide fast operand accessors
18061847 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
19592000 }
19602001 virtual ~ReturnInst();
19612002
1962 virtual ReturnInst *clone() const;
2003 virtual ReturnInst *clone(LLVMContext &Context) const;
19632004
19642005 /// Provide fast operand accessors
19652006 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
20412082 /// Transparently provide more efficient getOperand methods.
20422083 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
20432084
2044 virtual BranchInst *clone() const;
2085 virtual BranchInst *clone(LLVMContext &Context) const;
20452086
20462087 bool isUnconditional() const { return getNumOperands() == 1; }
20472088 bool isConditional() const { return getNumOperands() == 3; }
22112252 ///
22122253 void removeCase(unsigned idx);
22132254
2214 virtual SwitchInst *clone() const;
2255 virtual SwitchInst *clone(LLVMContext &Context) const;
22152256
22162257 unsigned getNumSuccessors() const { return getNumOperands()/2; }
22172258 BasicBlock *getSuccessor(unsigned idx) const {
23252366 Values, NameStr, InsertAtEnd);
23262367 }
23272368
2328 virtual InvokeInst *clone() const;
2369 virtual InvokeInst *clone(LLVMContext &Context) const;
23292370
23302371 /// Provide fast operand accessors
23312372 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
25132554 explicit UnwindInst(Instruction *InsertBefore = 0);
25142555 explicit UnwindInst(BasicBlock *InsertAtEnd);
25152556
2516 virtual UnwindInst *clone() const;
2557 virtual UnwindInst *clone(LLVMContext &Context) const;
25172558
25182559 unsigned getNumSuccessors() const { return 0; }
25192560
25502591 explicit UnreachableInst(Instruction *InsertBefore = 0);
25512592 explicit UnreachableInst(BasicBlock *InsertAtEnd);
25522593
2553 virtual UnreachableInst *clone() const;
2594 virtual UnreachableInst *clone(LLVMContext &Context) const;
25542595
25552596 unsigned getNumSuccessors() const { return 0; }
25562597
25962637 );
25972638
25982639 /// @brief Clone an identical TruncInst
2599 virtual CastInst *clone() const;
2640 virtual CastInst *clone(LLVMContext &Context) const;
26002641
26012642 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
26022643 static inline bool classof(const TruncInst *) { return true; }
26362677 );
26372678
26382679 /// @brief Clone an identical ZExtInst
2639 virtual CastInst *clone() const;
2680 virtual CastInst *clone(LLVMContext &Context) const;
26402681
26412682 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
26422683 static inline bool classof(const ZExtInst *) { return true; }
26762717 );
26772718
26782719 /// @brief Clone an identical SExtInst
2679 virtual CastInst *clone() const;
2720 virtual CastInst *clone(LLVMContext &Context) const;
26802721
26812722 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
26822723 static inline bool classof(const SExtInst *) { return true; }
27152756 );
27162757
27172758 /// @brief Clone an identical FPTruncInst
2718 virtual CastInst *clone() const;
2759 virtual CastInst *clone(LLVMContext &Context) const;
27192760
27202761 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
27212762 static inline bool classof(const FPTruncInst *) { return true; }
27542795 );
27552796
27562797 /// @brief Clone an identical FPExtInst
2757 virtual CastInst *clone() const;
2798 virtual CastInst *clone(LLVMContext &Context) const;
27582799
27592800 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
27602801 static inline bool classof(const FPExtInst *) { return true; }
27932834 );
27942835
27952836 /// @brief Clone an identical UIToFPInst
2796 virtual CastInst *clone() const;
2837 virtual CastInst *clone(LLVMContext &Context) const;
27972838
27982839 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
27992840 static inline bool classof(const UIToFPInst *) { return true; }
28322873 );
28332874
28342875 /// @brief Clone an identical SIToFPInst
2835 virtual CastInst *clone() const;
2876 virtual CastInst *clone(LLVMContext &Context) const;
28362877
28372878 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
28382879 static inline bool classof(const SIToFPInst *) { return true; }
28712912 );
28722913
28732914 /// @brief Clone an identical FPToUIInst
2874 virtual CastInst *clone() const;
2915 virtual CastInst *clone(LLVMContext &Context) const;
28752916
28762917 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
28772918 static inline bool classof(const FPToUIInst *) { return true; }
29102951 );
29112952
29122953 /// @brief Clone an identical FPToSIInst
2913 virtual CastInst *clone() const;
2954 virtual CastInst *clone(LLVMContext &Context) const;
29142955
29152956 /// @brief Methods for support type inquiry through isa, cast, and dyn_cast:
29162957 static inline bool classof(const FPToSIInst *) { return true; }
29492990 );
29502991
29512992 /// @brief Clone an identical IntToPtrInst
2952 virtual CastInst *clone() const;
2993 virtual CastInst *clone(LLVMContext &Context) const;
29532994
29542995 // Methods for support type inquiry through isa, cast, and dyn_cast:
29552996 static inline bool classof(const IntToPtrInst *) { return true; }
29883029 );
29893030
29903031 /// @brief Clone an identical PtrToIntInst
2991 virtual CastInst *clone() const;
3032 virtual CastInst *clone(LLVMContext &Context) const;
29923033
29933034 // Methods for support type inquiry through isa, cast, and dyn_cast:
29943035 static inline bool classof(const PtrToIntInst *) { return true; }
30273068 );
30283069
30293070 /// @brief Clone an identical BitCastInst
3030 virtual CastInst *clone() const;
3071 virtual CastInst *clone(LLVMContext &Context) const;
30313072
30323073 // Methods for support type inquiry through isa, cast, and dyn_cast:
30333074 static inline bool classof(const BitCastInst *) { return true; }
212212 VectorType* getVectorTypeInteger(const VectorType* VTy);
213213 VectorType* getVectorTypeExtendedElement(const VectorType* VTy);
214214 VectorType* getVectorTypeTruncatedElement(const VectorType* VTy);
215
216 // Other helpers
217 /// @brief Create a result type for fcmp/icmp
218 const Type* makeCmpResultType(const Type* opnd_type);
215219 };
216220
217221 /// FOR BACKWARDS COMPATIBILITY - Returns a global context.
564564 if (Constant *LC = dyn_cast(LHS))
565565 if (Constant *RC = dyn_cast(RHS))
566566 return Folder.CreateICmp(P, LC, RC);
567 return Insert(new ICmpInst(P, LHS, RHS), Name);
567 return Insert(new ICmpInst(Context, P, LHS, RHS), Name);
568568 }
569569 Value *CreateFCmp(CmpInst::Predicate P, Value *LHS, Value *RHS,
570570 const char *Name = "") {
571571 if (Constant *LC = dyn_cast(LHS))
572572 if (Constant *RC = dyn_cast(RHS))
573573 return Folder.CreateFCmp(P, LC, RC);
574 return Insert(new FCmpInst(P, LHS, RHS), Name);
574 return Insert(new FCmpInst(Context, P, LHS, RHS), Name);
575575 }
576576
577577 //===--------------------------------------------------------------------===//
28862886 if (Opc == Instruction::FCmp) {
28872887 if (!LHS->getType()->isFPOrFPVector())
28882888 return Error(Loc, "fcmp requires floating point operands");
2889 Inst = new FCmpInst(CmpInst::Predicate(Pred), LHS, RHS);
2889 Inst = new FCmpInst(Context, CmpInst::Predicate(Pred), LHS, RHS);
28902890 } else {
28912891 assert(Opc == Instruction::ICmp && "Unknown opcode for CmpInst!");
28922892 if (!LHS->getType()->isIntOrIntVector() &&
28932893 !isa(LHS->getType()))
28942894 return Error(Loc, "icmp requires integer operands");
2895 Inst = new ICmpInst(CmpInst::Predicate(Pred), LHS, RHS);
2895 Inst = new ICmpInst(Context, CmpInst::Predicate(Pred), LHS, RHS);
28962896 }
28972897 return false;
28982898 }
16421642 return Error("Invalid CMP record");
16431643
16441644 if (LHS->getType()->isFPOrFPVector())
1645 I = new FCmpInst((FCmpInst::Predicate)Record[OpNum], LHS, RHS);
1645 I = new FCmpInst(Context, (FCmpInst::Predicate)Record[OpNum], LHS, RHS);
16461646 else
1647 I = new ICmpInst((ICmpInst::Predicate)Record[OpNum], LHS, RHS);
1647 I = new ICmpInst(Context, (ICmpInst::Predicate)Record[OpNum], LHS, RHS);
16481648 break;
16491649 }
16501650
200200 // Generate the stack protector instructions in the old basic block.
201201 LoadInst *LI1 = new LoadInst(StackGuardVar, "", false, BB);
202202 LoadInst *LI2 = new LoadInst(AI, "", true, BB);
203 ICmpInst *Cmp = new ICmpInst(CmpInst::ICMP_EQ, LI1, LI2, "", BB);
203 ICmpInst *Cmp = new ICmpInst(*BB, CmpInst::ICMP_EQ, LI1, LI2, "");
204204 BranchInst::Create(NewBB, FailBB, Cmp, BB);
205205 }
206206
11841184 InsertedScalarizedValues, PHIsToRewrite,
11851185 Context);
11861186
1187 Value *New = new ICmpInst(SCI->getPredicate(), NPtr,
1188 Context->getNullValue(NPtr->getType()),
1189 SCI->getName(), SCI);
1187 Value *New = new ICmpInst(SCI, SCI->getPredicate(), NPtr,
1188 Context->getNullValue(NPtr->getType()),
1189 SCI->getName());
11901190 SCI->replaceAllUsesWith(New);
11911191 SCI->eraseFromParent();
11921192 return;
13091309 // }
13101310 Value *RunningOr = 0;
13111311 for (unsigned i = 0, e = FieldMallocs.size(); i != e; ++i) {
1312 Value *Cond = new ICmpInst(ICmpInst::ICMP_EQ, FieldMallocs[i],
1312 Value *Cond = new ICmpInst(MI, ICmpInst::ICMP_EQ, FieldMallocs[i],
13131313 Context->getNullValue(FieldMallocs[i]->getType()),
1314 "isnull", MI);
1314 "isnull");
13151315 if (!RunningOr)
13161316 RunningOr = Cond; // First seteq
13171317 else
13361336 // pointer, because some may be null while others are not.
13371337 for (unsigned i = 0, e = FieldGlobals.size(); i != e; ++i) {
13381338 Value *GVVal = new LoadInst(FieldGlobals[i], "tmp", NullPtrBlock);
1339 Value *Cmp = new ICmpInst(ICmpInst::ICMP_NE, GVVal,
1339 Value *Cmp = new ICmpInst(*NullPtrBlock, ICmpInst::ICMP_NE, GVVal,
13401340 Context->getNullValue(GVVal->getType()),
1341 "tmp", NullPtrBlock);
1341 "tmp");
13421342 BasicBlock *FreeBlock = BasicBlock::Create("free_it", OrigBB->getParent());
13431343 BasicBlock *NextBlock = BasicBlock::Create("next", OrigBB->getParent());
13441344 BranchInst::Create(FreeBlock, NextBlock, Cmp, NullPtrBlock);
212212 //decrement counter
213213 LoadInst* l = new LoadInst(Counter, "counter", t);
214214
215 ICmpInst* s = new ICmpInst(ICmpInst::ICMP_EQ, l,
215 ICmpInst* s = new ICmpInst(t, ICmpInst::ICMP_EQ, l,
216216 Context->getConstantInt(T, 0),
217 "countercc", t);
217 "countercc");
218218
219219 Value* nv = BinaryOperator::CreateSub(l, Context->getConstantInt(T, 1),
220220 "counternew", t);
286286 //decrement counter
287287 LoadInst* l = new LoadInst(AI, "counter", t);
288288
289 ICmpInst* s = new ICmpInst(ICmpInst::ICMP_EQ, l,
289 ICmpInst* s = new ICmpInst(t, ICmpInst::ICMP_EQ, l,
290290 Context->getConstantInt(T, 0),
291 "countercc", t);
291 "countercc");
292292
293293 Value* nv = BinaryOperator::CreateSub(l, Context->getConstantInt(T, 1),
294294 "counternew", t);
323323 BinaryOperator::CreateAnd(c, Context->getConstantInt(Type::Int64Ty, rm),
324324 "mrdcc", t);
325325
326 ICmpInst *s = new ICmpInst(ICmpInst::ICMP_EQ, b,
326 ICmpInst *s = new ICmpInst(t, ICmpInst::ICMP_EQ, b,
327327 Context->getConstantInt(Type::Int64Ty, 0),
328 "mrdccc", t);
328 "mrdccc");
329329
330330 t->setCondition(s);
331331 }
393393 return i;
394394 } else {
395395 //translate this
396 Instruction* i2 = i->clone();
396 Instruction* i2 = i->clone(*Context);
397397 if (i->hasName())
398398 i2->setName("dup_" + i->getName());
399399 TransCache[i] = i2;
519519 BasicBlock::iterator InsertPt = UserBB->getFirstNonPHI();
520520
521521 InsertedCmp =
522 CmpInst::Create(CI->getOpcode(), CI->getPredicate(), CI->getOperand(0),
522 CmpInst::Create(*DefBB->getContext(), CI->getOpcode(),
523 CI->getPredicate(), CI->getOperand(0),
523524 CI->getOperand(1), "", InsertPt);
524525 MadeChange = true;
525526 }
16261626 // will be available in the predecessor by the time we need them. Any
16271627 // that weren't original present will have been instantiated earlier
16281628 // in this loop.
1629 Instruction* PREInstr = CurInst->clone();
1629 Instruction* PREInstr = CurInst->clone(*Context);
16301630 bool success = true;
16311631 for (unsigned i = 0, e = CurInst->getNumOperands(); i != e; ++i) {
16321632 Value *Op = PREInstr->getOperand(i);
860860 newOp1, newOp2,
861861 BO->getName()+".expr");
862862 else if (CmpInst* C = dyn_cast(U))
863 newVal = CmpInst::Create(C->getOpcode(),
863 newVal = CmpInst::Create(*Context, C->getOpcode(),
864864 C->getPredicate(),
865865 newOp1, newOp2,
866866 C->getName()+".expr");
16781678 BO->getName()+".gvnpre",
16791679 (*PI)->getTerminator());
16801680 else if (CmpInst* C = dyn_cast(U))
1681 newVal = CmpInst::Create(C->getOpcode(), C->getPredicate(), s1, s2,
1681 newVal = CmpInst::Create(*Context, C->getOpcode(),
1682 C->getPredicate(), s1, s2,
16821683 C->getName()+".gvnpre",
16831684 (*PI)->getTerminator());
16841685 else if (ShuffleVectorInst* S = dyn_cast(U))
187187 << (Opcode == ICmpInst::ICMP_NE ? "!=" : "==") << "\n"
188188 << " RHS:\t" << *RHS << "\n";
189189
190 ICmpInst *Cond = new ICmpInst(Opcode, CmpIndVar, ExitCnt, "exitcond", BI);
190 ICmpInst *Cond = new ICmpInst(BI, Opcode, CmpIndVar, ExitCnt, "exitcond");
191191
192192 Instruction *OrigCond = cast(BI->getCondition());
193193 // It's tempting to use replaceAllUsesWith here to fully replace the old
293293 if (ExitBlocks.size() != 1) {
294294 // Clone the PHI and delete the original one. This lets IVUsers and
295295 // any other maps purge the original user from their records.
296 PHINode *NewPN = PN->clone();
296 PHINode *NewPN = PN->clone(*Context);
297297 NewPN->takeName(PN);
298298 NewPN->insertBefore(PN);
299299 PN->replaceAllUsesWith(NewPN);
725725 ConstantInt *NewEV = Context->getConstantInt(Type::Int32Ty, intEV);
726726 Value *LHS = (EVIndex == 1 ? NewPHI->getIncomingValue(1) : NewEV);
727727 Value *RHS = (EVIndex == 1 ? NewEV : NewPHI->getIncomingValue(1));
728 ICmpInst *NewEC = new ICmpInst(NewPred, LHS, RHS, EC->getNameStart(),
729 EC->getParent()->getTerminator());
728 ICmpInst *NewEC = new ICmpInst(EC->getParent()->getTerminator(),
729 NewPred, LHS, RHS, EC->getNameStart());
730730
731731 // In the following deltions, PH may become dead and may be deleted.
732732 // Use a WeakVH to observe whether this happens.
19231923 if (BinaryOperator *BO = dyn_cast(&I))
19241924 New = BinaryOperator::Create(BO->getOpcode(), Op0, Op1,SO->getName()+".op");
19251925 else if (CmpInst *CI = dyn_cast(&I))
1926 New = CmpInst::Create(CI->getOpcode(), CI->getPredicate(), Op0, Op1,
1927 SO->getName()+".cmp");
1926 New = CmpInst::Create(*Context, CI->getOpcode(), CI->getPredicate(),
1927 Op0, Op1, SO->getName()+".cmp");
19281928 else {
19291929 assert(0 && "Unknown binary instruction type!");
19301930 abort();
20132013 PN->getIncomingValue(i), C, "phitmp",
20142014 NonConstBB->getTerminator());
20152015 else if (CmpInst *CI = dyn_cast(&I))
2016 InV = CmpInst::Create(CI->getOpcode(),
2016 InV = CmpInst::Create(*Context, CI->getOpcode(),
20172017 CI->getPredicate(),
20182018 PN->getIncomingValue(i), C, "phitmp",
20192019 NonConstBB->getTerminator());
30413041
30423042 // X udiv C, where C >= signbit
30433043 if (C->getValue().isNegative()) {
3044 Value *IC = InsertNewInstBefore(new ICmpInst(ICmpInst::ICMP_ULT, Op0, C),
3044 Value *IC = InsertNewInstBefore(new ICmpInst(*Context,
3045 ICmpInst::ICMP_ULT, Op0, C),
30453046 I);
30463047 return SelectInst::Create(IC, Context->getNullValue(I.getType()),
30473048 Context->getConstantInt(I.getType(), 1));
33943395 case 0: return Context->getConstantIntFalse();
33953396 case 1:
33963397 if (sign)
3397 return new ICmpInst(ICmpInst::ICMP_SGT, LHS, RHS);
3398 return new ICmpInst(*Context, ICmpInst::ICMP_SGT, LHS, RHS);
33983399 else
3399 return new ICmpInst(ICmpInst::ICMP_UGT, LHS, RHS);
3400 case 2: return new ICmpInst(ICmpInst::ICMP_EQ, LHS, RHS);
3400 return new ICmpInst(*Context, ICmpInst::ICMP_UGT, LHS, RHS);
3401 case 2: return new ICmpInst(*Context, ICmpInst::ICMP_EQ, LHS, RHS);
34013402 case 3:
34023403 if (sign)
3403 return new ICmpInst(ICmpInst::ICMP_SGE, LHS, RHS);
3404 return new ICmpInst(*Context, ICmpInst::ICMP_SGE, LHS, RHS);
34043405 else
3405 return new ICmpInst(ICmpInst::ICMP_UGE, LHS, RHS);
3406 return new ICmpInst(*Context, ICmpInst::ICMP_UGE, LHS, RHS);
34063407 case 4:
34073408 if (sign)
3408 return new ICmpInst(ICmpInst::ICMP_SLT, LHS, RHS);
3409 return new ICmpInst(*Context, ICmpInst::ICMP_SLT, LHS, RHS);
34093410 else
3410 return new ICmpInst(ICmpInst::ICMP_ULT, LHS, RHS);
3411 case 5: return new ICmpInst(ICmpInst::ICMP_NE, LHS, RHS);
3411 return new ICmpInst(*Context, ICmpInst::ICMP_ULT, LHS, RHS);
3412 case 5: return new ICmpInst(*Context, ICmpInst::ICMP_NE, LHS, RHS);
34123413 case 6:
34133414 if (sign)
3414 return new ICmpInst(ICmpInst::ICMP_SLE, LHS, RHS);
3415 return new ICmpInst(*Context, ICmpInst::ICMP_SLE, LHS, RHS);
34153416 else
3416 return new ICmpInst(ICmpInst::ICMP_ULE, LHS, RHS);
3417 return new ICmpInst(*Context, ICmpInst::ICMP_ULE, LHS, RHS);
34173418 case 7: return Context->getConstantIntTrue();
34183419 }
34193420 }
34273428 default: assert(0 && "Illegal FCmp code!");
34283429 case 0:
34293430 if (isordered)
3430 return new FCmpInst(FCmpInst::FCMP_ORD, LHS, RHS);
3431 return new FCmpInst(*Context, FCmpInst::FCMP_ORD, LHS, RHS);
34313432 else
3432 return new FCmpInst(FCmpInst::FCMP_UNO, LHS, RHS);
3433 return new FCmpInst(*Context, FCmpInst::FCMP_UNO, LHS, RHS);
34333434 case 1:
34343435 if (isordered)
3435 return new FCmpInst(FCmpInst::FCMP_OGT, LHS, RHS);
3436 return new FCmpInst(*Context, FCmpInst::FCMP_OGT, LHS, RHS);
34363437 else
3437 return new FCmpInst(FCmpInst::FCMP_UGT, LHS, RHS);
3438 return new FCmpInst(*Context, FCmpInst::FCMP_UGT, LHS, RHS);
34383439 case 2:
34393440 if (isordered)
3440 return new FCmpInst(FCmpInst::FCMP_OEQ, LHS, RHS);
3441 return new FCmpInst(*Context, FCmpInst::FCMP_OEQ, LHS, RHS);
34413442 else
3442 return new FCmpInst(FCmpInst::FCMP_UEQ, LHS, RHS);
3443 return new FCmpInst(*Context, FCmpInst::FCMP_UEQ, LHS, RHS);
34433444 case 3:
34443445 if (isordered)
3445 return new FCmpInst(FCmpInst::FCMP_OGE, LHS, RHS);
3446 return new FCmpInst(*Context, FCmpInst::FCMP_OGE, LHS, RHS);
34463447 else
3447 return new FCmpInst(FCmpInst::FCMP_UGE, LHS, RHS);
3448 return new FCmpInst(*Context, FCmpInst::FCMP_UGE, LHS, RHS);
34483449 case 4:
34493450 if (isordered)
3450 return new FCmpInst(FCmpInst::FCMP_OLT, LHS, RHS);
3451 return new FCmpInst(*Context, FCmpInst::FCMP_OLT, LHS, RHS);
34513452 else
3452 return new FCmpInst(FCmpInst::FCMP_ULT, LHS, RHS);
3453 return new FCmpInst(*Context, FCmpInst::FCMP_ULT, LHS, RHS);
34533454 case 5:
34543455 if (isordered)
3455 return new FCmpInst(FCmpInst::FCMP_ONE, LHS, RHS);
3456 return new FCmpInst(*Context, FCmpInst::FCMP_ONE, LHS, RHS);
34563457 else
3457 return new FCmpInst(FCmpInst::FCMP_UNE, LHS, RHS);
3458 return new FCmpInst(*Context, FCmpInst::FCMP_UNE, LHS, RHS);
34583459 case 6:
34593460 if (isordered)
3460 return new FCmpInst(FCmpInst::FCMP_OLE, LHS, RHS);
3461 return new FCmpInst(*Context, FCmpInst::FCMP_OLE, LHS, RHS);
34613462 else
3462 return new FCmpInst(FCmpInst::FCMP_ULE, LHS, RHS);
3463 return new FCmpInst(*Context, FCmpInst::FCMP_ULE, LHS, RHS);
34633464 case 7: return Context->getConstantIntTrue();
34643465 }
34653466 }
36643665
36653666 if (Inside) {
36663667 if (Lo == Hi) // Trivially false.
3667 return new ICmpInst(ICmpInst::ICMP_NE, V, V);
3668 return new ICmpInst(*Context, ICmpInst::ICMP_NE, V, V);
36683669
36693670 // V >= Min && V < Hi --> V < Hi
36703671 if (cast(Lo)->isMinValue(isSigned)) {
36713672 ICmpInst::Predicate pred = (isSigned ?
36723673 ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT);
3673 return new ICmpInst(pred, V, Hi);
3674 return new ICmpInst(*Context, pred, V, Hi);
36743675 }
36753676
36763677 // Emit V-Lo
36783679 Instruction *Add = BinaryOperator::CreateAdd(V, NegLo, V->getName()+".off");
36793680 InsertNewInstBefore(Add, IB);
36803681 Constant *UpperBound = Context->getConstantExprAdd(NegLo, Hi);
3681 return new ICmpInst(ICmpInst::ICMP_ULT, Add, UpperBound);
3682 return new ICmpInst(*Context, ICmpInst::ICMP_ULT, Add, UpperBound);
36823683 }
36833684
36843685 if (Lo == Hi) // Trivially true.
3685 return new ICmpInst(ICmpInst::ICMP_EQ, V, V);
3686 return new ICmpInst(*Context, ICmpInst::ICMP_EQ, V, V);
36863687
36873688 // V < Min || V >= Hi -> V > Hi-1
36883689 Hi = SubOne(cast(Hi), Context);
36893690 if (cast(Lo)->isMinValue(isSigned)) {
36903691 ICmpInst::Predicate pred = (isSigned ?
36913692 ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT);
3692 return new ICmpInst(pred, V, Hi);
3693 return new ICmpInst(*Context, pred, V, Hi);
36933694 }
36943695
36953696 // Emit V-Lo >u Hi-1-Lo
36983699 Instruction *Add = BinaryOperator::CreateAdd(V, NegLo, V->getName()+".off");
36993700 InsertNewInstBefore(Add, IB);
37003701 Constant *LowerBound = Context->getConstantExprAdd(NegLo, Hi);
3701 return new ICmpInst(ICmpInst::ICMP_UGT, Add, LowerBound);
3702 return new ICmpInst(*Context, ICmpInst::ICMP_UGT, Add, LowerBound);
37023703 }
37033704
37043705 // isRunOfOnes - Returns true iff Val consists of one contiguous run of 1s with
37943795 LHSCst->getValue().isPowerOf2()) {
37953796 Instruction *NewOr = BinaryOperator::CreateOr(Val, Val2);
37963797 InsertNewInstBefore(NewOr, I);
3797 return new ICmpInst(LHSCC, NewOr, LHSCst);
3798 return new ICmpInst(*Context, LHSCC, NewOr, LHSCst);
37983799 }
37993800
38003801 // From here on, we only handle:
38543855 default: assert(0 && "Unknown integer condition code!");
38553856 case ICmpInst::ICMP_ULT:
38563857 if (LHSCst == SubOne(RHSCst, Context)) // (X != 13 & X u< 14) -> X < 13
3857 return new ICmpInst(ICmpInst::ICMP_ULT, Val, LHSCst);
3858 return new ICmpInst(*Context, ICmpInst::ICMP_ULT, Val, LHSCst);
38583859 break; // (X != 13 & X u< 15) -> no change
38593860 case ICmpInst::ICMP_SLT:
38603861 if (LHSCst == SubOne(RHSCst, Context)) // (X != 13 & X s< 14) -> X < 13
3861 return new ICmpInst(ICmpInst::ICMP_SLT, Val, LHSCst);
3862 return new ICmpInst(*Context, ICmpInst::ICMP_SLT, Val, LHSCst);
38623863 break; // (X != 13 & X s< 15) -> no change
38633864 case ICmpInst::ICMP_EQ: // (X != 13 & X == 15) -> X == 15
38643865 case ICmpInst::ICMP_UGT: // (X != 13 & X u> 15) -> X u> 15
38703871 Instruction *Add = BinaryOperator::CreateAdd(Val, AddCST,
38713872 Val->getName()+".off");
38723873 InsertNewInstBefore(Add, I);
3873 return new ICmpInst(ICmpInst::ICMP_UGT, Add,
3874 return new ICmpInst(*Context, ICmpInst::ICMP_UGT, Add,
38743875 Context->getConstantInt(Add->getType(), 1));
38753876 }
38763877 break; // (X != 13 & X != 15) -> no change
39163917 break;
39173918 case ICmpInst::ICMP_NE:
39183919 if (RHSCst == AddOne(LHSCst, Context)) // (X u> 13 & X != 14) -> X u> 14
3919 return new ICmpInst(LHSCC, Val, RHSCst);
3920 return new ICmpInst(*Context, LHSCC, Val, RHSCst);
39203921 break; // (X u> 13 & X != 15) -> no change
39213922 case ICmpInst::ICMP_ULT: // (X u> 13 & X u< 15) -> (X-14)
39223923 return InsertRangeTest(Val, AddOne(LHSCst, Context),
39353936 break;
39363937 case ICmpInst::ICMP_NE:
39373938 if (RHSCst == AddOne(LHSCst, Context)) // (X s> 13 & X != 14) -> X s> 14
3938 return new ICmpInst(LHSCC, Val, RHSCst);
3939 return new ICmpInst(*Context, LHSCC, Val, RHSCst);
39393940 break; // (X s> 13 & X != 15) -> no change
39403941 case ICmpInst::ICMP_SLT: // (X s> 13 & X s< 15) -> (X-14) s< 1
39413942 return InsertRangeTest(Val, AddOne(LHSCst, Context),
40474048 // (1 << x) & 1 --> zext(x == 0)
40484049 // (1 >> x) & 1 --> zext(x == 0)
40494050 if (AndRHSMask == 1 && Op0LHS == AndRHS) {
4050 Instruction *NewICmp = new ICmpInst(ICmpInst::ICMP_EQ, Op0RHS,
4051 Context->getNullValue(I.getType()));
4051 Instruction *NewICmp = new ICmpInst(*Context, ICmpInst::ICMP_EQ,
4052 Op0RHS, Context->getNullValue(I.getType()));
40524053 InsertNewInstBefore(NewICmp, I);
40534054 return new ZExtInst(NewICmp, I.getType());
40544055 }
42304231 // false.
42314232 if (LHSC->getValueAPF().isNaN() || RHSC->getValueAPF().isNaN())
42324233 return ReplaceInstUsesWith(I, Context->getConstantIntFalse());
4233 return new FCmpInst(FCmpInst::FCMP_ORD, LHS->getOperand(0),
4234 RHS->getOperand(0));
4234 return new FCmpInst(*Context, FCmpInst::FCMP_ORD,
4235 LHS->getOperand(0), RHS->getOperand(0));
42354236 }
42364237 } else {
42374238 Value *Op0LHS, *Op0RHS, *Op1LHS, *Op1RHS;
42464247 if (Op0LHS == Op1LHS && Op0RHS == Op1RHS) {
42474248 // Simplify (fcmp cc0 x, y) & (fcmp cc1 x, y).
42484249 if (Op0CC == Op1CC)
4249 return new FCmpInst((FCmpInst::Predicate)Op0CC, Op0LHS, Op0RHS);
4250 return new FCmpInst(*Context, (FCmpInst::Predicate)Op0CC,
4251 Op0LHS, Op0RHS);
42504252 else if (Op0CC == FCmpInst::FCMP_FALSE ||
42514253 Op1CC == FCmpInst::FCMP_FALSE)
42524254 return ReplaceInstUsesWith(I, Context->getConstantIntFalse());
45314533 Val->getName()+".off");
45324534 InsertNewInstBefore(Add, I);
45334535 AddCST = Context->getConstantExprSub(AddOne(RHSCst, Context), LHSCst);
4534 return new ICmpInst(ICmpInst::ICMP_ULT, Add, AddCST);
4536 return new ICmpInst(*Context, ICmpInst::ICMP_ULT, Add, AddCST);
45354537 }
45364538 break; // (X == 13 | X == 15) -> no change
45374539 case ICmpInst::ICMP_UGT: // (X == 13 | X u> 14) -> no change
49314933
49324934 // Otherwise, no need to compare the two constants, compare the
49334935 // rest.
4934 return new FCmpInst(FCmpInst::FCMP_UNO, LHS->getOperand(0),
4935 RHS->getOperand(0));
4936 return new FCmpInst(*Context, FCmpInst::FCMP_UNO,
4937 LHS->getOperand(0), RHS->getOperand(0));
49364938 }
49374939 } else {
49384940 Value *Op0LHS, *Op0RHS, *Op1LHS, *Op1RHS;
49474949 if (Op0LHS == Op1LHS && Op0RHS == Op1RHS) {
49484950 // Simplify (fcmp cc0 x, y) | (fcmp cc1 x, y).
49494951 if (Op0CC == Op1CC)
4950 return new FCmpInst((FCmpInst::Predicate)Op0CC, Op0LHS, Op0RHS);
4952 return new FCmpInst(*Context, (FCmpInst::Predicate)Op0CC,
4953 Op0LHS, Op0RHS);
49514954 else if (Op0CC == FCmpInst::FCMP_TRUE ||
49524955 Op1CC == FCmpInst::FCMP_TRUE)
49534956 return ReplaceInstUsesWith(I, Context->getConstantIntTrue());
50455048 if (RHS == Context->getConstantIntTrue() && Op0->hasOneUse()) {
50465049 // xor (cmp A, B), true = not (cmp A, B) = !cmp A, B
50475050 if (ICmpInst *ICI = dyn_cast(Op0))
5048 return new ICmpInst(ICI->getInversePredicate(),
5051 return new ICmpInst(*Context, ICI->getInversePredicate(),
50495052 ICI->getOperand(0), ICI->getOperand(1));
50505053
50515054 if (FCmpInst *FCI = dyn_cast(Op0))
5052 return new FCmpInst(FCI->getInversePredicate(),
5055 return new FCmpInst(*Context, FCI->getInversePredicate(),
50535056 FCI->getOperand(0), FCI->getOperand(1));
50545057 }
50555058
50635066 Context->getConstantIntTrue(),
50645067 Op0C->getDestTy())) {
50655068 Instruction *NewCI = InsertNewInstBefore(CmpInst::Create(
5069 *Context,
50665070 CI->getOpcode(), CI->getInversePredicate(),
50675071 CI->getOperand(0), CI->getOperand(1)), I);
50685072 NewCI->takeName(CI);
55535557 // If not, synthesize the offset the hard way.
55545558 if (Offset == 0)
55555559 Offset = EmitGEPOffset(GEPLHS, I, *this);
5556 return new ICmpInst(ICmpInst::getSignedPredicate(Cond), Offset,
5560 return new ICmpInst(*Context, ICmpInst::getSignedPredicate(Cond), Offset,
55575561 Context->getNullValue(Offset->getType()));
55585562 } else if (User *GEPRHS = dyn_castGetElementPtr(RHS)) {
55595563 // If the base pointers are different, but the indices are the same, just
55715575
55725576 // If all indices are the same, just compare the base pointers.
55735577 if (IndicesTheSame)
5574 return new ICmpInst(ICmpInst::getSignedPredicate(Cond),
5578 return new ICmpInst(*Context, ICmpInst::getSignedPredicate(Cond),
55755579 GEPLHS->getOperand(0), GEPRHS->getOperand(0));
55765580
55775581 // Otherwise, the base pointers are different and the indices are
56285632 Value *LHSV = GEPLHS->getOperand(DiffOperand);
56295633 Value *RHSV = GEPRHS->getOperand(DiffOperand);
56305634 // Make sure we do a signed comparison here.
5631 return new ICmpInst(ICmpInst::getSignedPredicate(Cond), LHSV, RHSV);
5635 return new ICmpInst(*Context,
5636 ICmpInst::getSignedPredicate(Cond), LHSV, RHSV);
56325637 }
56335638 }
56345639
56395644 // ((gep Ptr, OFFSET1) cmp (gep Ptr, OFFSET2) ---> (OFFSET1 cmp OFFSET2)
56405645 Value *L = EmitGEPOffset(GEPLHS, I, *this);
56415646 Value *R = EmitGEPOffset(GEPRHS, I, *this);
5642 return new ICmpInst(ICmpInst::getSignedPredicate(Cond), L, R);
5647 return new ICmpInst(*Context, ICmpInst::getSignedPredicate(Cond), L, R);
56435648 }
56445649 }
56455650 return 0;
58345839
58355840 // Lower this FP comparison into an appropriate integer version of the
58365841 // comparison.
5837 return new ICmpInst(Pred, LHSI->getOperand(0), RHSInt);
5842 return new ICmpInst(*Context, Pred, LHSI->getOperand(0), RHSInt);
58385843 }
58395844
58405845 Instruction *InstCombiner::visitFCmpInst(FCmpInst &I) {
59225927 // Fold the known value into the constant operand.
59235928 Op1 = Context->getConstantExprCompare(I.getPredicate(), C, RHSC);
59245929 // Insert a new FCmp of the other select operand.
5925 Op2 = InsertNewInstBefore(new FCmpInst(I.getPredicate(),
5930 Op2 = InsertNewInstBefore(new FCmpInst(*Context, I.getPredicate(),
59265931 LHSI->getOperand(2), RHSC,
59275932 I.getName()), I);
59285933 } else if (Constant *C = dyn_cast(LHSI->getOperand(2))) {
59295934 // Fold the known value into the constant operand.
59305935 Op2 = Context->getConstantExprCompare(I.getPredicate(), C, RHSC);
59315936 // Insert a new FCmp of the other select operand.
5932 Op1 = InsertNewInstBefore(new FCmpInst(I.getPredicate(),
5937 Op1 = InsertNewInstBefore(new FCmpInst(*Context, I.getPredicate(),
59335938 LHSI->getOperand(1), RHSC,
59345939 I.getName()), I);
59355940 }
60296034 if (I.isEquality() && CI->isNullValue() &&
60306035 match(Op0, m_Sub(m_Value(A), m_Value(B)))) {
60316036 // (icmp cond A B) if cond is equality
6032 return new ICmpInst(I.getPredicate(), A, B);
6037 return new ICmpInst(*Context, I.getPredicate(), A, B);
60336038 }
60346039
60356040 // If we have an icmp le or icmp ge instruction, turn it into the
60406045 case ICmpInst::ICMP_ULE:
60416046 if (CI->isMaxValue(false)) // A <=u MAX -> TRUE
60426047 return ReplaceInstUsesWith(I, Context->getConstantIntTrue());
6043 return new ICmpInst(ICmpInst::ICMP_ULT, Op0, AddOne(CI, Context));
6048 return new ICmpInst(*Context, ICmpInst::ICMP_ULT, Op0,
6049 AddOne(CI, Context));
60446050 case ICmpInst::ICMP_SLE:
60456051 if (CI->isMaxValue(true)) // A <=s MAX -> TRUE
60466052 return ReplaceInstUsesWith(I, Context->getConstantIntTrue());
6047 return new ICmpInst(ICmpInst::ICMP_SLT, Op0, AddOne(CI, Context));
6053 return new ICmpInst(*Context, ICmpInst::ICMP_SLT, Op0,
6054 AddOne(CI, Context));
60486055 case ICmpInst::ICMP_UGE:
60496056 if (CI->isMinValue(false)) // A >=u MIN -> TRUE
60506057 return ReplaceInstUsesWith(I, Context->getConstantIntTrue());
6051 return new ICmpInst( ICmpInst::ICMP_UGT, Op0, SubOne(CI, Context));
6058 return new ICmpInst(*Context, ICmpInst::ICMP_UGT, Op0,
6059 SubOne(CI, Context));
60526060 case ICmpInst::ICMP_SGE:
60536061 if (CI->isMinValue(true)) // A >=s MIN -> TRUE
60546062 return ReplaceInstUsesWith(I, Context->getConstantIntTrue());
6055 return new ICmpInst(ICmpInst::ICMP_SGT, Op0, SubOne(CI, Context));
6063 return new ICmpInst(*Context, ICmpInst::ICMP_SGT, Op0,
6064 SubOne(CI, Context));
60566065 }
60576066
60586067 // If this comparison is a normal comparison, it demands all
60986107 // figured out that the LHS is a constant. Just constant fold this now so
60996108 // that code below can assume that Min != Max.
61006109 if (!isa(Op0) && Op0Min == Op0Max)
6101 return new ICmpInst(I.getPredicate(),
6110 return new ICmpInst(*Context, I.getPredicate(),
61026111 Context->getConstantInt(Op0Min), Op1);
61036112 if (!isa(Op1) && Op1Min == Op1Max)
6104 return new ICmpInst(I.getPredicate(), Op0,
6113 return new ICmpInst(*Context, I.getPredicate(), Op0,
61056114 Context->getConstantInt(Op1Min));
61066115
61076116 // Based on the range information we know about the LHS, see if we can
61226131 if (Op0Min.uge(Op1Max)) // A false if min(A) >= max(B)
61236132 return ReplaceInstUsesWith(I, Context->getConstantIntFalse());
61246133 if (Op1Min == Op0Max) // A A != B if max(A) == min(B)
6125 return new ICmpInst(ICmpInst::ICMP_NE, Op0, Op1);
6134 return new ICmpInst(*Context, ICmpInst::ICMP_NE, Op0, Op1);
61266135 if (ConstantInt *CI = dyn_cast(Op1)) {
61276136 if (Op1Max == Op0Min+1) // A A == C-1 if min(A)+1 == C
6128 return new ICmpInst(ICmpInst::ICMP_EQ, Op0, SubOne(CI, Context));
6137 return new ICmpInst(*Context, ICmpInst::ICMP_EQ, Op0,
6138 SubOne(CI, Context));
61296139
61306140 // (x (x >s -1) -> true if sign bit clear
61316141 if (CI->isMinValue(true))
6132 return new ICmpInst(ICmpInst::ICMP_SGT, Op0,
6142 return new ICmpInst(*Context, ICmpInst::ICMP_SGT, Op0,
61336143 Context->getConstantIntAllOnesValue(Op0->getType()));
61346144 }
61356145 break;
61406150 return ReplaceInstUsesWith(I, Context->getConstantIntFalse());
61416151
61426152 if (Op1Max == Op0Min) // A >u B -> A != B if min(A) == max(B)
6143 return new ICmpInst(ICmpInst::ICMP_NE, Op0, Op1);
6153 return new ICmpInst(*Context, ICmpInst::ICMP_NE, Op0, Op1);
61446154 if (ConstantInt *CI = dyn_cast(Op1)) {
61456155 if (Op1Min == Op0Max-1) // A >u C -> A == C+1 if max(a)-1 == C
6146 return new ICmpInst(ICmpInst::ICMP_EQ, Op0, AddOne(CI, Context));
6156 return new ICmpInst(*Context, ICmpInst::ICMP_EQ, Op0,
6157 AddOne(CI, Context));
61476158
61486159 // (x >u 2147483647) -> (x true if sign bit set
61496160 if (CI->isMaxValue(true))
6150 return new ICmpInst(ICmpInst::ICMP_SLT, Op0,
6161 return new ICmpInst(*Context, ICmpInst::ICMP_SLT, Op0,
61516162 Context->getNullValue(Op0->getType()));
61526163 }
61536164 break;
61576168 if (Op0Min.sge(Op1Max)) // A false if min(A) >= max(C)
61586169 return ReplaceInstUsesWith(I, Context->getConstantIntFalse());
61596170 if (Op1Min == Op0Max) // A A != B if max(A) == min(B)
6160 return new ICmpInst(ICmpInst::ICMP_NE, Op0, Op1);
6171 return new ICmpInst(*Context, ICmpInst::ICMP_NE, Op0, Op1);
61616172 if (ConstantInt *CI = dyn_cast(Op1)) {
61626173 if (Op1Max == Op0Min+1) // A A == C-1 if min(A)+1 == C
6163 return new ICmpInst(ICmpInst::ICMP_EQ, Op0, SubOne(CI, Context));
6174 return new ICmpInst(*Context, ICmpInst::ICMP_EQ, Op0,
6175 SubOne(CI, Context));
61646176 }
61656177 break;
61666178 case ICmpInst::ICMP_SGT:
61706182 return ReplaceInstUsesWith(I, Context->getConstantIntFalse());
61716183
61726184 if (Op1Max == Op0Min) // A >s B -> A != B if min(A) == max(B)
6173 return new ICmpInst(ICmpInst::ICMP_NE, Op0, Op1);
6185 return new ICmpInst(*Context, ICmpInst::ICMP_NE, Op0, Op1);
61746186 if (ConstantInt *CI = dyn_cast(Op1)) {
61756187 if (Op1Min == Op0Max-1) // A >s C -> A == C+1 if max(A)-1 == C
6176 return new ICmpInst(ICmpInst::ICMP_EQ, Op0, AddOne(CI, Context));
6188 return new ICmpInst(*Context, ICmpInst::ICMP_EQ, Op0,
6189 AddOne(CI, Context));
61776190 }
61786191 break;
61796192 case ICmpInst::ICMP_SGE:
62116224 if (I.isSignedPredicate() &&
62126225 ((Op0KnownZero.isNegative() && Op1KnownZero.isNegative()) ||
62136226 (Op0KnownOne.isNegative() && Op1KnownOne.isNegative())))
6214 return new ICmpInst(I.getUnsignedPredicate(), Op0, Op1);
6227 return new ICmpInst(*Context, I.getUnsignedPredicate(), Op0, Op1);
62156228 }
62166229
62176230 // Test if the ICmpInst instruction is used exclusively by a select as
62536266 break;
62546267 }
62556268 if (isAllZeros)
6256 return new ICmpInst(I.getPredicate(), LHSI->getOperand(0),
6269 return new ICmpInst(*Context, I.getPredicate(), LHSI->getOperand(0),
62576270 Context->getNullValue(LHSI->getOperand(0)->getType()));
62586271 }
62596272 break;
62766289 // Fold the known value into the constant operand.
62776290 Op1 = Context->getConstantExprICmp(I.getPredicate(), C, RHSC);
62786291 // Insert a new ICmp of the other select operand.
6279 Op2 = InsertNewInstBefore(new ICmpInst(I.getPredicate(),
6292 Op2 = InsertNewInstBefore(new ICmpInst(*Context, I.getPredicate(),
62806293 LHSI->getOperand(2), RHSC,
62816294 I.getName()), I);
62826295 } else if (Constant *C = dyn_cast(LHSI->getOperand(2))) {
62836296 // Fold the known value into the constant operand.
62846297 Op2 = Context->getConstantExprICmp(I.getPredicate(), C, RHSC);
62856298 // Insert a new ICmp of the other select operand.
6286 Op1 = InsertNewInstBefore(new ICmpInst(I.getPredicate(),
6299 Op1 = InsertNewInstBefore(new ICmpInst(*Context, I.getPredicate(),
62876300 LHSI->getOperand(1), RHSC,
62886301 I.getName()), I);
62896302 }
63386351 Op1 = InsertBitCastBefore(Op1, Op0->getType(), I);
63396352 }
63406353 }
6341 return new ICmpInst(I.getPredicate(), Op0, Op1);
6354 return new ICmpInst(*Context, I.getPredicate(), Op0, Op1);
63426355 }
63436356 }
63446357
63656378 case Instruction::Sub:
63666379 case Instruction::Xor:
63676380 if (I.isEquality()) // a+x icmp eq/ne b+x --> a icmp b
6368 return new ICmpInst(I.getPredicate(), Op0I->getOperand(0),
6381 return new ICmpInst(*Context, I.getPredicate(), Op0I->getOperand(0),
63696382 Op1I->getOperand(0));
63706383 // icmp u/s (a ^ signbit), (b ^ signbit) --> icmp s/u a, b
63716384 if (ConstantInt *CI = dyn_cast(Op0I->getOperand(1))) {
63736386 ICmpInst::Predicate Pred = I.isSignedPredicate()
63746387 ? I.getUnsignedPredicate()
63756388 : I.getSignedPredicate();
6376 return new ICmpInst(Pred, Op0I->getOperand(0),
6389 return new ICmpInst(*Context, Pred, Op0I->getOperand(0),
63776390 Op1I->getOperand(0));
63786391 }
63796392
63826395 ? I.getUnsignedPredicate()
63836396 : I.getSignedPredicate();
63846397 Pred = I.getSwappedPredicate(Pred);
6385 return new ICmpInst(Pred, Op0I->getOperand(0),
6398 return new ICmpInst(*Context, Pred, Op0I->getOperand(0),
63866399 Op1I->getOperand(0));
63876400 }
63886401 }
64066419 Mask);
64076420 InsertNewInstBefore(And1, I);
64086421 InsertNewInstBefore(And2, I);
6409 return new ICmpInst(I.getPredicate(), And1, And2);
6422 return new ICmpInst(*Context, I.getPredicate(), And1, And2);
64106423 }
64116424 }
64126425 break;
64196432 { Value *A, *B;
64206433 if (match(Op0, m_Not(m_Value(A))) &&
64216434 match(Op1, m_Not(m_Value(B))))
6422 return new ICmpInst(I.getPredicate(), B, A);
6435 return new ICmpInst(*Context, I.getPredicate(), B, A);
64236436 }
64246437
64256438 if (I.isEquality()) {
64286441 // -x == -y --> x == y
64296442 if (match(Op0, m_Neg(m_Value(A))) &&
64306443 match(Op1, m_Neg(m_Value(B))))
6431 return new ICmpInst(I.getPredicate(), A, B);
6444 return new ICmpInst(*Context, I.getPredicate(), A, B);
64326445
64336446 if (match(Op0, m_Xor(m_Value(A), m_Value(B)))) {
64346447 if (A == Op1 || B == Op1) { // (A^B) == A -> B == 0
64356448 Value *OtherVal = A == Op1 ? B : A;
6436 return new ICmpInst(I.getPredicate(), OtherVal,
6449 return new ICmpInst(*Context, I.getPredicate(), OtherVal,
64376450 Context->getNullValue(A->getType()));
64386451 }
64396452
64456458 Constant *NC =
64466459 Context->getConstantInt(C1->getValue() ^ C2->getValue());
64476460 Instruction *Xor = BinaryOperator::CreateXor(C, NC, "tmp");
6448 return new ICmpInst(I.getPredicate(), A,
6461 return new ICmpInst(*Context, I.getPredicate(), A,
64496462 InsertNewInstBefore(Xor, I));
64506463 }
64516464
64526465 // A^B == A^D -> B == D
6453 if (A == C) return new ICmpInst(I.getPredicate(), B, D);
6454 if (A == D) return new ICmpInst(I.getPredicate(), B, C);
6455 if (B == C) return new ICmpInst(I.getPredicate(), A, D);
6456 if (B == D) return new ICmpInst(I.getPredicate(), A, C);
6466 if (A == C) return new ICmpInst(*Context, I.getPredicate(), B, D);
6467 if (A == D) return new ICmpInst(*Context, I.getPredicate(), B, C);
6468 if (B == C) return new ICmpInst(*Context, I.getPredicate(), A, D);
6469 if (B == D) return new ICmpInst(*Context, I.getPredicate(), A, C);
64576470 }
64586471 }
64596472
64616474 (A == Op0 || B == Op0)) {
64626475 // A == (A^B) -> B == 0
64636476 Value *OtherVal = A == Op0 ? B : A;
6464 return new ICmpInst(I.getPredicate(), OtherVal,
6477 return new ICmpInst(*Context, I.getPredicate(), OtherVal,
64656478 Context->getNullValue(A->getType()));
64666479 }
64676480
64686481 // (A-B) == A -> B == 0
64696482 if (match(Op0, m_Sub(m_Specific(Op1), m_Value(B))))
6470 return new ICmpInst(I.getPredicate(), B,
6483 return new ICmpInst(*Context, I.getPredicate(), B,
64716484 Context->getNullValue(B->getType()));
64726485
64736486 // A == (A-B) -> B == 0
64746487 if (match(Op1, m_Sub(m_Specific(Op0), m_Value(B))))
6475 return new ICmpInst(I.getPredicate(), B,
6488 return new ICmpInst(*Context, I.getPredicate(), B,
64766489 Context->getNullValue(B->getType()));
64776490
64786491 // (X&Z) == (Y&Z) -> (X^Y) & Z == 0
66176630 if (LoOverflow && HiOverflow)
66186631 return ReplaceInstUsesWith(ICI, Context->getConstantIntFalse());
66196632 else if (HiOverflow)
6620 return new ICmpInst(DivIsSigned ? ICmpInst::ICMP_SGE :
6633 return new ICmpInst(*Context, DivIsSigned ? ICmpInst::ICMP_SGE :
66216634 ICmpInst::ICMP_UGE, X, LoBound);
66226635 else if (LoOverflow)
6623 return new ICmpInst(DivIsSigned ? ICmpInst::ICMP_SLT :
6636 return new ICmpInst(*Context, DivIsSigned ? ICmpInst::ICMP_SLT :
66246637 ICmpInst::ICMP_ULT, X, HiBound);
66256638 else
66266639 return InsertRangeTest(X, LoBound, HiBound, DivIsSigned, true, ICI);
66286641 if (LoOverflow && HiOverflow)
66296642 return ReplaceInstUsesWith(ICI, Context->getConstantIntTrue());
66306643 else if (HiOverflow)
6631 return new ICmpInst(DivIsSigned ? ICmpInst::ICMP_SLT :
6644 return new ICmpInst(*Context, DivIsSigned ? ICmpInst::ICMP_SLT :
66326645 ICmpInst::ICMP_ULT, X, LoBound);
66336646 else if (LoOverflow)
6634 return new ICmpInst(DivIsSigned ? ICmpInst::ICMP_SGE :
6647 return new ICmpInst(*Context, DivIsSigned ? ICmpInst::ICMP_SGE :
66356648 ICmpInst::ICMP_UGE, X, HiBound);
66366649 else
66376650 return InsertRangeTest(X, LoBound, HiBound, DivIsSigned, false, ICI);
66416654 return ReplaceInstUsesWith(ICI, Context->getConstantIntTrue());
66426655 if (LoOverflow == -1) // Low bound is less than input range.
66436656 return ReplaceInstUsesWith(ICI, Context->getConstantIntFalse());
6644 return new ICmpInst(Pred, X, LoBound);
6657 return new ICmpInst(*Context, Pred, X, LoBound);
66456658 case ICmpInst::ICMP_UGT:
66466659 case ICmpInst::ICMP_SGT:
66476660 if (HiOverflow == +1) // High bound greater than input range.
66496662 else if (HiOverflow == -1) // High bound less than input range.
66506663 return ReplaceInstUsesWith(ICI, Context->getConstantIntTrue());
66516664 if (Pred == ICmpInst::ICMP_UGT)
6652 return new ICmpInst(ICmpInst::ICMP_UGE, X, HiBound);
6665 return new ICmpInst(*Context, ICmpInst::ICMP_UGE, X, HiBound);
66536666 else
6654 return new ICmpInst(ICmpInst::ICMP_SGE, X, HiBound);
6667 return new ICmpInst(*Context, ICmpInst::ICMP_SGE, X, HiBound);
66556668 }
66566669 }
66576670
66806693 APInt NewRHS(RHS->getValue());
66816694 NewRHS.zext(SrcBits);
66826695 NewRHS |= KnownOne;
6683 return new ICmpInst(ICI.getPredicate(), LHSI->getOperand(0),
6696 return new ICmpInst(*Context, ICI.getPredicate(), LHSI->getOperand(0),
66846697 Context->getConstantInt(NewRHS));
66856698 }
66866699 }
67096722 isTrueIfPositive ^= true;
67106723
67116724 if (isTrueIfPositive)
6712 return new ICmpInst(ICmpInst::ICMP_SGT, CompareVal,
6725 return new ICmpInst(*Context, ICmpInst::ICMP_SGT, CompareVal,
67136726 SubOne(RHS, Context));
67146727 else
6715 return new ICmpInst(ICmpInst::ICMP_SLT, CompareVal,
6728 return new ICmpInst(*Context, ICmpInst::ICMP_SLT, CompareVal,
67166729 AddOne(RHS, Context));
67176730 }
67186731
67236736 ICmpInst::Predicate Pred = ICI.isSignedPredicate()
67246737 ? ICI.getUnsignedPredicate()
67256738 : ICI.getSignedPredicate();
6726 return new ICmpInst(Pred, LHSI->getOperand(0),
6739 return new ICmpInst(*Context, Pred, LHSI->getOperand(0),
67276740 Context->getConstantInt(RHSV ^ SignBit));
67286741 }
67296742
67346747 ? ICI.getUnsignedPredicate()
67356748 : ICI.getSignedPredicate();
67366749 Pred = ICI.getSwappedPredicate(Pred);
6737 return new ICmpInst(Pred, LHSI->getOperand(0),
6750 return new ICmpInst(*Context, Pred, LHSI->getOperand(0),
67386751 Context->getConstantInt(RHSV ^ NotSignBit));
67396752 }
67406753 }
67666779 BinaryOperator::CreateAnd(Cast->getOperand(0),
67676780 Context->getConstantInt(NewCST),LHSI->getName());
67686781 InsertNewInstBefore(NewAnd, ICI);
6769 return new ICmpInst(ICI.getPredicate(), NewAnd,
6782 return new ICmpInst(*Context, ICI.getPredicate(), NewAnd,
67706783 Context->getConstantInt(NewCI));
67716784 }
67726785 }
68996912 BinaryOperator::CreateAnd(LHSI->getOperand(0),
69006913 Mask, LHSI->getName()+".mask");
69016914 Value *And = InsertNewInstBefore(AndI, ICI);
6902 return new ICmpInst(ICI.getPredicate(), And,
6915 return new ICmpInst(*Context, ICI.getPredicate(), And,
69036916 Context->getConstantInt(RHSV.lshr(ShAmtVal)));
69046917 }
69056918 }
69166929 Mask, LHSI->getName()+".mask");
69176930 Value *And = InsertNewInstBefore(AndI, ICI);
69186931
6919 return new ICmpInst(TrueIfSigned ? ICmpInst::ICMP_NE : ICmpInst::ICMP_EQ,
6932 return new ICmpInst(*Context,
6933 TrueIfSigned ? ICmpInst::ICMP_NE : ICmpInst::ICMP_EQ,
69206934 And, Context->getNullValue(And->getType()));
69216935 }
69226936 break;
69576971 if (LHSI->hasOneUse() &&
69586972 MaskedValueIsZero(LHSI->getOperand(0),
69596973 APInt::getLowBitsSet(Comp.getBitWidth(), ShAmtVal))) {
6960 return new ICmpInst(ICI.getPredicate(), LHSI->getOperand(0),
6974 return new ICmpInst(*Context, ICI.getPredicate(), LHSI->getOperand(0),
69616975 Context->getConstantExprShl(RHS, ShAmt));
69626976 }
69636977
69706984 BinaryOperator::CreateAnd(LHSI->getOperand(0),
69716985 Mask, LHSI->getName()+".mask");
69726986 Value *And = InsertNewInstBefore(AndI, ICI);
6973 return new ICmpInst(ICI.getPredicate(), And,
6987 return new ICmpInst(*Context, ICI.getPredicate(), And,
69746988 Context->getConstantExprShl(RHS, ShAmt));
69756989 }
69766990 break;
70037017
70047018 if (ICI.isSignedPredicate()) {
70057019 if (CR.getLower().isSignBit()) {
7006 return new ICmpInst(ICmpInst::ICMP_SLT, LHSI->getOperand(0),
7020 return new ICmpInst(*Context, ICmpInst::ICMP_SLT, LHSI->getOperand(0),
70077021 Context->getConstantInt(CR.getUpper()));
70087022 } else if (CR.getUpper().isSignBit()) {
7009 return new ICmpInst(ICmpInst::ICMP_SGE, LHSI->getOperand(0),
7023 return new ICmpInst(*Context, ICmpInst::ICMP_SGE, LHSI->getOperand(0),
70107024 Context->getConstantInt(CR.getLower()));
70117025 }
70127026 } else {
70137027 if (CR.getLower().isMinValue()) {
7014 return new ICmpInst(ICmpInst::ICMP_ULT, LHSI->getOperand(0),
7028 return new ICmpInst(*Context, ICmpInst::ICMP_ULT, LHSI->getOperand(0),
70157029 Context->getConstantInt(CR.getUpper()));
70167030 } else if (CR.getUpper().isMinValue()) {
7017 return new ICmpInst(ICmpInst::ICMP_UGE, LHSI->getOperand(0),
7031 return new ICmpInst(*Context, ICmpInst::ICMP_UGE, LHSI->getOperand(0),
70187032 Context->getConstantInt(CR.getLower()));
70197033 }
70207034 }
70397053 BinaryOperator::CreateURem(BO->getOperand(0), BO->getOperand(1),
70407054 BO->getName());
70417055 InsertNewInstBefore(NewRem, ICI);
7042 return new ICmpInst(ICI.getPredicate(), NewRem,
7056 return new ICmpInst(*Context, ICI.getPredicate(), NewRem,
70437057 Context->getNullValue(BO->getType()));
70447058 }
70457059 }
70487062 // Replace ((add A, B) != C) with (A != C-B) if B & C are constants.
70497063 if (ConstantInt *BOp1C = dyn_cast(BO->getOperand(1))) {
70507064 if (BO->hasOneUse())
7051 return new ICmpInst(ICI.getPredicate(), BO->getOperand(0),
7065 return new ICmpInst(*Context, ICI.getPredicate(), BO->getOperand(0),
70527066 Context->getConstantExprSub(RHS, BOp1C));
70537067 } else if (RHSV == 0) {
70547068 // Replace ((add A, B) != 0) with (A != -B) if A or B is
70567070 Value *BOp0 = BO->getOperand(0), *BOp1 = BO->getOperand(1);
70577071
70587072 if (Value *NegVal = dyn_castNegVal(BOp1, Context))
7059 return new ICmpInst(ICI.getPredicate(), BOp0, NegVal);
7073 return new ICmpInst(*Context, ICI.getPredicate(), BOp0, NegVal);
70607074 else if (Value *NegVal = dyn_castNegVal(BOp0, Context))
7061 return new ICmpInst(ICI.getPredicate(), NegVal, BOp1);
7075 return new ICmpInst(*Context, ICI.getPredicate(), NegVal, BOp1);
70627076 else if (BO->hasOneUse()) {
70637077 Instruction *Neg = BinaryOperator::CreateNeg(BOp1);
70647078 InsertNewInstBefore(Neg, ICI);
70657079 Neg->takeName(BO);
7066 return new ICmpInst(ICI.getPredicate(), BOp0, Neg);
7080 return new ICmpInst(*Context, ICI.getPredicate(), BOp0, Neg);
70677081 }
70687082 }
70697083 break;
70717085 // For the xor case, we can xor two constants together, eliminating
70727086 // the explicit xor.
70737087 if (Constant *BOC = dyn_cast(BO->getOperand(1)))
7074 return new ICmpInst(ICI.getPredicate(), BO->getOperand(0),
7088 return new ICmpInst(*Context, ICI.getPredicate(), BO->getOperand(0),
70757089 Context->getConstantExprXor(RHS, BOC));
70767090
70777091 // FALLTHROUGH
70787092 case Instruction::Sub:
70797093 // Replace (([sub|xor] A, B) != 0) with (A != B)
70807094 if (RHSV == 0)
7081 return new ICmpInst(ICI.getPredicate(), BO->getOperand(0),
7095 return new ICmpInst(*Context, ICI.getPredicate(), BO->getOperand(0),
70827096 BO->getOperand(1));
70837097 break;
70847098
71057119
71067120 // If we have ((X & C) == C), turn it into ((X & C) != 0).
71077121 if (RHS == BOC && RHSV.isPowerOf2())
7108 return new ICmpInst(isICMP_NE ? ICmpInst::ICMP_EQ :
7122 return new ICmpInst(*Context, isICMP_NE ? ICmpInst::ICMP_EQ :
71097123 ICmpInst::ICMP_NE, LHSI,
71107124 Context->getNullValue(RHS->getType()));
71117125
71157129 Constant *Zero = Context->getNullValue(X->getType());
71167130 ICmpInst::Predicate pred = isICMP_NE ?
71177131 ICmpInst::ICMP_SLT : ICmpInst::ICMP_SGE;
7118 return new ICmpInst(pred, X, Zero);
7132 return new ICmpInst(*Context, pred, X, Zero);
71197133 }
71207134
71217135 // ((X & ~7) == 0) --> X < 8
71247138 Constant *NegX = Context->getConstantExprNeg(BOC);
71257139 ICmpInst::Predicate pred = isICMP_NE ?
71267140 ICmpInst::ICMP_UGE : ICmpInst::ICMP_ULT;
7127 return new ICmpInst(pred, X, NegX);
7141 return new ICmpInst(*Context, pred, X, NegX);
71287142 }
71297143 }
71307144 default: break;
71687182 }
71697183
71707184 if (RHSOp)
7171 return new ICmpInst(ICI.getPredicate(), LHSCIOp, RHSOp);
7185 return new ICmpInst(*Context, ICI.getPredicate(), LHSCIOp, RHSOp);
71727186 }
71737187
71747188 // The code below only handles extension cast instructions, so far.
71937207
71947208 // Deal with equality cases early.
71957209 if (ICI.isEquality())
7196 return new ICmpInst(ICI.getPredicate(), LHSCIOp, RHSCIOp);
7210 return new ICmpInst(*Context, ICI.getPredicate(), LHSCIOp, RHSCIOp);
71977211
71987212 // A signed comparison of sign extended values simplifies into a
71997213 // signed comparison.
72007214 if (isSignedCmp && isSignedExt)
7201 return new ICmpInst(ICI.getPredicate(), LHSCIOp, RHSCIOp);
7215 return new ICmpInst(*Context, ICI.getPredicate(), LHSCIOp, RHSCIOp);
72027216
72037217 // The other three cases all fold into an unsigned comparison.
7204 return new ICmpInst(ICI.getUnsignedPredicate(), LHSCIOp, RHSCIOp);
7218 return new ICmpInst(*Context, ICI.getUnsignedPredicate(), LHSCIOp, RHSCIOp);
72057219 }
72067220
72077221 // If we aren't dealing with a constant on the RHS, exit early
72287242 // However, we allow this when the compare is EQ/NE, because they are
72297243 // signless.
72307244 if (isSignedExt == isSignedCmp || ICI.isEquality())
7231 return new ICmpInst(ICI.getPredicate(), LHSCIOp, Res1);
7245 return new ICmpInst(*Context, ICI.getPredicate(), LHSCIOp, Res1);
72327246 return 0;
72337247 }
72347248
72577271 // We're performing an unsigned comp with a sign extended value.
72587272 // This is true if the input is >= 0. [aka >s -1]
72597273 Constant *NegOne = Context->getConstantIntAllOnesValue(SrcTy);
7260 Result = InsertNewInstBefore(new ICmpInst(ICmpInst::ICMP_SGT, LHSCIOp,
7261 NegOne, ICI.getName()), ICI);
7274 Result = InsertNewInstBefore(new ICmpInst(*Context, ICmpInst::ICMP_SGT,
7275 LHSCIOp, NegOne, ICI.getName()), ICI);
72627276 } else {
72637277 // Unsigned extend & unsigned compare -> always true.
72647278 Result = Context->getConstantIntTrue();
84548468 Constant *One = Context->getConstantInt(Src->getType(), 1);
84558469 Src = InsertNewInstBefore(BinaryOperator::CreateAnd(Src, One, "tmp"), CI);
84568470 Value *Zero = Context->getNullValue(Src->getType());
8457 return new ICmpInst(ICmpInst::ICMP_NE, Src, Zero);
8471 return new ICmpInst(*Context, ICmpInst::ICMP_NE, Src, Zero);
84588472 }
84598473
84608474 // Optimize trunc(lshr(), c) to pull the shift through the truncate.
1059010604 if (BinaryOperator *BinOp = dyn_cast(FirstInst))
1059110605 return BinaryOperator::Create(BinOp->getOpcode(), LHSVal, RHSVal);
1059210606 CmpInst *CIOp = cast(FirstInst);
10593 return CmpInst::Create(CIOp->getOpcode(), CIOp->getPredicate(), LHSVal,
10594 RHSVal);
10607 return CmpInst::Create(*Context, CIOp->getOpcode(), CIOp->getPredicate(),
10608 LHSVal, RHSVal);
1059510609 }
1059610610
1059710611 Instruction *InstCombiner::FoldPHIArgGEPIntoPHI(PHINode &PN) {
1083710851 if (BinaryOperator *BinOp = dyn_cast(FirstInst))
1083810852 return BinaryOperator::Create(BinOp->getOpcode(), PhiVal, ConstantOp);
1083910853 if (CmpInst *CIOp = dyn_cast(FirstInst))
10840 return CmpInst::Create(CIOp->getOpcode(), CIOp->getPredicate(),
10854 return CmpInst::Create(*Context, CIOp->getOpcode(), CIOp->getPredicate(),
1084110855 PhiVal, ConstantOp);
1084210856 assert(isa(FirstInst) && "Unknown operation");
1084310857
1210312117 FPred == FCmpInst::FCMP_OGE) && BI.getCondition()->hasOneUse()) {
1210412118 FCmpInst *I = cast(BI.getCondition());
1210512119 FCmpInst::Predicate NewPred = FCmpInst::getInversePredicate(FPred);
12106 Instruction *NewSCC = new FCmpInst(NewPred, X, Y, "", I);
12120 Instruction *NewSCC = new FCmpInst(I, NewPred, X, Y, "");
1210712121 NewSCC->takeName(I);
1210812122 // Swap Destinations and condition...
1210912123 BI.setCondition(NewSCC);
1212412138 IPred == ICmpInst::ICMP_SGE) && BI.getCondition()->hasOneUse()) {
1212512139 ICmpInst *I = cast(BI.getCondition());
1212612140 ICmpInst::Predicate NewPred = ICmpInst::getInversePredicate(IPred);
12127 Instruction *NewSCC = new ICmpInst(NewPred, X, Y, "", I);
12141 Instruction *NewSCC = new ICmpInst(I, NewPred, X, Y, "");
1212812142 NewSCC->takeName(I);
1212912143 // Swap Destinations and condition...
1213012144 BI.setCondition(NewSCC);
930930 // Clone the non-phi instructions of BB into NewBB, keeping track of the
931931 // mapping and using it to remap operands in the cloned instructions.
932932 for (; !isa(BI); ++BI) {
933 Instruction *New = BI->clone();
933 Instruction *New = BI->clone(*Context);
934934 New->setName(BI->getNameStart());
935935 NewBB->getInstList().push_back(New);
936936 ValueMapping[BI] = New;
569569 ExitBlock->getInstList().insert(InsertPt, &I);
570570 New = &I;
571571 } else {
572 New = I.clone();
572 New = I.clone(*Context);
573573 CurAST->copyValue(&I, New);
574574 if (!I.getName().empty())
575575 New->setName(I.getName()+".le");
308308 // Return min(V1, V1)
309309 static Value *getMin(Value *V1, Value *V2, bool Sign, Instruction *InsertPt) {
310310
311 Value *C = new ICmpInst(Sign ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
312 V1, V2, "lsp", InsertPt);
311 Value *C = new ICmpInst(InsertPt,
312 Sign ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
313 V1, V2, "lsp");
313314 return SelectInst::Create(C, V1, V2, "lsp", InsertPt);
314315 }
315316
316317 // Return max(V1, V2)
317318 static Value *getMax(Value *V1, Value *V2, bool Sign, Instruction *InsertPt) {
318319
319 Value *C = new ICmpInst(Sign ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
320 V1, V2, "lsp", InsertPt);
320 Value *C = new ICmpInst(InsertPt,
321 Sign ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
322 V1, V2, "lsp");
321323 return SelectInst::Create(C, V2, V1, "lsp", InsertPt);
322324 }
323325
426428 // c1 = icmp uge i32 SplitValue, StartValue
427429 // c2 = icmp ult i32 SplitValue, ExitValue
428430 // and i32 c1, c2
429 Instruction *C1 = new ICmpInst(ExitCondition->isSignedPredicate() ?
431 Instruction *C1 = new ICmpInst(BR, ExitCondition->isSignedPredicate() ?
430432 ICmpInst::ICMP_SGE : ICmpInst::ICMP_UGE,
431 SplitValue, StartValue, "lisplit", BR);
433 SplitValue, StartValue, "lisplit");
432434
433435 CmpInst::Predicate C2P = ExitCondition->getPredicate();
434436 BranchInst *LatchBR = cast(Latch->getTerminator());
435437 if (LatchBR->getOperand(0) != Header)
436438 C2P = CmpInst::getInversePredicate(C2P);
437 Instruction *C2 = new ICmpInst(C2P, SplitValue, ExitValue, "lisplit", BR);
439 Instruction *C2 = new ICmpInst(BR, C2P, SplitValue, ExitValue, "lisplit");
438440 Instruction *NSplitCond = BinaryOperator::CreateAnd(C1, C2, "lisplit", BR);
439441
440442 SplitCondition->replaceAllUsesWith(NSplitCond);
237237 // This is not a PHI instruction. Insert its clone into original pre-header.
238238 // If this instruction is using a value from same basic block then
239239 // update it to use value from cloned instruction.
240 Instruction *C = In->clone();
240 Instruction *C = In->clone(*Context);
241241 C->setName(In->getName());
242242 OrigPreHeader->getInstList().push_back(C);
243243
20182018 // Create a new compare instruction using new stride / iv.
20192019 ICmpInst *OldCond = Cond;
20202020 // Insert new compare instruction.
2021 Cond = new ICmpInst(Predicate, NewCmpLHS, NewCmpRHS,
2022 L->getHeader()->getName() + ".termcond",
2023 OldCond);
2021 Cond = new ICmpInst(OldCond, Predicate, NewCmpLHS, NewCmpRHS,
2022 L->getHeader()->getName() + ".termcond");
20242023
20252024 // Remove the old compare instruction. The old indvar is probably dead too.
20262025 DeadInsts.push_back(CondUse->getOperandValToReplace());
21512150 // Ok, everything looks ok to change the condition into an SLT or SGE and
21522151 // delete the max calculation.
21532152 ICmpInst *NewCond =
2154 new ICmpInst(Pred, Cond->getOperand(0), NewRHS, "scmp", Cond);
2153 new ICmpInst(Cond, Pred, Cond->getOperand(0), NewRHS, "scmp");
21552154
21562155 // Delete the max calculation instructions.
21572156 Cond->replaceAllUsesWith(NewCond);
23822381 Cond->moveBefore(TermBr);
23832382 } else {
23842383 // Otherwise, clone the terminating condition and insert into the loopend.
2385 Cond = cast(Cond->clone());
2384 Cond = cast(Cond->clone(*Context));
23862385 Cond->setName(L->getHeader()->getName() + ".termcond");
23872386 LatchBlock->getInstList().insert(TermBr, Cond);
23882387
506506 // code is the true version and the new code is the false version.
507507 Value *BranchVal = LIC;
508508 if (!isa(Val) || Val->getType() != Type::Int1Ty)
509 BranchVal = new ICmpInst(ICmpInst::ICMP_EQ, LIC, Val, "tmp", InsertPt);
509 BranchVal = new ICmpInst(InsertPt, ICmpInst::ICMP_EQ, LIC, Val, "tmp");
510510 else if (Val != Context->getConstantIntTrue())
511511 // We want to enter the new loop when the condition is true.
512512 std::swap(TrueDest, FalseDest);
26922692 VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, &IC);
26932693 if (VRP.isRelatedBy(IC.getOperand(0), NextVal,
26942694 ICmpInst::getInversePredicate(Pred))) {
2695 ICmpInst *NewIC = new ICmpInst(ICmpInst::ICMP_EQ, IC.getOperand(0),
2696 NextVal, "", &IC);
2695 ICmpInst *NewIC = new ICmpInst(&IC, ICmpInst::ICMP_EQ,
2696 IC.getOperand(0), NextVal, "");
26972697 NewIC->takeName(&IC);
26982698 IC.replaceAllUsesWith(NewIC);
26992699
11921192 assert(NumElements == 2 && "Unhandled case!");
11931193 // All users of the GEP must be loads. At each use of the GEP, insert
11941194 // two loads of the appropriate indexed GEP and select between them.
1195 Value *IsOne = new ICmpInst(ICmpInst::ICMP_NE, I.getOperand(),
1195 Value *IsOne = new ICmpInst(GEPI, ICmpInst::ICMP_NE, I.getOperand(),
11961196 Context->getNullValue(I.getOperand()->getType()),
1197 "isone", GEPI);
1197 "isone");
11981198 // Insert the new GEP instructions, which are properly indexed.
11991199 SmallVector Indices(GEPI->op_begin()+1, GEPI->op_end());
12001200 Indices[1] = Context->getNullValue(Type::Int32Ty);
303303 // keeping track of the mapping...
304304 //
305305 for (; BI != DestBlock->end(); ++BI) {
306 Instruction *New = BI->clone();
306 Instruction *New = BI->clone(*Context);
307307 New->setName(BI->getName());
308308 SourceBlock->getInstList().push_back(New);
309309 ValueMapping[BI] = New;
617617 if (I != I->getParent()->begin()) {
618618 BasicBlock::iterator BBI = I; --BBI;
619619 if (DbgStopPointInst *DSPI = dyn_cast(BBI)) {
620 CallInst *newDSPI = DSPI->clone();
620 CallInst *newDSPI = DSPI->clone(*I->getParent()->getContext());
621621 newDSPI->insertBefore(InsertPos);
622622 }
623623 }
4242 // Loop over all instructions, and copy them over.
4343 for (BasicBlock::const_iterator II = BB->begin(), IE = BB->end();
4444 II != IE; ++II) {
45 Instruction *NewInst = II->clone();
45 Instruction *NewInst = II->clone(*BB->getContext());
4646 if (II->hasName())
4747 NewInst->setName(II->getName()+NameSuffix);
4848 NewBB->getInstList().push_back(NewInst);
248248 continue;
249249 }
250250
251 Instruction *NewInst = II->clone();
251 Instruction *NewInst = II->clone(*BB->getContext());
252252 if (II->hasName())
253253 NewInst->setName(II->getName()+NameSuffix);
254254 NewBB->getInstList().push_back(NewInst);
296296 }
297297
298298 if (!TerminatorDone) {
299 Instruction *NewInst = OldTI->clone();
299 Instruction *NewInst = OldTI->clone(*BB->getContext());
300300 if (OldTI->hasName())
301301 NewInst->setName(OldTI->getName()+NameSuffix);
302302 NewBB->getInstList().push_back(NewInst);
360360 BE = TheCall->getParent()->end(); BI != BE; ++BI) {
361361 if (DbgStopPointInst *DSPI = dyn_cast(BI)) {
362362 if (DbgRegionEndInst *NewDREI =
363 dyn_cast(DREI->clone()))
363 dyn_cast(DREI->clone(*Context)))
364364 NewDREI->insertAfter(DSPI);
365365 break;
366366 }
183183 } else if (SI->getNumSuccessors() == 2) {
184184 // Otherwise, we can fold this switch into a conditional branch
185185 // instruction if it has only one non-default destination.
186 Value *Cond = new ICmpInst(ICmpInst::ICMP_EQ, SI->getCondition(),
187 SI->getSuccessorValue(1), "cond", SI);
186 Value *Cond = new ICmpInst(SI, ICmpInst::ICMP_EQ, SI->getCondition(),
187 SI->getSuccessorValue(1), "cond");
188188 // Insert the new branch...
189189 BranchInst::Create(SI->getSuccessor(1), SI->getSuccessor(0), Cond, SI);
190190
522522 EntryBB->getTerminator());
523523
524524 // Compare the return value to zero.
525 Value *IsNormal = new ICmpInst(ICmpInst::ICMP_EQ, SJRet,
525 Value *IsNormal = new ICmpInst(EntryBB->getTerminator(),
526 ICmpInst::ICMP_EQ, SJRet,
526527 Constant::getNullValue(SJRet->getType()),
527 "notunwind", EntryBB->getTerminator());
528 "notunwind");
528529 // Nuke the uncond branch.
529530 EntryBB->getTerminator()->eraseFromParent();
530531
556557 }
557558
558559 // Load the JBList, if it's null, then there was no catch!
559 Value *NotNull = new ICmpInst(ICmpInst::ICMP_NE, BufPtr,
560 Value *NotNull = new ICmpInst(*UnwindHandler, ICmpInst::ICMP_NE, BufPtr,
560561 Constant::getNullValue(BufPtr->getType()),
561 "notnull", UnwindHandler);
562 "notnull");
562563 BranchInst::Create(UnwindBlock, TermBlock, NotNull, UnwindHandler);
563564
564565 // Create the block to do the longjmp.
161161 Function::iterator FI = OrigBlock;
162162 F->getBasicBlockList().insert(++FI, NewNode);
163163
164 ICmpInst* Comp = new ICmpInst(ICmpInst::ICMP_SLT, Val, Pivot.Low, "Pivot");
164 ICmpInst* Comp = new ICmpInst(*Default->getContext(), ICmpInst::ICMP_SLT,
165 Val, Pivot.Low, "Pivot");
165166 NewNode->getInstList().push_back(Comp);
166167 BranchInst::Create(LBranch, RBranch, Comp, NewNode);
167168 return NewNode;
186187 ICmpInst* Comp = NULL;
187188 if (Leaf.Low == Leaf.High) {
188189 // Make the seteq instruction...
189 Comp = new ICmpInst(ICmpInst::ICMP_EQ, Val, Leaf.Low,
190 "SwitchLeaf", NewLeaf);
190 Comp = new ICmpInst(*NewLeaf, ICmpInst::ICMP_EQ, Val,
191 Leaf.Low, "SwitchLeaf");
191192 } else {
192193 // Make range comparison
193194 if (cast(Leaf.Low)->isMinValue(true /*isSigned*/)) {
194195 // Val >= Min && Val <= Hi --> Val <= Hi
195 Comp = new ICmpInst(ICmpInst::ICMP_SLE, Val, Leaf.High,
196 "SwitchLeaf", NewLeaf);
196 Comp = new ICmpInst(*NewLeaf, ICmpInst::ICMP_SLE, Val, Leaf.High,
197 "SwitchLeaf");
197198 } else if (cast(Leaf.Low)->isZero()) {
198199 // Val >= 0 && Val <= Hi --> Val <=u Hi
199 Comp = new ICmpInst(ICmpInst::ICMP_ULE, Val, Leaf.High,
200 "SwitchLeaf", NewLeaf);
200 Comp = new ICmpInst(*NewLeaf, ICmpInst::ICMP_ULE, Val, Leaf.High,
201 "SwitchLeaf");
201202 } else {
202203 // Emit V-Lo <=u Hi-Lo
203204 Constant* NegLo = Context->getConstantExprNeg(Leaf.Low);
205206 Val->getName()+".off",
206207 NewLeaf);
207208 Constant *UpperBound = Context->getConstantExprAdd(NegLo, Leaf.High);
208 Comp = new ICmpInst(ICmpInst::ICMP_ULE, Add, UpperBound,
209 "SwitchLeaf", NewLeaf);
209 Comp = new ICmpInst(*NewLeaf, ICmpInst::ICMP_ULE, Add, UpperBound,
210 "SwitchLeaf");
210211 }
211212 }
212213
937937 return true;
938938
939939 // Okay, it is safe to hoist the terminator.
940 Instruction *NT = I1->clone();
940 Instruction *NT = I1->clone(*BB1->getContext());
941941 BIParent->getInstList().insert(BI, NT);
942942 if (NT->getType() != Type::VoidTy) {
943943 I1->replaceAllUsesWith(NT);
12301230 TranslateMap[PN] = PN->getIncomingValueForBlock(PredBB);
12311231 } else {
12321232 // Clone the instruction.
1233 Instruction *N = BBI->clone();
1233 Instruction *N = BBI->clone(*Context);
12341234 if (BBI->hasName()) N->setName(BBI->getName()+".c");
12351235
12361236 // Update operands due to translation.
15801580
15811581 // Clone Cond into the predecessor basic block, and or/and the
15821582 // two conditions together.
1583 Instruction *New = Cond->clone();
1583 Instruction *New = Cond->clone(*BB->getContext());
15841584 PredBlock->getInstList().insert(PBI, New);
15851585 New->takeName(Cond);
15861586 Cond->setName(New->getName()+".old");
18401840 << "INTO UNCOND BRANCH PRED: " << *Pred;
18411841 Instruction *UncondBranch = Pred->getTerminator();
18421842 // Clone the return and add it to the end of the predecessor.
1843 Instruction *NewRet = RI->clone();
1843 Instruction *NewRet = RI->clone(*BB->getContext());
18441844 Pred->getInstList().push_back(NewRet);
18451845
18461846 BasicBlock::iterator BBI = RI;
25752575 }
25762576
25772577 CmpInst *
2578 CmpInst::Create(OtherOps Op, unsigned short predicate, Value *S1, Value *S2,
2578 CmpInst::Create(LLVMContext &Context, OtherOps Op, unsigned short predicate,
2579 Value *S1, Value *S2,
25792580 const std::string &Name, Instruction *InsertBefore) {
25802581 if (Op == Instruction::ICmp) {
2581 return new ICmpInst(CmpInst::Predicate(predicate), S1, S2, Name,
2582 InsertBefore);
2583 }
2584 return new FCmpInst(CmpInst::Predicate(predicate), S1, S2, Name,
2585 InsertBefore);
2582 if (InsertBefore)
2583 return new ICmpInst(InsertBefore, CmpInst::Predicate(predicate),
2584 S1, S2, Name);
2585 else
2586 return new ICmpInst(Context, CmpInst::Predicate(predicate),
2587 S1, S2, Name);
2588 }
2589
2590 if (InsertBefore)
2591 return new FCmpInst(InsertBefore, CmpInst::Predicate(predicate),
2592 S1, S2, Name);
2593 else
2594 return new FCmpInst(Context, CmpInst::Predicate(predicate),
2595 S1, S2, Name);
25862596 }
25872597
25882598 CmpInst *
25892599 CmpInst::Create(OtherOps Op, unsigned short predicate, Value *S1, Value *S2,
25902600 const std::string &Name, BasicBlock *InsertAtEnd) {
25912601 if (Op == Instruction::ICmp) {
2592 return new ICmpInst(CmpInst::Predicate(predicate), S1, S2, Name,
2593 InsertAtEnd);
2594 }
2595 return new FCmpInst(CmpInst::Predicate(predicate), S1, S2, Name,
2596 InsertAtEnd);
2602 return new ICmpInst(*InsertAtEnd, CmpInst::Predicate(predicate),
2603 S1, S2, Name);
2604 }
2605 return new FCmpInst(*InsertAtEnd, CmpInst::Predicate(predicate),
2606 S1, S2, Name);
25972607 }
25982608
25992609 void CmpInst::swapOperands() {
29182928 // Define these methods here so vtables don't get emitted into every translation
29192929 // unit that uses these classes.
29202930
2921 GetElementPtrInst *GetElementPtrInst::clone() const {
2931 GetElementPtrInst *GetElementPtrInst::clone(LLVMContext&) const {
29222932 return new(getNumOperands()) GetElementPtrInst(*this);
29232933 }
29242934
2925 BinaryOperator *BinaryOperator::clone() const {
2935 BinaryOperator *BinaryOperator::clone(LLVMContext&) const {
29262936 return Create(getOpcode(), Op<0>(), Op<1>());
29272937 }
29282938
2929 FCmpInst* FCmpInst::clone() const {
2930 return new FCmpInst(getPredicate(), Op<0>(), Op<1>());
2931 }
2932 ICmpInst* ICmpInst::clone() const {
2933 return new ICmpInst(getPredicate(), Op<0>(), Op<1>());
2934 }
2935
2936 ExtractValueInst *ExtractValueInst::clone() const {
2939 FCmpInst* FCmpInst::clone(LLVMContext &Context) const {
2940 return new FCmpInst(Context, getPredicate(), Op<0>(), Op<1>());
2941 }
2942 ICmpInst* ICmpInst::clone(LLVMContext &Context) const {
2943 return new ICmpInst(Context, getPredicate(), Op<0>(), Op<1>());
2944 }
2945
2946 ExtractValueInst *ExtractValueInst::clone(LLVMContext&) const {
29372947 return new ExtractValueInst(*this);
29382948 }
2939 InsertValueInst *InsertValueInst::clone() const {
2949 InsertValueInst *InsertValueInst::clone(LLVMContext&) const {
29402950 return new InsertValueInst(*this);
29412951 }
29422952
2943
2944 MallocInst *MallocInst::clone() const { return new MallocInst(*this); }
2945 AllocaInst *AllocaInst::clone() const { return new AllocaInst(*this); }
2946 FreeInst *FreeInst::clone() const { return new FreeInst(getOperand(0)); }
2947 LoadInst *LoadInst::clone() const { return new LoadInst(*this); }
2948 StoreInst *StoreInst::clone() const { return new StoreInst(*this); }
2949 CastInst *TruncInst::clone() const { return new TruncInst(*this); }
2950 CastInst *ZExtInst::clone() const { return new ZExtInst(*this); }
2951 CastInst *SExtInst::clone() const { return new SExtInst(*this); }
2952 CastInst *FPTruncInst::clone() const { return new FPTruncInst(*this); }
2953 CastInst *FPExtInst::clone() const { return new FPExtInst(*this); }
2954 CastInst *UIToFPInst::clone() const { return new UIToFPInst(*this); }
2955 CastInst *SIToFPInst::clone() const { return new SIToFPInst(*this); }
2956 CastInst *FPToUIInst::clone() const { return new FPToUIInst(*this); }
2957 CastInst *FPToSIInst::clone() const { return new FPToSIInst(*this); }
2958 CastInst *PtrToIntInst::clone() const { return new PtrToIntInst(*this); }
2959 CastInst *IntToPtrInst::clone() const { return new IntToPtrInst(*this); }
2960 CastInst *BitCastInst::clone() const { return new BitCastInst(*this); }
2961 CallInst *CallInst::clone() const {
2953 MallocInst *MallocInst::clone(LLVMContext&) const {
2954 return new MallocInst(*this);
2955 }
2956
2957 AllocaInst *AllocaInst::clone(LLVMContext&) const {
2958 return new AllocaInst(*this);
2959 }
2960
2961 FreeInst *FreeInst::clone(LLVMContext&) const {
2962 return new FreeInst(getOperand(0));
2963 }
2964
2965 LoadInst *LoadInst::clone(LLVMContext&) const {
2966 return new LoadInst(*this);
2967 }
2968
2969 StoreInst *StoreInst::clone(LLVMContext&) const {
2970 return new StoreInst(*this);
2971 }
2972
2973 CastInst *TruncInst::clone(LLVMContext&) const {
2974 return new TruncInst(*this);
2975 }
2976
2977 CastInst *ZExtInst::clone(LLVMContext&) const {
2978 return new ZExtInst(*this);
2979 }
2980
2981 CastInst *SExtInst::clone(LLVMContext&) const {
2982 return new SExtInst(*this);
2983 }
2984
2985 CastInst *FPTruncInst::clone(LLVMContext&) const {
2986 return new FPTruncInst(*this);
2987 }
2988
2989 CastInst *FPExtInst::clone(LLVMContext&) const {
2990 return new FPExtInst(*this);
2991 }
2992
2993 CastInst *UIToFPInst::clone(LLVMContext&) const {
2994 return new UIToFPInst(*this);
2995 }
2996
2997 CastInst *SIToFPInst::clone(LLVMContext&) const {
2998 return new SIToFPInst(*this);
2999 }
3000
3001 CastInst *FPToUIInst::clone(LLVMContext&) const {
3002 return new FPToUIInst(*this);
3003 }
3004
3005 CastInst *FPToSIInst::clone(LLVMContext&) const {
3006 return new FPToSIInst(*this);
3007 }
3008
3009 CastInst *PtrToIntInst::clone(LLVMContext&) const {
3010 return new PtrToIntInst(*this);
3011 }
3012
3013 CastInst *IntToPtrInst::clone(LLVMContext&) const {
3014 return new IntToPtrInst(*this);
3015 }
3016
3017 CastInst *BitCastInst::clone(LLVMContext&) const {
3018 return new BitCastInst(*this);
3019 }
3020
3021 CallInst *CallInst::clone(LLVMContext&) const {
29623022 return new(getNumOperands()) CallInst(*this);
29633023 }
2964 SelectInst *SelectInst::clone() const {
3024
3025 SelectInst *SelectInst::clone(LLVMContext&) const {
29653026 return new(getNumOperands()) SelectInst(*this);
29663027 }
2967 VAArgInst *VAArgInst::clone() const { return new VAArgInst(*this); }
2968
2969 ExtractElementInst *ExtractElementInst::clone() const {
3028
3029 VAArgInst *VAArgInst::clone(LLVMContext&) const {
3030 return new VAArgInst(*this);
3031 }
3032
3033 ExtractElementInst *ExtractElementInst::clone(LLVMContext&) const {
29703034 return new ExtractElementInst(*this);
29713035 }
2972 InsertElementInst *InsertElementInst::clone() const {
3036
3037 InsertElementInst *InsertElementInst::clone(LLVMContext&) const {
29733038 return InsertElementInst::Create(*this);
29743039 }
2975 ShuffleVectorInst *ShuffleVectorInst::clone() const {
3040
3041 ShuffleVectorInst *ShuffleVectorInst::clone(LLVMContext&) const {
29763042 return new ShuffleVectorInst(*this);
29773043 }
2978 PHINode *PHINode::clone() const { return new PHINode(*this); }
2979 ReturnInst *ReturnInst::clone() const {
3044
3045 PHINode *PHINode::clone(LLVMContext&) const {
3046 return new PHINode(*this);
3047 }
3048
3049 ReturnInst *ReturnInst::clone(LLVMContext&) const {
29803050 return new(getNumOperands()) ReturnInst(*this);
29813051 }
2982 BranchInst *BranchInst::clone() const {
3052
3053 BranchInst *BranchInst::clone(LLVMContext&) const {
29833054 unsigned Ops(getNumOperands());
29843055 return new(Ops, Ops == 1) BranchInst(*this);
29853056 }
2986 SwitchInst *SwitchInst::clone() const { return new SwitchInst(*this); }
2987 InvokeInst *InvokeInst::clone() const {
3057
3058 SwitchInst *SwitchInst::clone(LLVMContext&) const {
3059 return new SwitchInst(*this);
3060 }
3061
3062 InvokeInst *InvokeInst::clone(LLVMContext&) const {
29883063 return new(getNumOperands()) InvokeInst(*this);
29893064 }
2990 UnwindInst *UnwindInst::clone() const { return new UnwindInst(); }
2991 UnreachableInst *UnreachableInst::clone() const { return new UnreachableInst();}
3065
3066 UnwindInst *UnwindInst::clone(LLVMContext&) const {
3067 return new UnwindInst();
3068 }
3069
3070 UnreachableInst *UnreachableInst::clone(LLVMContext&) const {
3071 return new UnreachableInst();
3072 }
484484 VectorType* LLVMContext::getVectorTypeTruncatedElement(const VectorType* VTy) {
485485 return VectorType::getTruncatedElementVectorType(VTy);
486486 }
487
488 const Type* LLVMContext::makeCmpResultType(const Type* opnd_type) {
489 if (const VectorType* vt = dyn_cast(opnd_type)) {
490 return getVectorType(Type::Int1Ty, vt->getNumElements());
491 }
492 return Type::Int1Ty;
493 }
737737
738738 // Check to see if we already looked up the value.
739739 Value *CachedVal = new LoadInst(Cache, "fpcache", EntryBB);
740 Value *IsNull = new ICmpInst(ICmpInst::ICMP_EQ, CachedVal,
741 NullPtr, "isNull", EntryBB);
740 Value *IsNull = new ICmpInst(*EntryBB, ICmpInst::ICMP_EQ, CachedVal,
741 NullPtr, "isNull");
742742 BranchInst::Create(LookupBB, DoCallBB, IsNull, EntryBB);
743743
744744 // Resolve the call to function F via the JIT API: