[llvm] 8253a86 - [InstCombine] Erase old mul when creating umulo

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 29 11:48:49 PDT 2020


Author: Nikita Popov
Date: 2020-03-29T20:46:08+02:00
New Revision: 8253a86b65c626f470e90ddacba1166b81012b12

URL: https://github.com/llvm/llvm-project/commit/8253a86b65c626f470e90ddacba1166b81012b12
DIFF: https://github.com/llvm/llvm-project/commit/8253a86b65c626f470e90ddacba1166b81012b12.diff

LOG: [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.

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 259481041302..31dfd46bb858 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -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;
 }
 


        


More information about the llvm-commits mailing list