[llvm] 1e9a0a4 - SROA: Remove pointer from visited along with instruction

Stanislav Mekhanoshin via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 5 12:47:33 PDT 2020


Author: Stanislav Mekhanoshin
Date: 2020-06-05T12:47:23-07:00
New Revision: 1e9a0a4e04aa66f048ba791e25d32ce8c02a20a4

URL: https://github.com/llvm/llvm-project/commit/1e9a0a4e04aa66f048ba791e25d32ce8c02a20a4
DIFF: https://github.com/llvm/llvm-project/commit/1e9a0a4e04aa66f048ba791e25d32ce8c02a20a4.diff

LOG: SROA: Remove pointer from visited along with instruction

If an instruction is erased we also need to remove it from
Visited set. There is a very small chance that an another
newly created instruction will be created with the same
pointer value in place of an erased one.

Differential Revision: https://reviews.llvm.org/D80958

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/SROA.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/SROA.cpp b/llvm/lib/Transforms/Scalar/SROA.cpp
index 7e92f7b06ecb..9b3c77eae120 100644
--- a/llvm/lib/Transforms/Scalar/SROA.cpp
+++ b/llvm/lib/Transforms/Scalar/SROA.cpp
@@ -3381,6 +3381,7 @@ class AggLoadStoreRewriter : public InstVisitor<AggLoadStoreRewriter, bool> {
                             getAdjustedAlignment(&LI, 0), DL);
     Value *V = UndefValue::get(LI.getType());
     Splitter.emitSplitOps(LI.getType(), V, LI.getName() + ".fca");
+    Visited.erase(&LI);
     LI.replaceAllUsesWith(V);
     LI.eraseFromParent();
     return true;
@@ -3427,6 +3428,7 @@ class AggLoadStoreRewriter : public InstVisitor<AggLoadStoreRewriter, bool> {
     StoreOpSplitter Splitter(&SI, *U, V->getType(), AATags,
                              getAdjustedAlignment(&SI, 0), DL);
     Splitter.emitSplitOps(V->getType(), V, V->getName() + ".fca");
+    Visited.erase(&SI);
     SI.eraseFromParent();
     return true;
   }
@@ -3473,6 +3475,7 @@ class AggLoadStoreRewriter : public InstVisitor<AggLoadStoreRewriter, bool> {
 
     Value *NSel = Builder.CreateSelect(Sel->getCondition(), NTrue, NFalse,
                                        Sel->getName() + ".sroa.sel");
+    Visited.erase(&GEPI);
     GEPI.replaceAllUsesWith(NSel);
     GEPI.eraseFromParent();
     Instruction *NSelI = cast<Instruction>(NSel);
@@ -3521,6 +3524,7 @@ class AggLoadStoreRewriter : public InstVisitor<AggLoadStoreRewriter, bool> {
       NewPN->addIncoming(NewVal, PHI->getIncomingBlock(I));
     }
 
+    Visited.erase(&GEPI);
     GEPI.replaceAllUsesWith(NewPN);
     GEPI.eraseFromParent();
     Visited.insert(NewPN);


        


More information about the llvm-commits mailing list