Skip to content

Commit d1c62d3

Browse files
gbaraldiZentrik
authored andcommitted
Fix late gc lowering issue
1 parent 0deb8fc commit d1c62d3

File tree

2 files changed

+42
-12
lines changed

2 files changed

+42
-12
lines changed

src/llvm-late-gc-lowering.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,22 +1219,18 @@ State LateLowerGCFrame::LocalScan(Function &F) {
12191219
else {
12201220
Value *arg1 = (CI->arg_begin()[1])->stripInBoundsOffsets();
12211221
SmallSetVector<AllocaInst *, 8> gc_allocas = FindSretAllocas(arg1);
1222-
AllocaInst *SRet_gc = nullptr;
1223-
if (gc_allocas.size() == 1) {
1224-
SRet_gc = gc_allocas.pop_back_val();
1222+
if (gc_allocas.size() == 0) {
1223+
llvm_dump(CI);
1224+
assert(false && "Expected at least one alloca");
12251225
}
12261226
else {
1227-
llvm_dump(CI);
1228-
for (AllocaInst *Alloca : gc_allocas) {
1229-
llvm_dump(Alloca);
1227+
for (AllocaInst* SRet_gc : gc_allocas) {
1228+
Type *ElT = SRet_gc->getAllocatedType();
1229+
if (!(SRet_gc->isStaticAlloca() && isa<PointerType>(ElT) && ElT->getPointerAddressSpace() == AddressSpace::Tracked)) {
1230+
S.ArrayAllocas[SRet_gc] = tracked.count * cast<ConstantInt>(SRet_gc->getArraySize())->getZExtValue();
1231+
}
12301232
}
1231-
assert(false && "Expected single alloca");
1232-
}
1233-
Type *ElT = SRet_gc->getAllocatedType();
1234-
if (!(SRet_gc->isStaticAlloca() && isa<PointerType>(ElT) && ElT->getPointerAddressSpace() == AddressSpace::Tracked)) {
1235-
S.ArrayAllocas[SRet_gc] = tracked.count * cast<ConstantInt>(SRet_gc->getArraySize())->getZExtValue();
12361233
}
1237-
break; // Found our gc roots
12381234
}
12391235
}
12401236
}

test/llvmpasses/late-lower-gc-sret.ll

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,37 @@ ret: ; preds = %false, %true
4747
; CHECK: call void @julia.pop_gc_frame(ptr %gcframe)
4848
ret ptr addrspace(10) %1
4949
}
50+
51+
declare swiftcc void @sret_call_gc(ptr noalias nocapture noundef sret({ ptr addrspace(10), i64, i64 }), ptr noalias nocapture noundef, ptr nonnull swiftself)
52+
53+
declare ptr @julia.get_pgcstack()
54+
55+
define hidden swiftcc void @sret_gc_root_phi(ptr nonnull swiftself %0, i1 %unpredictable) {
56+
top:
57+
; CHECK-LABEL: @sret_gc_root_phi
58+
; CHECK: %gcframe = call ptr @julia.new_gc_frame(i32 2)
59+
; CHECK: call ptr @julia.get_gc_frame_slot(ptr %gcframe, i32 1)
60+
; CHECK: call ptr @julia.get_gc_frame_slot(ptr %gcframe, i32 0)
61+
; CHECK: %pgcstack = call ptr @julia.get_pgcstack()
62+
; CHECK: call void @julia.push_gc_frame(ptr %gcframe, i32 2)
63+
; CHECK: alloca [3 x i64], align 8
64+
%pgcstack = call ptr @julia.get_pgcstack()
65+
%1 = alloca [3 x i64], align 8
66+
%2 = alloca ptr addrspace(10), align 8
67+
%3 = alloca ptr addrspace(10), align 8
68+
store i64 0, ptr %2, align 8
69+
store i64 0, ptr %3, align 8
70+
br i1 %unpredictable, label %true, label %false
71+
72+
true: ; preds = %top
73+
br label %ret
74+
75+
false: ; preds = %top
76+
br label %ret
77+
78+
ret: ; preds = %false, %true
79+
%4 = phi ptr [ %2, %true ], [ %3, %false ]
80+
call swiftcc void @sret_call_gc(ptr noalias nocapture noundef sret({ ptr addrspace(10), i64, i64 }) %1, ptr noalias nocapture noundef %4, ptr nonnull swiftself %0)
81+
; CHECK: call void @julia.pop_gc_frame(ptr %gcframe)
82+
ret void
83+
}

0 commit comments

Comments
 (0)