Skip to content

Commit bb5a09f

Browse files
authored
Merge pull request #37430 from JuliaLang/vc/phi_late-gc
[LateGCLowering] Look through Phi node
2 parents a108d6c + 38e2df9 commit bb5a09f

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/llvm-late-gc-lowering.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1458,7 +1458,33 @@ State LateLowerGCFrame::LocalScan(Function &F) {
14581458
S.ArrayAllocas[SRet] = tracked.count * cast<ConstantInt>(SRet->getArraySize())->getZExtValue();
14591459
}
14601460
else {
1461-
AllocaInst *SRet_gc = dyn_cast<AllocaInst>((CI->arg_begin()[1])->stripInBoundsOffsets());
1461+
Value *arg1 = (CI->arg_begin()[1])->stripInBoundsOffsets();
1462+
AllocaInst *SRet_gc = nullptr;
1463+
if (PHINode *Phi = dyn_cast<PHINode>(arg1)) {
1464+
for (Value *V : Phi->incoming_values()) {
1465+
if (AllocaInst *Alloca = dyn_cast<AllocaInst>(V->stripInBoundsOffsets())) {
1466+
if (SRet_gc == nullptr) {
1467+
SRet_gc = Alloca;
1468+
} else if (SRet_gc == Alloca) {
1469+
continue;
1470+
} else {
1471+
llvm_dump(Alloca);
1472+
llvm_dump(SRet_gc);
1473+
assert(false && "Allocas in Phi node should match");
1474+
}
1475+
} else {
1476+
llvm_dump(V->stripInBoundsOffsets());
1477+
assert(false && "Expected alloca");
1478+
}
1479+
}
1480+
} else {
1481+
SRet_gc = dyn_cast<AllocaInst>(arg1);
1482+
}
1483+
if (!SRet_gc) {
1484+
llvm_dump(CI);
1485+
llvm_dump(arg1);
1486+
assert(false && "Expected alloca");
1487+
}
14621488
Type *ElT = SRet_gc->getAllocatedType();
14631489
if (!(SRet_gc->isStaticAlloca() && isa<PointerType>(ElT) && ElT->getPointerAddressSpace() == AddressSpace::Tracked)) {
14641490
S.ArrayAllocas[SRet_gc] = tracked.count * cast<ConstantInt>(SRet_gc->getArraySize())->getZExtValue();

0 commit comments

Comments
 (0)