Skip to content

Commit 2a0eebb

Browse files
traoux1gfxbot
authored andcommitted
Fix crash in standalone tests due to wrong pressure estimate.
Need to look at the load/store inst to estimate pressure from promoting alloca Change-Id: Ifb49b787d434c516700ff38652eadceaaed1c577
1 parent eb57168 commit 2a0eebb

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

IGC/Compiler/CISACodeGen/LowerGEPForPrivMem.cpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,23 @@ unsigned int LowerGEPForPrivMem::extractAllocaSize(llvm::AllocaInst* pAlloca)
206206
return totalArrayStructureSize;
207207
}
208208

209+
static void GetAllocaLiverange(Instruction* I, unsigned int& liverangeStart, unsigned int& liverangeEnd, RegisterPressureEstimate* rpe)
210+
{
211+
for(Value::user_iterator use_it = I->user_begin(), use_e = I->user_end(); use_it != use_e; ++use_it)
212+
{
213+
if(isa<GetElementPtrInst>(*use_it) || isa<BitCastInst>(*use_it))
214+
{
215+
GetAllocaLiverange(cast<Instruction>(*use_it), liverangeStart, liverangeEnd, rpe);
216+
}
217+
else if(isa<LoadInst>(*use_it) || isa<StoreInst>(*use_it) || isa<llvm::IntrinsicInst>(*use_it))
218+
{
219+
unsigned int idx = rpe->getAssignedNumberForInst(cast<Instruction>(*use_it));
220+
liverangeStart = std::min(liverangeStart, idx);
221+
liverangeEnd = std::max(liverangeEnd, idx);
222+
}
223+
}
224+
}
225+
209226
bool LowerGEPForPrivMem::CheckIfAllocaPromotable(llvm::AllocaInst* pAlloca)
210227
{
211228
auto WI = &getAnalysis<WIAnalysis>();
@@ -261,24 +278,15 @@ bool LowerGEPForPrivMem::CheckIfAllocaPromotable(llvm::AllocaInst* pAlloca)
261278

262279
// get all the basic blocks that contain the uses of the alloca
263280
// then estimate how much changing this alloca to register adds to the pressure at that block.
264-
unsigned int assignedNumber = 0;
265-
unsigned int lowestAssignedNumber = m_pRegisterPressureEstimate->getMaxAssignedNumberForFunction();
281+
unsigned int lowestAssignedNumber = 0xFFFFFFFF;
266282
unsigned int highestAssignedNumber = 0;
267283

268-
for (auto II = pAlloca->user_begin(), IE = pAlloca->user_end(); II != IE; ++II)
269-
{
270-
if (Instruction* inst = dyn_cast<Instruction>(*II))
271-
{
272-
assignedNumber = m_pRegisterPressureEstimate->getAssignedNumberForInst(inst);
273-
lowestAssignedNumber = (lowestAssignedNumber < assignedNumber) ? lowestAssignedNumber : assignedNumber;
274-
highestAssignedNumber = (highestAssignedNumber > assignedNumber) ? highestAssignedNumber : assignedNumber;
275-
}
276-
}
284+
GetAllocaLiverange(pAlloca, lowestAssignedNumber, highestAssignedNumber, m_pRegisterPressureEstimate);
277285

278286
uint32_t maxGRFPressure = (uint32_t)(grfRatio * MAX_PRESSURE_GRF_NUM * 4);
279287

280288
unsigned int pressure = 0;
281-
for(unsigned int i = lowestAssignedNumber; i < highestAssignedNumber; i++)
289+
for(unsigned int i = lowestAssignedNumber; i <= highestAssignedNumber; i++)
282290
{
283291
pressure = std::max(
284292
pressure, m_pRegisterPressureEstimate->getRegisterPressureForInstructionFromRPMap(i));

0 commit comments

Comments
 (0)