[InstCombine] Erase old mul when creating umulo

As we don't return the result of replaceInstUsesWith(), we are
responsible for erasing the instruction.

There is a small subtlety here in that we need to do this after
the other uses of Builder, which uses the original multiply as
the insertion point.

NFC apart from worklist order changes.
This commit is contained in:
Nikita Popov 2020-03-29 19:20:11 +02:00
parent 53d209076a
commit 8253a86b65
1 changed files with 5 additions and 0 deletions

View File

@ -3671,6 +3671,11 @@ Value *InstCombiner::foldUnsignedMultiplicationOverflowCheck(ICmpInst &I) {
if (NeedNegation) // This technically increases instruction count.
Res = Builder.CreateNot(Res, "umul.not.ov");
// If we replaced the mul, erase it. Do this after all uses of Builder,
// as the mul is used as insertion point.
if (MulHadOtherUses)
eraseInstFromFunction(*Mul);
return Res;
}