Skip to content

Commit aefc51f

Browse files
pchintalapudiKristofferC
authored andcommitted
Initialize hoisted object allocations (#49584)
(cherry picked from commit 5032a1a)
1 parent db0b126 commit aefc51f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/llvm-julia-licm.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,20 @@ struct JuliaLICM : public JuliaPassContext {
290290
}
291291
changed = true;
292292
}
293+
IRBuilder<> builder(preheader->getTerminator());
294+
builder.SetCurrentDebugLocation(call->getDebugLoc());
295+
auto obj_i8 = builder.CreateBitCast(call, Type::getInt8PtrTy(call->getContext(), call->getType()->getPointerAddressSpace()));
296+
// Note that this alignment is assuming the GC allocates at least pointer-aligned memory
297+
auto align = Align(DL.getPointerSize(0));
298+
auto clear_obj = builder.CreateMemSet(obj_i8, ConstantInt::get(Type::getInt8Ty(call->getContext()), 0), call->getArgOperand(1), align);
299+
if (MSSAU.getMemorySSA()) {
300+
auto alloc_mdef = MSSAU.getMemorySSA()->getMemoryAccess(call);
301+
assert(isa<MemoryDef>(alloc_mdef) && "Expected alloc to be associated with a memory def!");
302+
auto clear_mdef = MSSAU.createMemoryAccessAfter(clear_obj, nullptr, alloc_mdef);
303+
assert(isa<MemoryDef>(clear_mdef) && "Expected memset to be associated with a memory def!");
304+
(void) clear_mdef;
305+
}
306+
changed = true;
293307
}
294308
}
295309
}

0 commit comments

Comments
 (0)