Skip to content

Commit 92a8010

Browse files
jrbyrnesyuxuanchen1997
authored andcommitted
[AMDGPU] Protect against null entries in ValMap
Change-Id: Icbda7c3fecf38679d06006986e5e17cb1f1b8749
1 parent 59acbab commit 92a8010

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

llvm/lib/Target/AMDGPU/AMDGPULateCodeGenPrepare.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ bool LiveRegOptimizer::optimizeLiveType(
360360
Type *NewType = calculateConvertType(Phi->getType());
361361
NewPhi->addIncoming(ConstantInt::get(NewType, 0, false),
362362
Phi->getIncomingBlock(I));
363-
} else if (ValMap.contains(IncVal))
363+
} else if (ValMap.contains(IncVal) && ValMap[IncVal])
364364
NewPhi->addIncoming(ValMap[IncVal], Phi->getIncomingBlock(I));
365365
else
366366
MissingIncVal = true;
@@ -370,11 +370,11 @@ bool LiveRegOptimizer::optimizeLiveType(
370370
// The coercion chain of the PHI is broken. Delete the Phi
371371
// from the ValMap and any connected / user Phis.
372372
SmallVector<Value *, 4> PHIWorklist;
373-
SmallPtrSet<Value *, 4> Visited;
373+
SmallPtrSet<Value *, 4> VisitedPhis;
374374
PHIWorklist.push_back(DeadVal);
375375
while (!PHIWorklist.empty()) {
376376
Value *NextDeadValue = PHIWorklist.pop_back_val();
377-
Visited.insert(NextDeadValue);
377+
VisitedPhis.insert(NextDeadValue);
378378
auto OriginalPhi =
379379
std::find_if(PhiNodes.begin(), PhiNodes.end(),
380380
[this, &NextDeadValue](PHINode *CandPhi) {
@@ -388,7 +388,7 @@ bool LiveRegOptimizer::optimizeLiveType(
388388
DeadInsts.emplace_back(cast<Instruction>(NextDeadValue));
389389

390390
for (User *U : NextDeadValue->users()) {
391-
if (!Visited.contains(cast<PHINode>(U)))
391+
if (!VisitedPhis.contains(cast<PHINode>(U)))
392392
PHIWorklist.push_back(U);
393393
}
394394
}

0 commit comments

Comments
 (0)