From 68cda2ef15ee1956b28b785fbcfa98c902f11ce4 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 | 5 ++--- src/codegen.cpp | 32 +++++++++++++++++++++++--------- test/compiler/codegen.jl | 2 +- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/cgutils.cpp b/src/cgutils.cpp index 8e3fb0ee34909e..1cabee9412c620 100644 --- a/src/cgutils.cpp +++ b/src/cgutils.cpp @@ -1240,8 +1240,7 @@ static void recombine_value(jl_codectx_t &ctx, const jl_cgval_t &x, Value *dst, { jl_datatype_t *typ = (jl_datatype_t*)x.typ; assert(jl_is_concrete_type(x.typ)); - bool hasptr = typ->layout->first_ptr >= 0; - assert(hasptr && x.inline_roots != nullptr); + assert(typ->layout->first_ptr >= 0 && x.inline_roots != nullptr); Align align_dst = alignment; Align align_src(1); // TODO: compute this (and keep aligned) Value *src = x.V; @@ -4201,7 +4200,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 3bd3c1f2622fbb..7190f9db81b741 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -6190,11 +6190,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)); + } } } } @@ -8421,7 +8432,7 @@ static jl_llvm_functions_t // step 7. allocate local variables slots // must be in the first basic block for the llvm mem2reg pass to work - auto allocate_local = [&ctx, &dbuilder, &debugcache, topdebugloc, va, debug_enabled, M](jl_varinfo_t &varinfo, jl_sym_t *s, int i) { + auto allocate_local = [&ctx, &dbuilder, &debugcache, topdebugloc, va, debug_enabled](jl_varinfo_t &varinfo, jl_sym_t *s, int i) { jl_value_t *jt = varinfo.value.typ; assert(!varinfo.boxroot); // variables shouldn't have memory locs already if (varinfo.value.constant) { @@ -9601,15 +9612,19 @@ 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); + (void)SRU; + } + else if (MemSetInst *MSI = dyn_cast(RU)) { + assert(MSI->getValue() == ctx.builder.getInt8(0)); + (void)MSI; } else if (isa(RU)) { } @@ -9631,7 +9646,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 6137be3cac936f..c5edf2deb412b3 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