Skip to content

Commit 601d61e

Browse files
grey-eminencesys_zuul
authored andcommitted
Fix in Global Address Space Resolution pass.
Since %49 is used twice in phi instruction like below: %56 = phi %"class.someclass" addrspace(4)* [ %49, %53 ], [ %49, %742 ] the use iterator was handling such phi instructions twice. This was causing a crash since propagate function might erase instructions. Change-Id: I23cec884d6331258562a30e37a70f03148a076b0
1 parent 7fa42ec commit 601d61e

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

IGC/Compiler/CISACodeGen/ResolveGAS.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,25 @@ bool GASResolving::resolveOnBasicBlock(BasicBlock* BB) const {
218218
CI->setOperand(0, Src);
219219
Changed = true;
220220
}
221+
// Since %49 is used twice in a phi instruction like the one below:
222+
// %56 = phi %"class.someclass" addrspace(4)* [ %49, %53 ], [ %49, %742 ]
223+
// the use iterator was handling such phi instructions twice.
224+
// This was causing a crash since propagate function might erase instructions.
225+
DenseSet<Instruction*> instructionSet;
226+
DenseSet<Use*> useSet;
227+
for (auto UI = CI->use_begin(), UE = CI->use_end(); UI != UE; ++UI) {
228+
Use* U = &(*UI);
229+
Instruction* I = cast<Instruction>(U->getUser());
230+
if (instructionSet.find(I) == instructionSet.end())
231+
{
232+
instructionSet.insert(I);
233+
useSet.insert(U);
234+
}
235+
}
221236
// Propagate that source through all users of this cast.
222-
for (auto UI = CI->use_begin(), UE = CI->use_end(); UI != UE; /* EMPTY */) {
223-
Use& U = *UI++; // Propagation may invalidate the use list.
224-
Changed |= Propagator->propagate(&U, Src);
237+
for (auto it = useSet.begin(); it != useSet.end(); ++it) {
238+
Use* U = *it;
239+
Changed |= Propagator->propagate(U, Src);
225240
}
226241
// Re-update next instruction once there's change.
227242
if (Changed)

0 commit comments

Comments
 (0)