@@ -116,6 +116,22 @@ void GCNSchedStrategy::initialize(ScheduleDAGMI *DAG) {
116116 << " , SGPRExcessLimit = " << SGPRExcessLimit << " \n\n " );
117117}
118118
119+ // / Checks whether \p SU can use the cached DAG pressure diffs to compute the
120+ // / current register pressure.
121+ // /
122+ // / This works for the common case, but it has a few exceptions that have been
123+ // / observed through trial and error:
124+ // / - Explicit physical register operands
125+ // / - Subregister definitions
126+ // /
127+ // / In both of those cases, PressureDiff doesn't represent the actual pressure,
128+ // / and querying LiveIntervals through the RegPressureTracker is needed to get
129+ // / an accurate value.
130+ // /
131+ // / We should eventually only use PressureDiff for maximum performance, but this
132+ // / already allows 80% of SUs to take the fast path without changing scheduling
133+ // / at all. Further changes would either change scheduling, or require a lot
134+ // / more logic to recover an accurate pressure estimate from the PressureDiffs.
119135static bool canUsePressureDiffs (const SUnit &SU) {
120136 if (!SU.isInstr ())
121137 return false ;
@@ -160,6 +176,17 @@ void GCNSchedStrategy::initCandidate(SchedCandidate &Cand, SUnit *SU,
160176 Pressure.clear ();
161177 MaxPressure.clear ();
162178
179+ // We try to use the cached PressureDiffs in the ScheduleDAG whenever
180+ // possible over querying the RegPressureTracker.
181+ //
182+ // RegPressureTracker will make a lot of LIS queries which are very
183+ // expensive, it is considered a slow function in this context.
184+ //
185+ // PressureDiffs are precomputed and cached, and getPressureDiff is just a
186+ // trivial lookup into an array. It is pretty much free.
187+ //
188+ // In EXPENSIVE_CHECKS, we always query RPTracker to verify the results of
189+ // PressureDiffs.
163190 if (AtTop || !canUsePressureDiffs (*SU)) {
164191 getRegisterPressures (AtTop, RPTracker, SU, Pressure, MaxPressure);
165192 } else {
0 commit comments