[InstCombine] Fix worklist management in varargs transform

Add a replaceUse() helper to mirror replaceOperand() for the
rare cases where we're working directly on uses.

NFC apart from worklist order changes.
This commit is contained in:
Nikita Popov 2020-03-29 17:38:23 +02:00
parent 6f07a9e80a
commit 28f67bd5c5
3 changed files with 8 additions and 4 deletions

View File

@ -4573,7 +4573,7 @@ Instruction *InstCombiner::visitCallBase(CallBase &Call) {
I != E; ++I, ++ix) {
CastInst *CI = dyn_cast<CastInst>(*I);
if (CI && isSafeToEliminateVarargsCast(Call, DL, CI, ix)) {
*I = CI->getOperand(0);
replaceUse(*I, CI->getOperand(0));
// Update the byval type to match the argument type.
if (Call.isByValArgument(ix)) {

View File

@ -686,6 +686,12 @@ public:
return &I;
}
/// Replace use and add the previously used value to the worklist.
void replaceUse(Use &U, Value *NewValue) {
Worklist.addValue(U);
U = NewValue;
}
/// Creates a result tuple for an overflow intrinsic \p II with a given
/// \p Result and a constant \p Overflow value.
Instruction *CreateOverflowTuple(IntrinsicInst *II, Value *Result,

View File

@ -87,9 +87,7 @@ bool InstCombiner::SimplifyDemandedBits(Instruction *I, unsigned OpNo,
Value *NewVal = SimplifyDemandedUseBits(U.get(), DemandedMask, Known,
Depth, I);
if (!NewVal) return false;
// Add the old operand back to the worklist.
Worklist.addValue(U.get());
U = NewVal;
replaceUse(U, NewVal);
return true;
}