[InstCombine] Erase original add when creating saddo
authorNikita Popov <nikita.ppv@gmail.com>
Sun, 29 Mar 2020 15:25:42 +0000 (17:25 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Sun, 29 Mar 2020 16:01:32 +0000 (18:01 +0200)
Usually when we replaceInstUsesWith() we also return the original
instruction, and InstCombine will take care of erasing it. Here
we don't do that, so we need to manually erase it.

NFC apart from worklist order changes.

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

index d1fa802..f36dcac 100644 (file)
@@ -1330,6 +1330,7 @@ static Instruction *processUGT_ADDCST_ADD(ICmpInst &I, Value *A, Value *B,
   // The inner add was the result of the narrow add, zero extended to the
   // wider type.  Replace it with the result computed by the intrinsic.
   IC.replaceInstUsesWith(*OrigAdd, ZExt);
+  IC.eraseInstFromFunction(*OrigAdd);
 
   // The original icmp gets replaced with the overflow value.
   return ExtractValueInst::Create(Call, 1, "sadd.overflow");