[PATCH] D54011: [NFC][LICM] Factor out instruction erasing logic

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 1 17:25:23 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL345914: [NFC][LICM] Factor out instruction erasing logic (authored by mkazantsev, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D54011?vs=172270&id=172281#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D54011

Files:
  llvm/trunk/lib/Transforms/Scalar/LICM.cpp


Index: llvm/trunk/lib/Transforms/Scalar/LICM.cpp
===================================================================
--- llvm/trunk/lib/Transforms/Scalar/LICM.cpp
+++ llvm/trunk/lib/Transforms/Scalar/LICM.cpp
@@ -123,6 +123,8 @@
                             const LoopInfo *LI,
                             const LoopSafetyInfo *SafetyInfo);
 
+static void eraseInstruction(Instruction &I, AliasSetTracker *AST);
+
 namespace {
 struct LoopInvariantCodeMotion {
   using ASTrackerMapTy = DenseMap<Loop *, std::unique_ptr<AliasSetTracker>>;
@@ -404,8 +406,7 @@
         LLVM_DEBUG(dbgs() << "LICM deleting dead inst: " << I << '\n');
         salvageDebugInfo(I);
         ++II;
-        CurAST->deleteValue(&I);
-        I.eraseFromParent();
+        eraseInstruction(I, CurAST);
         Changed = true;
         continue;
       }
@@ -422,8 +423,7 @@
         if (sink(I, LI, DT, CurLoop, SafetyInfo, ORE, FreeInLoop)) {
           if (!FreeInLoop) {
             ++II;
-            CurAST->deleteValue(&I);
-            I.eraseFromParent();
+            eraseInstruction(I, CurAST);
           }
           Changed = true;
         }
@@ -480,10 +480,8 @@
                           << '\n');
         CurAST->copyValue(&I, C);
         I.replaceAllUsesWith(C);
-        if (isInstructionTriviallyDead(&I, TLI)) {
-          CurAST->deleteValue(&I);
-          I.eraseFromParent();
-        }
+        if (isInstructionTriviallyDead(&I, TLI))
+          eraseInstruction(I, CurAST);
         Changed = true;
         continue;
       }
@@ -519,7 +517,7 @@
         Product->setFastMathFlags(I.getFastMathFlags());
         Product->insertAfter(&I);
         I.replaceAllUsesWith(Product);
-        I.eraseFromParent();
+        eraseInstruction(I, CurAST);
 
         hoist(*ReciprocalDivisor, DT, CurLoop, SafetyInfo, ORE);
         Changed = true;
@@ -888,6 +886,12 @@
   return New;
 }
 
+static void eraseInstruction(Instruction &I, AliasSetTracker *AST) {
+  if (AST)
+    AST->deleteValue(&I);
+  I.eraseFromParent();
+}
+
 static Instruction *sinkThroughTriviallyReplaceablePHI(
     PHINode *TPN, Instruction *I, LoopInfo *LI,
     SmallDenseMap<BasicBlock *, Instruction *, 32> &SunkCopies,
@@ -1086,7 +1090,7 @@
     Instruction *New = sinkThroughTriviallyReplaceablePHI(PN, &I, LI, SunkCopies,
                                                           SafetyInfo, CurLoop);
     PN->replaceAllUsesWith(New);
-    PN->eraseFromParent();
+    eraseInstruction(*PN, nullptr);
     Changed = true;
   }
   return Changed;
@@ -1516,7 +1520,7 @@
 
   // If the SSAUpdater didn't use the load in the preheader, just zap it now.
   if (PreheaderLoad->use_empty())
-    PreheaderLoad->eraseFromParent();
+    eraseInstruction(*PreheaderLoad, CurAST);
 
   return true;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54011.172281.patch
Type: text/x-patch
Size: 2777 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181102/80e3fc59/attachment.bin>


More information about the llvm-commits mailing list