@@ -1051,19 +1051,20 @@ bool UnclusteredHighRPStage::initGCNSchedStage() {
10511051 createIGroupLPDAGMutation (AMDGPU::SchedulingPhase::PreRAReentry));
10521052
10531053 InitialOccupancy = DAG.MinOccupancy ;
1054- IsAnyRegionScheduled = false ;
1055- // Aggressivly try to reduce register pressure in the unclustered high RP
1054+ // Aggressively try to reduce register pressure in the unclustered high RP
10561055 // stage. Temporarily increase occupancy target in the region.
1056+ TempTargetOccupancy = MFI.getMaxWavesPerEU () > DAG.MinOccupancy
1057+ ? InitialOccupancy + 1
1058+ : InitialOccupancy;
1059+ IsAnyRegionScheduled = false ;
10571060 S.SGPRLimitBias = S.HighRPSGPRBias ;
10581061 S.VGPRLimitBias = S.HighRPVGPRBias ;
1059- if (MFI.getMaxWavesPerEU () > DAG.MinOccupancy )
1060- MFI.increaseOccupancy (MF, ++DAG.MinOccupancy );
10611062
10621063 LLVM_DEBUG (
10631064 dbgs ()
10641065 << " Retrying function scheduling without clustering. "
1065- " Aggressivly try to reduce register pressure to achieve occupancy "
1066- << DAG. MinOccupancy << " .\n " );
1066+ " Aggressively try to reduce register pressure to achieve occupancy "
1067+ << TempTargetOccupancy << " .\n " );
10671068
10681069 return true ;
10691070}
@@ -1144,16 +1145,16 @@ void UnclusteredHighRPStage::finalizeGCNSchedStage() {
11441145 SavedMutations.swap (DAG.Mutations );
11451146 S.SGPRLimitBias = S.VGPRLimitBias = 0 ;
11461147 if (DAG.MinOccupancy > InitialOccupancy) {
1147- if (IsAnyRegionScheduled) {
1148- LLVM_DEBUG (dbgs () << StageID
1149- << " stage successfully increased occupancy to "
1150- << DAG.MinOccupancy << ' \n ' );
1151- } else {
1152- DAG.MinOccupancy = InitialOccupancy;
1153- LLVM_DEBUG (dbgs () << StageID
1154- << " : No regions scheduled, resetting min occupancy to "
1155- << InitialOccupancy << " \n " );
1156- }
1148+ assert (IsAnyRegionScheduled);
1149+ LLVM_DEBUG (dbgs () << StageID
1150+ << " stage successfully increased occupancy to "
1151+ << DAG.MinOccupancy << ' \n ' );
1152+ } else if (!IsAnyRegionScheduled) {
1153+ assert ( DAG.MinOccupancy == InitialOccupancy) ;
1154+ LLVM_DEBUG (dbgs () << StageID
1155+ << " : No regions scheduled, min occupancy stays at "
1156+ << DAG. MinOccupancy << " , MFI occupancy stays at "
1157+ << MFI. getOccupancy () << " . \n " );
11571158 }
11581159
11591160 GCNSchedStage::finalizeGCNSchedStage ();
@@ -1227,16 +1228,27 @@ bool UnclusteredHighRPStage::initGCNRegion() {
12271228 // rescheduling of previous regions did not make occupancy drop back down to
12281229 // the initial minimum).
12291230 unsigned DynamicVGPRBlockSize = DAG.MFI .getDynamicVGPRBlockSize ();
1231+ // If no region has been scheduled yet, the DAG has not yet been updated with
1232+ // the occupancy target. So retrieve it from the temporary.
1233+ unsigned CurrentTargetOccupancy =
1234+ IsAnyRegionScheduled ? DAG.MinOccupancy : TempTargetOccupancy;
12301235 if (!DAG.RegionsWithExcessRP [RegionIdx] &&
1231- (DAG. MinOccupancy <= InitialOccupancy ||
1236+ (CurrentTargetOccupancy <= InitialOccupancy ||
12321237 DAG.Pressure [RegionIdx].getOccupancy (ST, DynamicVGPRBlockSize) !=
12331238 InitialOccupancy))
12341239 return false ;
12351240
1236- bool IsRegionScheduled = GCNSchedStage::initGCNRegion ();
1237- if (!IsAnyRegionScheduled && IsRegionScheduled)
1241+ bool IsSchedulingThisRegion = GCNSchedStage::initGCNRegion ();
1242+ // If this is the first region scheduled during this stage, make the target
1243+ // occupancy changes in the DAG and MFI.
1244+ if (!IsAnyRegionScheduled && IsSchedulingThisRegion) {
12381245 IsAnyRegionScheduled = true ;
1239- return IsRegionScheduled;
1246+ if (MFI.getMaxWavesPerEU () > DAG.MinOccupancy ) {
1247+ DAG.MinOccupancy = TempTargetOccupancy;
1248+ MFI.increaseOccupancy (MF, TempTargetOccupancy);
1249+ }
1250+ }
1251+ return IsSchedulingThisRegion;
12401252}
12411253
12421254bool ClusteredLowOccStage::initGCNRegion () {
0 commit comments