[llvm] [GVNSink] Fix non-determinisms by using Depth-First ordering (PR #90995)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed May 8 18:38:38 PDT 2024


================
@@ -575,6 +607,13 @@ class GVNSink {
     unsigned NumSunk = 0;
     ReversePostOrderTraversal<Function*> RPOT(&F);
     VN.setReachableBBs(BasicBlocksSet(RPOT.begin(), RPOT.end()));
+    // Populated DFSNumbers ahead of time to avoid updating dominator tree
+    // when CFG is modified. The DFSNumbers of newly created basic blocks
+    // are irrelevant because RPOT is also obtained ahead of time and only
+    // DFSNumbers of original CFG are relevant for sinkable candidates.
+    for (auto *BB : RPOT)
+      if (DT->getNode(BB))
+        DFSNumbers[BB] = DT->getNode(BB)->getDFSNumIn();
----------------
nikic wrote:

Do you actually care about these being DFS numbers, rather than some arbitrary block numbering? If not, you could just use the numbering produced by RPOT.

https://github.com/llvm/llvm-project/pull/90995


More information about the llvm-commits mailing list