Skip to content

Commit bf2e38d

Browse files
Gang Y Chenigcbot
authored andcommitted
add conditions for hoisting
measure level of dependences in BB. Note this optimization is still off by default
1 parent 52ffe42 commit bf2e38d

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

IGC/Compiler/CISACodeGen/AdvMemOpt.cpp

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,19 +185,46 @@ bool AdvMemOpt::runOnFunction(Function& F) {
185185
BasicBlock& EntryBlk = F.getEntryBlock();
186186
unsigned LiveOutPressure = 0;
187187
unsigned NumSampleInsts = 0;
188-
// check how many sample instruction and the live-out registers in the entry-block
188+
unsigned NumOtherInsts = 0;
189+
unsigned MaxLevelDeps = 0;
190+
std::map<Instruction*, unsigned> InstDepLevel;
191+
// check several parameters as the indicator of sampler hoisting:
192+
// the number of sample instructions
193+
// the number of other instructions
194+
// the level of dependencies on sample instructions
195+
// the live-out registers in the entry-block
189196
for (auto BI = EntryBlk.begin(), BE = EntryBlk.end(); BI != BE; ++BI)
190197
{
191198
auto Inst = &*BI;
199+
// compute instruction's dependency level
200+
unsigned DepLevel = 0;
201+
for (Value* Opnd : Inst->operands())
202+
{
203+
if (auto SrcI = dyn_cast<Instruction>(Opnd))
204+
{
205+
if (InstDepLevel.find(SrcI) != InstDepLevel.end())
206+
{
207+
DepLevel = max(DepLevel, InstDepLevel[SrcI]);
208+
}
209+
}
210+
}
192211
if (isSampleLoadGather4InfoInstruction(Inst))
212+
{
193213
NumSampleInsts++;
214+
DepLevel++; // bump up the dependency-level
215+
}
216+
else
217+
NumOtherInsts++;
218+
InstDepLevel[Inst] = DepLevel;
219+
MaxLevelDeps = max(MaxLevelDeps, DepLevel);
194220
if (Inst->isUsedOutsideOfBlock(&EntryBlk))
195221
{
196222
LiveOutPressure += (uint)(DL.getTypeAllocSize(Inst->getType()));
197223
}
198224
}
199225
// hoist sampler instructions from the blocks post-dominiating the entry block
200-
if (NumSampleInsts > 0 && NumSampleInsts <= 3 && LiveOutPressure <= 92)
226+
if ((NumSampleInsts * 33) >= NumOtherInsts &&
227+
MaxLevelDeps >= 2 && LiveOutPressure <= 96)
201228
{
202229
auto Node = PDT->getNode(&EntryBlk);
203230
unsigned NumSampleHoisted = 0;

0 commit comments

Comments
 (0)