@@ -1705,14 +1705,16 @@ struct ExcessRP {
1705
1705
bool HasAGPRs = false ;
1706
1706
// / Whether the subtarget has a unified RF.
1707
1707
bool UnifiedRF;
1708
- // / Whether we consider that ArchVGPRs can be spilled to AGPRs and the other
1709
- // / way around.
1710
- bool AllowVGPRToVGPRSpill;
1708
+ // / Whether we consider that the register allocator will be able to swap
1709
+ // / between ArchVGPRs and AGPRs by copying them to a super register class.
1710
+ // / Concretely, this allows savings of one kind of VGPR to help toward savings
1711
+ // / the other kind of VGPR.
1712
+ bool CombineVGPRSavings;
1711
1713
1712
1714
// / Constructs the excess RP model; determines the excess pressure w.r.t. a
1713
1715
// / maximum number of allowed SGPRs/VGPRs.
1714
1716
ExcessRP (const GCNSubtarget &ST, const GCNRegPressure &RP, unsigned MaxSGPRs,
1715
- unsigned MaxVGPRs, bool AllowVGPRToVGPRSpill );
1717
+ unsigned MaxVGPRs, bool CombineVGPRSavings );
1716
1718
1717
1719
// / Accounts for \p NumRegs saved SGPRs in the model. Returns whether saving
1718
1720
// / these SGPRs helped reduce excess pressure.
@@ -1751,9 +1753,8 @@ struct ExcessRP {
1751
1753
1752
1754
ExcessRP::ExcessRP (const GCNSubtarget &ST, const GCNRegPressure &RP,
1753
1755
unsigned MaxSGPRs, unsigned MaxVGPRs,
1754
- bool AllowVGPRToVGPRSpill)
1755
- : UnifiedRF(ST.hasGFX90AInsts()),
1756
- AllowVGPRToVGPRSpill(AllowVGPRToVGPRSpill) {
1756
+ bool CombineVGPRSavings)
1757
+ : UnifiedRF(ST.hasGFX90AInsts()), CombineVGPRSavings(CombineVGPRSavings) {
1757
1758
// Compute excess SGPR pressure.
1758
1759
unsigned NumSGPRs = RP.getSGPRNum ();
1759
1760
if (NumSGPRs > MaxSGPRs)
@@ -1804,9 +1805,9 @@ bool ExcessRP::saveArchVGPRs(unsigned NumRegs) {
1804
1805
return Progress;
1805
1806
1806
1807
if (!UnifiedRF) {
1807
- if (AllowVGPRToVGPRSpill )
1808
+ if (CombineVGPRSavings )
1808
1809
Progress |= saveRegs (AGPRs, NumRegs);
1809
- } else if (HasAGPRs && (VGPRs || (AllowVGPRToVGPRSpill && AGPRs))) {
1810
+ } else if (HasAGPRs && (VGPRs || (CombineVGPRSavings && AGPRs))) {
1810
1811
// There is progress as long as there are VGPRs left to save, even if the
1811
1812
// save induced by this particular call does not cross an ArchVGPR alignment
1812
1813
// barrier.
@@ -1830,10 +1831,10 @@ bool ExcessRP::saveArchVGPRs(unsigned NumRegs) {
1830
1831
ArchVGPRsToAlignment -= NumRegs;
1831
1832
}
1832
1833
1833
- // Prioritize saving generic VGPRs, then AGPRs if we allow AGPR-to-ArchVGPR
1834
- // spilling and have some free ArchVGPR slots .
1834
+ // Prioritize saving generic VGPRs, then AGPRs if we consider that the
1835
+ // register allocator will be able to replace an AGPR with an ArchVGPR .
1835
1836
saveRegs (VGPRs, NumSavedRegs);
1836
- if (AllowVGPRToVGPRSpill )
1837
+ if (CombineVGPRSavings )
1837
1838
saveRegs (AGPRs, NumSavedRegs);
1838
1839
} else {
1839
1840
// No AGPR usage in the region i.e., no allocation granule to worry about.
@@ -1846,7 +1847,7 @@ bool ExcessRP::saveAGPRs(unsigned NumRegs) {
1846
1847
bool Progress = saveRegs (AGPRs, NumRegs);
1847
1848
if (UnifiedRF)
1848
1849
Progress |= saveRegs (VGPRs, NumRegs);
1849
- if (AllowVGPRToVGPRSpill )
1850
+ if (CombineVGPRSavings )
1850
1851
Progress |= saveRegs (ArchVGPRs, NumRegs);
1851
1852
return Progress;
1852
1853
}
@@ -1878,13 +1879,14 @@ bool PreRARematStage::canIncreaseOccupancyOrReduceSpill() {
1878
1879
// one in the whole function.
1879
1880
for (unsigned I = 0 , E = DAG.Regions .size (); I != E; ++I) {
1880
1881
GCNRegPressure &RP = DAG.Pressure [I];
1881
- // We allow saved VGPRs of one category (ArchVGPR or AGPR) to be considered
1882
- // as free spill slots for the other category only when we are just trying
1883
- // to eliminate spilling. At this point we err on the conservative side and
1884
- // do not increase register-to-register spilling for the sake of increasing
1885
- // occupancy.
1882
+ // We allow ArchVGPR or AGPR savings to count as savings of the other kind
1883
+ // of VGPR only when trying to eliminate spilling. We cannot do this when
1884
+ // trying to increase occupancy since VGPR class swaps only occur later in
1885
+ // the register allocator i.e., the scheduler will not be able to reason
1886
+ // about these savings and will not report an increase in the achievable
1887
+ // occupancy, triggering rollbacks.
1886
1888
ExcessRP Excess (ST, RP, MaxSGPRsNoSpill, MaxVGPRsNoSpill,
1887
- /* AllowVGPRToVGPRSpill =*/ true );
1889
+ /* CombineVGPRSavings =*/ true );
1888
1890
if (Excess && IncreaseOccupancy) {
1889
1891
// There is spilling in the region and we were so far trying to increase
1890
1892
// occupancy. Strop trying that and focus on reducing spilling.
@@ -1893,7 +1895,7 @@ bool PreRARematStage::canIncreaseOccupancyOrReduceSpill() {
1893
1895
} else if (IncreaseOccupancy) {
1894
1896
// There is no spilling in the region, try to increase occupancy.
1895
1897
Excess = ExcessRP (ST, RP, MaxSGPRsIncOcc, MaxVGPRsIncOcc,
1896
- /* AllowVGPRToVGPRSpill =*/ false );
1898
+ /* CombineVGPRSavings =*/ false );
1897
1899
}
1898
1900
if (Excess)
1899
1901
OptRegions.insert ({I, Excess});
0 commit comments