Index: include/llvm/IR/InstrTypes.h =================================================================== --- include/llvm/IR/InstrTypes.h +++ include/llvm/IR/InstrTypes.h @@ -913,8 +913,7 @@ /// 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, - Predicate predicate, Value *S1, + static CmpInst *Create(Predicate predicate, Value *S1, Value *S2, const Twine &Name = "", Instruction *InsertBefore = nullptr); @@ -922,7 +921,7 @@ /// two operands. Also automatically insert this instruction to the end of /// the BasicBlock specified. /// @brief Create a CmpInst - static CmpInst *Create(OtherOps Op, Predicate predicate, Value *S1, + static CmpInst *Create(Predicate predicate, Value *S1, Value *S2, const Twine &Name, BasicBlock *InsertAtEnd); /// @brief Get the opcode casted to the right type Index: lib/CodeGen/CodeGenPrepare.cpp =================================================================== --- lib/CodeGen/CodeGenPrepare.cpp +++ lib/CodeGen/CodeGenPrepare.cpp @@ -1266,7 +1266,7 @@ BasicBlock::iterator InsertPt = UserBB->getFirstInsertionPt(); assert(InsertPt != UserBB->end()); InsertedCmp = - CmpInst::Create(CI->getOpcode(), CI->getPredicate(), + CmpInst::Create(CI->getPredicate(), CI->getOperand(0), CI->getOperand(1), "", &*InsertPt); // Propagate the debug info. InsertedCmp->setDebugLoc(CI->getDebugLoc()); Index: lib/IR/Constants.cpp =================================================================== --- lib/IR/Constants.cpp +++ lib/IR/Constants.cpp @@ -2853,8 +2853,7 @@ } case Instruction::ICmp: case Instruction::FCmp: - return CmpInst::Create((Instruction::OtherOps)getOpcode(), - (CmpInst::Predicate)getPredicate(), Ops[0], Ops[1]); + return CmpInst::Create((CmpInst::Predicate)getPredicate(), Ops[0], Ops[1]); default: assert(getNumOperands() == 2 && "Must be binary operator?"); Index: lib/IR/Instructions.cpp =================================================================== --- lib/IR/Instructions.cpp +++ lib/IR/Instructions.cpp @@ -3310,9 +3310,9 @@ } CmpInst * -CmpInst::Create(OtherOps Op, Predicate predicate, Value *S1, Value *S2, +CmpInst::Create(Predicate predicate, Value *S1, Value *S2, const Twine &Name, Instruction *InsertBefore) { - if (Op == Instruction::ICmp) { + if (isIntPredicate(predicate)) { if (InsertBefore) return new ICmpInst(InsertBefore, CmpInst::Predicate(predicate), S1, S2, Name); @@ -3330,9 +3330,9 @@ } CmpInst * -CmpInst::Create(OtherOps Op, Predicate predicate, Value *S1, Value *S2, +CmpInst::Create(Predicate predicate, Value *S1, Value *S2, const Twine &Name, BasicBlock *InsertAtEnd) { - if (Op == Instruction::ICmp) { + if (isIntPredicate(predicate)) { return new ICmpInst(*InsertAtEnd, CmpInst::Predicate(predicate), S1, S2, Name); } Index: lib/Transforms/InstCombine/InstCombineCompares.cpp =================================================================== --- lib/Transforms/InstCombine/InstCombineCompares.cpp +++ lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -4469,11 +4469,11 @@ m_Value(SelectFalse)))) { if (Value *V = dyn_castNegVal(SelectTrue)) { if (V == SelectFalse) - return CmpInst::Create(Instruction::ICmp, I.getPredicate(), V, Op1); + return new ICmpInst(I.getPredicate(), V, Op1); } else if (Value *V = dyn_castNegVal(SelectFalse)) { if (V == SelectTrue) - return CmpInst::Create(Instruction::ICmp, I.getPredicate(), V, Op1); + return new ICmpInst(I.getPredicate(), V, Op1); } } } Index: lib/Transforms/InstCombine/InstCombinePHI.cpp =================================================================== --- lib/Transforms/InstCombine/InstCombinePHI.cpp +++ lib/Transforms/InstCombine/InstCombinePHI.cpp @@ -115,8 +115,7 @@ } if (CmpInst *CIOp = dyn_cast(FirstInst)) { - CmpInst *NewCI = CmpInst::Create(CIOp->getOpcode(), CIOp->getPredicate(), - LHSVal, RHSVal); + CmpInst *NewCI = CmpInst::Create(CIOp->getPredicate(), LHSVal, RHSVal); NewCI->setDebugLoc(PHIArgMergedDebugLoc(PN)); return NewCI; } @@ -581,8 +580,7 @@ } CmpInst *CIOp = cast(FirstInst); - CmpInst *NewCI = CmpInst::Create(CIOp->getOpcode(), CIOp->getPredicate(), - PhiVal, ConstantOp); + CmpInst *NewCI = CmpInst::Create(CIOp->getPredicate(), PhiVal, ConstantOp); NewCI->setDebugLoc(PHIArgMergedDebugLoc(PN)); return NewCI; } Index: lib/Transforms/InstCombine/InstCombineSelect.cpp =================================================================== --- lib/Transforms/InstCombine/InstCombineSelect.cpp +++ lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -868,8 +868,8 @@ /// icmp instruction with zero, and we have an 'and' with the non-constant value /// and a power of two we can turn the select into a shift on the result of the /// 'and'. -static Value *foldSelectICmpAnd(const SelectInst &SI, ConstantInt *TrueVal, - ConstantInt *FalseVal, +static Value *foldSelectICmpAnd(const SelectInst &SI, APInt TrueVal, + APInt FalseVal, InstCombiner::BuilderTy *Builder) { const ICmpInst *IC = dyn_cast(SI.getCondition()); if (!IC || !IC->isEquality() || !SI.getType()->isIntegerTy()) @@ -886,38 +886,35 @@ // If both select arms are non-zero see if we have a select of the form // 'x ? 2^n + C : C'. Then we can offset both arms by C, use the logic // for 'x ? 2^n : 0' and fix the thing up at the end. - ConstantInt *Offset = nullptr; - if (!TrueVal->isZero() && !FalseVal->isZero()) { - if ((TrueVal->getValue() - FalseVal->getValue()).isPowerOf2()) + APInt Offset(TrueVal.getBitWidth(), 0); + if (!TrueVal.isNullValue() && !FalseVal.isNullValue()) { + if ((TrueVal - FalseVal).isPowerOf2()) Offset = FalseVal; - else if ((FalseVal->getValue() - TrueVal->getValue()).isPowerOf2()) + else if ((FalseVal - TrueVal).isPowerOf2()) Offset = TrueVal; else return nullptr; // Adjust TrueVal and FalseVal to the offset. - TrueVal = ConstantInt::get(Builder->getContext(), - TrueVal->getValue() - Offset->getValue()); - FalseVal = ConstantInt::get(Builder->getContext(), - FalseVal->getValue() - Offset->getValue()); + TrueVal -= Offset; + FalseVal -= Offset; } // Make sure the mask in the 'and' and one of the select arms is a power of 2. if (!AndRHS->getValue().isPowerOf2() || - (!TrueVal->getValue().isPowerOf2() && - !FalseVal->getValue().isPowerOf2())) + (!TrueVal.isPowerOf2() && !FalseVal.isPowerOf2())) return nullptr; // Determine which shift is needed to transform result of the 'and' into the // desired result. - ConstantInt *ValC = !TrueVal->isZero() ? TrueVal : FalseVal; - unsigned ValZeros = ValC->getValue().logBase2(); + const APInt &ValC = !TrueVal.isNullValue() ? TrueVal : FalseVal; + unsigned ValZeros = ValC.logBase2(); unsigned AndZeros = AndRHS->getValue().logBase2(); // If types don't match we can still convert the select by introducing a zext // or a trunc of the 'and'. The trunc case requires that all of the truncated // bits are zero, we can figure that out by looking at the 'and' mask. - if (AndZeros >= ValC->getBitWidth()) + if (AndZeros >= ValC.getBitWidth()) return nullptr; Value *V = Builder->CreateZExtOrTrunc(LHS, SI.getType()); @@ -928,14 +925,14 @@ // Okay, now we know that everything is set up, we just don't know whether we // have a icmp_ne or icmp_eq and whether the true or false val is the zero. - bool ShouldNotVal = !TrueVal->isZero(); + bool ShouldNotVal = !TrueVal.isNullValue(); ShouldNotVal ^= IC->getPredicate() == ICmpInst::ICMP_NE; if (ShouldNotVal) V = Builder->CreateXor(V, ValC); // Apply an offset if needed. - if (Offset) - V = Builder->CreateAdd(V, Offset); + if (!Offset.isNullValue()) + V = Builder->CreateAdd(V, ConstantInt::get(V->getType(), Offset)); return V; } @@ -1250,7 +1247,8 @@ if (ConstantInt *TrueValC = dyn_cast(TrueVal)) if (ConstantInt *FalseValC = dyn_cast(FalseVal)) - if (Value *V = foldSelectICmpAnd(SI, TrueValC, FalseValC, Builder)) + if (Value *V = foldSelectICmpAnd(SI, TrueValC->getValue(), + FalseValC->getValue(), Builder)) return replaceInstUsesWith(SI, V); // See if we are selecting two values based on a comparison of the two values. Index: lib/Transforms/Vectorize/LoopVectorize.cpp =================================================================== --- lib/Transforms/Vectorize/LoopVectorize.cpp +++ lib/Transforms/Vectorize/LoopVectorize.cpp @@ -3554,9 +3554,8 @@ // Add a check in the middle block to see if we have completed // all of the iterations in the first vector loop. // If (N - N%VF) == N, then we *don't* need to run the remainder. - Value *CmpN = - CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, Count, - CountRoundDown, "cmp.n", MiddleBlock->getTerminator()); + Value *CmpN = new ICmpInst(MiddleBlock->getTerminator(), ICmpInst::ICMP_EQ, + Count, CountRoundDown, "cmp.n"); ReplaceInstWithInst(MiddleBlock->getTerminator(), BranchInst::Create(ExitBlock, ScalarPH, CmpN)); Index: tools/llvm-stress/llvm-stress.cpp =================================================================== --- tools/llvm-stress/llvm-stress.cpp +++ tools/llvm-stress/llvm-stress.cpp @@ -627,8 +627,7 @@ CmpInst::FIRST_ICMP_PREDICATE; } - Value *V = CmpInst::Create(fp ? Instruction::FCmp : Instruction::ICmp, - (CmpInst::Predicate)op, Val0, Val1, "Cmp", + Value *V = CmpInst::Create((CmpInst::Predicate)op, Val0, Val1, "Cmp", BB->getTerminator()); return PT->push_back(V); } Index: unittests/Analysis/ScalarEvolutionTest.cpp =================================================================== --- unittests/Analysis/ScalarEvolutionTest.cpp +++ unittests/Analysis/ScalarEvolutionTest.cpp @@ -320,8 +320,8 @@ GetElementPtrInst::Create(I8Ty, CastA, Ci32, "gep1", Br); GetElementPtrInst *Gep2 = GetElementPtrInst::Create( I8Ty, UndefValue::get(I8PtrTy), Ci32, "gep2", Br); - CmpInst *Cmp = CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_ULT, - UndefValue::get(I8PtrTy), CastA, "cmp", Br); + CmpInst *Cmp = new ICmpInst(Br, ICmpInst::ICMP_ULT, + UndefValue::get(I8PtrTy), CastA, "cmp"); SelectInst *Sel = SelectInst::Create(Cmp, Gep1, Gep2, "select", Br); CastInst *CastB = CastInst::CreateBitOrPointerCast(Sel, I32PtrTy, "bitcast2", Br); @@ -828,9 +828,8 @@ BasicBlock *IncBB = BasicBlock::Create(Context, "for.inc", F, EndBB); auto *PN = PHINode::Create(I64Ty, 2, "", CondBB); PN->addIncoming(ConstantInt::get(Context, APInt(64, 100)), PrevBB); - auto *Cmp = CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_SGT, PN, - ConstantInt::get(Context, APInt(64, 90)), "cmp", - CondBB); + auto *Cmp = new ICmpInst(*CondBB, ICmpInst::ICMP_SGT, PN, + ConstantInt::get(Context, APInt(64, 90)), "cmp"); BasicBlock *NextBB; if (i != Iters - 1) NextBB = BasicBlock::Create(Context, "for.cond", F, EndBB);