diff --git a/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h b/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h --- a/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h +++ b/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h @@ -398,7 +398,7 @@ "New instruction already inserted into a basic block!"); BasicBlock *BB = Old.getParent(); New->insertInto(BB, Old.getIterator()); // Insert inst - Worklist.push(New); + Worklist.add(New); return New; } @@ -417,8 +417,7 @@ Instruction *replaceInstUsesWith(Instruction &I, Value *V) { // If there are no uses to replace, then we return nullptr to indicate that // no changes were made to the program. - if (I.use_empty()) - return nullptr; + if (I.use_empty()) return nullptr; Worklist.pushUsersToWorkList(I); // Add all modified instrs to worklist. @@ -430,6 +429,10 @@ LLVM_DEBUG(dbgs() << "IC: Replacing " << I << "\n" << " with " << *V << '\n'); + // If V is a new unnamed instruction, take the name from the old one. + if (V->use_empty() && isa(V) && !V->hasName() && I.hasName()) + V->takeName(&I); + I.replaceAllUsesWith(V); return &I; } diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h --- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h +++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h @@ -383,68 +383,6 @@ bool IsAnd); public: - /// Inserts an instruction \p New before instruction \p Old - /// - /// Also adds the new instruction to the worklist and returns \p New so that - /// it is suitable for use as the return from the visitation patterns. - Instruction *InsertNewInstBefore(Instruction *New, Instruction &Old) { - assert(New && !New->getParent() && - "New instruction already inserted into a basic block!"); - BasicBlock *BB = Old.getParent(); - New->insertInto(BB, Old.getIterator()); // Insert inst - Worklist.add(New); - return New; - } - - /// Same as InsertNewInstBefore, but also sets the debug loc. - Instruction *InsertNewInstWith(Instruction *New, Instruction &Old) { - New->setDebugLoc(Old.getDebugLoc()); - return InsertNewInstBefore(New, Old); - } - - /// A combiner-aware RAUW-like routine. - /// - /// This method is to be used when an instruction is found to be dead, - /// replaceable with another preexisting expression. Here we add all uses of - /// I to the worklist, replace all uses of I with the new value, then return - /// I, so that the inst combiner will know that I was modified. - Instruction *replaceInstUsesWith(Instruction &I, Value *V) { - // If there are no uses to replace, then we return nullptr to indicate that - // no changes were made to the program. - if (I.use_empty()) return nullptr; - - Worklist.pushUsersToWorkList(I); // Add all modified instrs to worklist. - - // If we are replacing the instruction with itself, this must be in a - // segment of unreachable code, so just clobber the instruction. - if (&I == V) - V = PoisonValue::get(I.getType()); - - LLVM_DEBUG(dbgs() << "IC: Replacing " << I << "\n" - << " with " << *V << '\n'); - - // If V is a new unnamed instruction, take the name from the old one. - if (V->use_empty() && isa(V) && !V->hasName() && I.hasName()) - V->takeName(&I); - - I.replaceAllUsesWith(V); - MadeIRChange = true; - return &I; - } - - /// Replace operand of instruction and add old operand to the worklist. - Instruction *replaceOperand(Instruction &I, unsigned OpNum, Value *V) { - Worklist.addValue(I.getOperand(OpNum)); - I.setOperand(OpNum, V); - return &I; - } - - /// Replace use and add the previously used value to the worklist. - void replaceUse(Use &U, Value *NewValue) { - Worklist.addValue(U); - U = NewValue; - } - /// Create and insert the idiom we use to indicate a block is unreachable /// without having to rewrite the CFG from within InstCombine. void CreateNonTerminatorUnreachable(Instruction *InsertAt) { @@ -477,67 +415,6 @@ return nullptr; // Don't do anything with FI } - void computeKnownBits(const Value *V, KnownBits &Known, - unsigned Depth, const Instruction *CxtI) const { - llvm::computeKnownBits(V, Known, DL, Depth, &AC, CxtI, &DT); - } - - KnownBits computeKnownBits(const Value *V, unsigned Depth, - const Instruction *CxtI) const { - return llvm::computeKnownBits(V, DL, Depth, &AC, CxtI, &DT); - } - - bool isKnownToBeAPowerOfTwo(const Value *V, bool OrZero = false, - unsigned Depth = 0, - const Instruction *CxtI = nullptr) { - return llvm::isKnownToBeAPowerOfTwo(V, DL, OrZero, Depth, &AC, CxtI, &DT); - } - - bool MaskedValueIsZero(const Value *V, const APInt &Mask, unsigned Depth = 0, - const Instruction *CxtI = nullptr) const { - return llvm::MaskedValueIsZero(V, Mask, DL, Depth, &AC, CxtI, &DT); - } - - unsigned ComputeNumSignBits(const Value *Op, unsigned Depth = 0, - const Instruction *CxtI = nullptr) const { - return llvm::ComputeNumSignBits(Op, DL, Depth, &AC, CxtI, &DT); - } - - OverflowResult computeOverflowForUnsignedMul(const Value *LHS, - const Value *RHS, - const Instruction *CxtI) const { - return llvm::computeOverflowForUnsignedMul(LHS, RHS, DL, &AC, CxtI, &DT); - } - - OverflowResult computeOverflowForSignedMul(const Value *LHS, - const Value *RHS, - const Instruction *CxtI) const { - return llvm::computeOverflowForSignedMul(LHS, RHS, DL, &AC, CxtI, &DT); - } - - OverflowResult computeOverflowForUnsignedAdd(const Value *LHS, - const Value *RHS, - const Instruction *CxtI) const { - return llvm::computeOverflowForUnsignedAdd(LHS, RHS, DL, &AC, CxtI, &DT); - } - - OverflowResult computeOverflowForSignedAdd(const Value *LHS, - const Value *RHS, - const Instruction *CxtI) const { - return llvm::computeOverflowForSignedAdd(LHS, RHS, DL, &AC, CxtI, &DT); - } - - OverflowResult computeOverflowForUnsignedSub(const Value *LHS, - const Value *RHS, - const Instruction *CxtI) const { - return llvm::computeOverflowForUnsignedSub(LHS, RHS, DL, &AC, CxtI, &DT); - } - - OverflowResult computeOverflowForSignedSub(const Value *LHS, const Value *RHS, - const Instruction *CxtI) const { - return llvm::computeOverflowForSignedSub(LHS, RHS, DL, &AC, CxtI, &DT); - } - OverflowResult computeOverflow( Instruction::BinaryOps BinaryOp, bool IsSigned, Value *LHS, Value *RHS, Instruction *CxtI) const;