[PATCH] D77508: [RDA] Only store most recent reaching def from predecessors (NFCI)

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 5 12:16:53 PDT 2020


nikic created this revision.
nikic added reviewers: samparker, SjoerdMeijer, craig.topper.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

When entering a basic block, RDA inserts reaching definitions coming from predecessor blocks (which will be negative numbers) in a rather peculiar way. If you save have incoming reaching definitions -4, -3, -2, -1, it will insert those. If you have incoming reaching definitions -1, -2, -3, -4, it will insert -1, -1, -1, -1, as the max is taken at each step. That's probably not what was intended...

However, RDA only actually cares about the most recent reaching definition from a predecessor (to calculate clearance), so this ends up working fine as far as behavior is concerned. It does waste memory on unnecessary reaching definitions though.

This patch changes the implementation to first compute the most recent reaching definition in one loop, and then insert only that one in a separate loop.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77508

Files:
  lib/CodeGen/ReachingDefAnalysis.cpp


Index: lib/CodeGen/ReachingDefAnalysis.cpp
===================================================================
--- lib/CodeGen/ReachingDefAnalysis.cpp
+++ lib/CodeGen/ReachingDefAnalysis.cpp
@@ -83,14 +83,16 @@
     if (Incoming.empty())
       continue;
 
-    for (unsigned Unit = 0; Unit != NumRegUnits; ++Unit) {
-      // Use the most recent predecessor def for each register.
+    // Find the most recent reaching definition from a predecessor.
+    for (unsigned Unit = 0; Unit != NumRegUnits; ++Unit)
       LiveRegs[Unit] = std::max(LiveRegs[Unit], Incoming[Unit]);
-      if ((LiveRegs[Unit] != ReachingDefDefaultVal))
-        MBBReachingDefs[MBBNumber][Unit].push_back(LiveRegs[Unit]);
-    }
   }
 
+  // Insert the most recent reaching definition we found.
+  for (unsigned Unit = 0; Unit != NumRegUnits; ++Unit)
+    if (LiveRegs[Unit] != ReachingDefDefaultVal)
+      MBBReachingDefs[MBBNumber][Unit].push_back(LiveRegs[Unit]);
+
   LLVM_DEBUG(dbgs() << printMBBReference(*MBB)
                     << (!TraversedMBB.IsDone ? ": incomplete\n"
                                              : ": all preds known\n"));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77508.255180.patch
Type: text/x-patch
Size: 1132 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200405/2996c45e/attachment.bin>


More information about the llvm-commits mailing list