From e3f5ea0047349095a31e253ffb58a17cdd7397a9 Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Fri, 13 Sep 2024 19:18:29 +0000 Subject: [PATCH] bugfix --- src/cgutils.cpp | 2 +- src/codegen.cpp | 28 ++++++++++++++++++++-------- test/compiler/codegen.jl | 2 +- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/cgutils.cpp b/src/cgutils.cpp index 8e3fb0ee34909e..c9beb40a7e4744 100644 --- a/src/cgutils.cpp +++ b/src/cgutils.cpp @@ -4201,7 +4201,7 @@ static jl_cgval_t emit_new_struct(jl_codectx_t &ctx, jl_value_t *ty, size_t narg fval = boxed(ctx, fval_info, field_promotable); if (!init_as_value) { jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_stack); - ai.decorateInst(ctx.builder.CreateAlignedStore(fval, roots ? roots : dest, Align(jl_field_align(sty, i)))); + ai.decorateInst(ctx.builder.CreateAlignedStore(fval, roots ? roots : dest, Align(roots ? sizeof(void*) : jl_field_align(sty, i)))); } } else if (jl_is_uniontype(jtype)) { diff --git a/src/codegen.cpp b/src/codegen.cpp index d86aa7ba1eb875..68f27fa23d5f09 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -6187,11 +6187,22 @@ static void emit_upsilonnode(jl_codectx_t &ctx, ssize_t phic, jl_value_t *val) vi.pTIndex, Align(1), true); } else if (vi.value.V && !vi.value.constant && vi.value.typ != jl_bottom_type) { - assert(vi.value.ispointer()); - Type *T = cast(vi.value.V)->getAllocatedType(); - if (CountTrackedPointers(T).count) { + assert(vi.value.inline_roots || vi.value.ispointer()); + if (vi.value.inline_roots) { // memory optimization: make gc pointers re-initialized to NULL - ctx.builder.CreateStore(Constant::getNullValue(T), vi.value.V, true); + AllocaInst *ssaroots = cast(vi.value.inline_roots); + size_t nroots = cast(ssaroots->getArraySize())->getZExtValue(); + auto T_prjlvalue = ssaroots->getAllocatedType(); + if (auto AT = dyn_cast(T_prjlvalue)) { + nroots *= AT->getNumElements(); + T_prjlvalue = AT->getElementType(); + } + assert(T_prjlvalue == ctx.types().T_prjlvalue); + Value *nullval = Constant::getNullValue(T_prjlvalue); + auto stack_ai = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_stack); + for (size_t i = 0; i < nroots; i++) { + stack_ai.decorateInst(ctx.builder.CreateAlignedStore(nullval, emit_ptrgep(ctx, ssaroots, i * sizeof(void*)), ssaroots->getAlign(), true)); + } } } } @@ -9598,15 +9609,17 @@ static jl_llvm_functions_t if (ctx.vaSlot > 0) { // remove VA allocation if we never referenced it + assert(ctx.slots[ctx.vaSlot].isSA && ctx.slots[ctx.vaSlot].isArgument); Instruction *root = cast_or_null(ctx.slots[ctx.vaSlot].boxroot); if (root) { - Instruction *store_value = NULL; bool have_real_use = false; for (Use &U : root->uses()) { User *RU = U.getUser(); if (StoreInst *SRU = dyn_cast(RU)) { - if (!store_value) - store_value = dyn_cast(SRU->getValueOperand()); + assert(isa(SRU->getValueOperand()) || SRU->getValueOperand() == restTuple); + } + else if (MemSetInst *MSI = dyn_cast(RU)) { + assert(MSI->getValue() == ctx.builder.getInt8(0)); } else if (isa(RU)) { } @@ -9628,7 +9641,6 @@ static jl_llvm_functions_t if (use) use->eraseFromParent(); root->eraseFromParent(); - assert(!store_value || store_value == restTuple); restTuple->eraseFromParent(); } } diff --git a/test/compiler/codegen.jl b/test/compiler/codegen.jl index fa7532c5cc827d..f152407ea5b77f 100644 --- a/test/compiler/codegen.jl +++ b/test/compiler/codegen.jl @@ -501,7 +501,7 @@ function f37262(x) end end @testset "#37262" begin - str_opaque = "store volatile { i8, ptr, ptr, ptr, ptr } zeroinitializer, ptr %phic" + str_opaque = "getelementptr inbounds i8, ptr %.roots.phic, i32 16\n store volatile ptr null" llvmstr = get_llvm(f37262, (Bool,), false, false, false) @test contains(llvmstr, str_opaque) @test f37262(Base.inferencebarrier(true)) === nothing