@@ -2118,7 +2118,8 @@ unsigned G4_Kernel::getSRFInWords() {
2118
2118
2119
2119
// GRF modes supported by HW
2120
2120
// There must be at least one Config that is VRTEnable for each platform
2121
- GRFMode::GRFMode (const TARGET_PLATFORM platform, Options *op) : options(op) {
2121
+ GRFMode::GRFMode (const TARGET_PLATFORM plat, Options *op)
2122
+ : platform(plat), options(op) {
2122
2123
switch (platform) {
2123
2124
case Xe_XeHPSDV:
2124
2125
case Xe_DG2:
@@ -2179,7 +2180,7 @@ GRFMode::GRFMode(const TARGET_PLATFORM platform, Options *op) : options(op) {
2179
2180
unsigned GRFMode::setModeByRegPressure (unsigned maxRP, unsigned largestInputReg,
2180
2181
bool forceGRFModeUp) {
2181
2182
unsigned size = configs.size (), i = 0 ;
2182
- bool spillAllowed = options-> getuInt32Option (vISA_SpillAllowed ) > 256 ;
2183
+ bool spillAllowed = getSpillThreshold ( ) > 0 ;
2183
2184
// find appropiate GRF based on reg pressure
2184
2185
for (; i < size; i++) {
2185
2186
if (configs[i].VRTEnable && configs[i].numGRF >= lowerBoundGRF &&
@@ -2197,10 +2198,22 @@ unsigned GRFMode::setModeByRegPressure(unsigned maxRP, unsigned largestInputReg,
2197
2198
currentMode = newGRFMode < maxGRFMode ? newGRFMode : maxGRFMode;
2198
2199
}
2199
2200
2200
- if (spillAllowed && currentMode > 0 )
2201
- return configs[--currentMode].numGRF ;
2202
- else
2203
- return configs[currentMode].numGRF ;
2201
+ if (spillAllowed && currentMode > 0 ) {
2202
+ unsigned lowerGRFNum = configs[currentMode - 1 ].numGRF ;
2203
+ // Select a lower GRF number in PreRA in case the register
2204
+ // pressure computed is a bit higher (e.g. 5%) than the lower GRF
2205
+ // config. If spills are detected, RA will still bump up the GRF
2206
+ // number to avoid them.
2207
+ // For example, if reg pressure is 167, we select 160GRF since
2208
+ // we have spill threshold enabled and the diff between 167 and 160
2209
+ // is less than 5%.
2210
+ if ((lowerGRFNum * 1.05 >= maxRP ||
2211
+ configs[currentMode].numGRF == getMaxGRF ()) &&
2212
+ lowerGRFNum >= (largestInputReg + 8 ) &&
2213
+ lowerGRFNum >= lowerBoundGRF)
2214
+ return configs[--currentMode].numGRF ;
2215
+ }
2216
+ return configs[currentMode].numGRF ;
2204
2217
}
2205
2218
}
2206
2219
}
@@ -2220,6 +2233,8 @@ bool GRFMode::hasLargerGRFSameThreads() const {
2220
2233
2221
2234
// Get spill threshold for current GRF mode
2222
2235
unsigned GRFMode::getSpillThreshold () const {
2236
+ if (platform < Xe3)
2237
+ return 0 ;
2223
2238
if (configs[currentMode].numGRF == 256 &&
2224
2239
options->getuInt32Option (vISA_SpillAllowed256GRF) > 0 )
2225
2240
return options->getuInt32Option (vISA_SpillAllowed256GRF);
0 commit comments