Skip to content

Commit e8b83f7

Browse files
committed
[RDA] Only store most recent reaching def from predecessors (NFCI)
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 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. Differential Revision: https://reviews.llvm.org/D77508
1 parent a2bb19c commit e8b83f7

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

llvm/lib/CodeGen/ReachingDefAnalysis.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,16 @@ void ReachingDefAnalysis::enterBasicBlock(
8383
if (Incoming.empty())
8484
continue;
8585

86-
for (unsigned Unit = 0; Unit != NumRegUnits; ++Unit) {
87-
// Use the most recent predecessor def for each register.
86+
// Find the most recent reaching definition from a predecessor.
87+
for (unsigned Unit = 0; Unit != NumRegUnits; ++Unit)
8888
LiveRegs[Unit] = std::max(LiveRegs[Unit], Incoming[Unit]);
89-
if ((LiveRegs[Unit] != ReachingDefDefaultVal))
90-
MBBReachingDefs[MBBNumber][Unit].push_back(LiveRegs[Unit]);
91-
}
9289
}
9390

91+
// Insert the most recent reaching definition we found.
92+
for (unsigned Unit = 0; Unit != NumRegUnits; ++Unit)
93+
if (LiveRegs[Unit] != ReachingDefDefaultVal)
94+
MBBReachingDefs[MBBNumber][Unit].push_back(LiveRegs[Unit]);
95+
9496
LLVM_DEBUG(dbgs() << printMBBReference(*MBB)
9597
<< (!TraversedMBB.IsDone ? ": incomplete\n"
9698
: ": all preds known\n"));

0 commit comments

Comments
 (0)