These two helpers also decrement the use count of the replaced
operand, so give them the same treatment as eraseInstruction().
/// Replace operand of instruction and add old operand to the worklist.
Instruction *replaceOperand(Instruction &I, unsigned OpNum, Value *V) {
- Worklist.addValue(I.getOperand(OpNum));
+ Value *OldOp = I.getOperand(OpNum);
I.setOperand(OpNum, V);
+ Worklist.handleUseCountDecrement(OldOp);
return &I;
}
/// Replace use and add the previously used value to the worklist.
void replaceUse(Use &U, Value *NewValue) {
- Worklist.addValue(U);
+ Value *OldOp = U;
U = NewValue;
+ Worklist.handleUseCountDecrement(OldOp);
}
/// Combiner aware instruction erasure.