[llvm] 5405ee5 - [CodeGenPrepare] Simplify code. NFCI.

Benjamin Kramer via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 11 02:24:50 PDT 2020


Author: Benjamin Kramer
Date: 2020-09-11T11:24:08+02:00
New Revision: 5405ee553a631dd8cd18eed8ed9e76ec318febcb

URL: https://github.com/llvm/llvm-project/commit/5405ee553a631dd8cd18eed8ed9e76ec318febcb
DIFF: https://github.com/llvm/llvm-project/commit/5405ee553a631dd8cd18eed8ed9e76ec318febcb.diff

LOG: [CodeGenPrepare] Simplify code. NFCI.

Added: 
    

Modified: 
    llvm/lib/CodeGen/CodeGenPrepare.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index 9a4ed2fab608..3e5dceccf49b 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -5274,22 +5274,11 @@ bool CodeGenPrepare::optimizeMemoryInst(Instruction *MemoryInst, Value *Addr,
   // If we have no uses, recursively delete the value and all dead instructions
   // using it.
   if (Repl->use_empty()) {
-    // This can cause recursive deletion, which can invalidate our iterator.
-    // Use a WeakTrackingVH to hold onto it in case this happens.
-    Value *CurValue = &*CurInstIterator;
-    WeakTrackingVH IterHandle(CurValue);
-    BasicBlock *BB = CurInstIterator->getParent();
-
-    RecursivelyDeleteTriviallyDeadInstructions(
-        Repl, TLInfo, nullptr,
-        [&](Value *V) { removeAllAssertingVHReferences(V); });
-
-    if (IterHandle != CurValue) {
-      // If the iterator instruction was recursively deleted, start over at the
-      // start of the block.
-      CurInstIterator = BB->begin();
-      SunkAddrs.clear();
-    }
+    resetIteratorIfInvalidatedWhileCalling(CurInstIterator->getParent(), [&]() {
+      RecursivelyDeleteTriviallyDeadInstructions(
+          Repl, TLInfo, nullptr,
+          [&](Value *V) { removeAllAssertingVHReferences(V); });
+    });
   }
   ++NumMemoryInsts;
   return true;


        


More information about the llvm-commits mailing list