[PATCH] D105061: [IR] Fix replaceUsesWithIf ponetial issue with constants

Stanislav Mekhanoshin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 28 14:43:08 PDT 2021


rampitec updated this revision to Diff 355046.
rampitec marked an inline comment as done.
rampitec added a comment.

Use TrackingVH.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105061/new/

https://reviews.llvm.org/D105061

Files:
  llvm/lib/IR/Value.cpp


Index: llvm/lib/IR/Value.cpp
===================================================================
--- llvm/lib/IR/Value.cpp
+++ llvm/lib/IR/Value.cpp
@@ -531,6 +531,9 @@
   assert(New->getType() == getType() &&
          "replaceUses of value with new value of different type!");
 
+  SmallVector<TrackingVH<Constant>, 8> Consts;
+  SmallPtrSet<Constant *, 8> Visited;
+
   for (use_iterator UI = use_begin(), E = use_end(); UI != E;) {
     Use &U = *UI;
     ++UI;
@@ -540,12 +543,19 @@
     // constant because they are uniqued.
     if (auto *C = dyn_cast<Constant>(U.getUser())) {
       if (!isa<GlobalValue>(C)) {
-        C->handleOperandChange(this, New);
+        if (Visited.insert(C).second)
+          Consts.push_back(TrackingVH<Constant>(C));
         continue;
       }
     }
     U.set(New);
   }
+
+  while (!Consts.empty()) {
+    // FIXME: handleOperandChange() updates all the uses in a given Constant,
+    //        not just the one passed to ShouldReplace
+    Consts.pop_back_val()->handleOperandChange(this, New);
+  }
 }
 
 /// Replace llvm.dbg.* uses of MetadataAsValue(ValueAsMetadata(V)) outside BB


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105061.355046.patch
Type: text/x-patch
Size: 1129 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210628/1b51a919/attachment-0001.bin>


More information about the llvm-commits mailing list