[llvm] [AMDGPU][Scheduler] Scoring system for rematerialization candidates (PR #153092)
Lucas Ramirez via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 20 13:40:33 PDT 2025
================
@@ -1634,122 +1838,89 @@ void GCNSchedStage::revertScheduling() {
DAG.Regions[RegionIdx] = std::pair(DAG.RegionBegin, DAG.RegionEnd);
}
-bool PreRARematStage::canIncreaseOccupancyOrReduceSpill() {
+bool PreRARematStage::setObjective() {
const Function &F = MF.getFunction();
- // Maps optimizable regions (i.e., regions at minimum and register-limited
- // occupancy, or regions with spilling) to the target RP we would like to
- // reach.
- DenseMap<unsigned, GCNRPTarget> OptRegions;
+ // Set up "spilling targets" for all regions.
unsigned MaxSGPRs = ST.getMaxNumSGPRs(F);
unsigned MaxVGPRs = ST.getMaxNumVGPRs(F);
- auto ResetTargetRegions = [&]() {
- OptRegions.clear();
- for (unsigned I = 0, E = DAG.Regions.size(); I != E; ++I) {
- const GCNRegPressure &RP = DAG.Pressure[I];
- GCNRPTarget Target(MaxSGPRs, MaxVGPRs, MF, RP);
- if (!Target.satisfied())
- OptRegions.insert({I, Target});
- }
- };
+ for (unsigned I = 0, E = DAG.Regions.size(); I != E; ++I) {
+ const GCNRegPressure &RP = DAG.Pressure[I];
+ GCNRPTarget &Target = RPTargets.emplace_back(MaxSGPRs, MaxVGPRs, MF, RP);
+ if (!Target.satisfied())
+ TargetRegions.set(I);
+ }
- ResetTargetRegions();
- if (!OptRegions.empty() || DAG.MinOccupancy >= MFI.getMaxWavesPerEU()) {
+ if (TargetRegions.any() || DAG.MinOccupancy >= MFI.getMaxWavesPerEU()) {
----------------
lucas-rami wrote:
It makes sense that we should be able to do that but after trying to move this to the beginning of `PreRARematStage::initGCNSchedStage` it can have an impact when the "amdgpu-num-sgpr" or "amdgpu-num-vgpr" attributes are set with values lower than the maximums we would have gotten by default. If the condition is met we will ignore these harder to achieve RP targets, whereas `setObjective` takes those attributes into account through `getMaxNumSGPRs`/`getMaxNumVGPRs`. The effect can be seen on the `small_num_sgprs_as_spill`/`small_num_vgprs_as_spill` tests in `machine-scheduler-sink-trivial-remats-attr.mir`.
I am unsure whether we should care about honoring these attributes if we are already at maximum achievable occupancy though.
https://github.com/llvm/llvm-project/pull/153092
More information about the llvm-commits
mailing list