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) {