diff --git a/src/cgutils.cpp b/src/cgutils.cpp index 79837d80d8f43..93571db9bc808 100644 --- a/src/cgutils.cpp +++ b/src/cgutils.cpp @@ -4550,15 +4550,20 @@ static jl_cgval_t emit_const_len_memorynew(jl_codectx_t &ctx, jl_datatype_t *typ int pooled = tot <= GC_MAX_SZCLASS; Value *alloc, *decay_alloc, *ptr_field; + jl_aliasinfo_t aliasinfo; if (pooled) { auto cg_tot = ConstantInt::get(T_size, tot); auto call = prepare_call(jl_alloc_obj_func); alloc = ctx.builder.CreateCall(call, { ct, cg_tot, track_pjlvalue(ctx, cg_typ)}); decay_alloc = decay_derived(ctx, alloc); ptr_field = ctx.builder.CreateStructGEP(ctx.types().T_jlgenericmemory, decay_alloc, 1); + setName(ctx.emission_context, ptr_field, "memory_ptr"); auto objref = emit_pointer_from_objref(ctx, alloc); - Value *data = track_pjlvalue(ctx, emit_ptrgep(ctx, objref, JL_SMALL_BYTE_ALIGNMENT)); - ctx.builder.CreateAlignedStore(data, ptr_field, Align(sizeof(void*))); + Value *data = emit_ptrgep(ctx, objref, JL_SMALL_BYTE_ALIGNMENT); + auto *store = ctx.builder.CreateAlignedStore(data, ptr_field, Align(sizeof(void*))); + aliasinfo = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_memoryptr); + aliasinfo.decorateInst(store); + setName(ctx.emission_context, data, "memory_data"); } else { // just use the dynamic length version since the malloc will be slow anyway auto ptls = get_current_ptls(ctx); auto call = prepare_call(jl_alloc_genericmemory_unchecked_func); @@ -4567,7 +4572,10 @@ static jl_cgval_t emit_const_len_memorynew(jl_codectx_t &ctx, jl_datatype_t *typ } // set length (jl_alloc_genericmemory_unchecked_func doesn't have it) Value *len_field = ctx.builder.CreateStructGEP(ctx.types().T_jlgenericmemory, decay_alloc, 0); - ctx.builder.CreateStore(cg_nel, len_field); + auto *len_store = ctx.builder.CreateAlignedStore(cg_nel, len_field, Align(sizeof(void*))); + aliasinfo = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_memorylen); + aliasinfo.decorateInst(len_store); + // zeroinit pointers and unions if (zi) { ptr_field = ctx.builder.CreateStructGEP(ctx.types().T_jlgenericmemory, decay_alloc, 1); @@ -4651,7 +4659,9 @@ static jl_cgval_t emit_memorynew(jl_codectx_t &ctx, jl_datatype_t *typ, jl_cgval // set length (jl_alloc_genericmemory_unchecked_func doesn't have it) auto decay_alloc = maybe_decay_tracked(ctx, alloc); auto len_field = ctx.builder.CreateStructGEP(ctx.types().T_jlgenericmemory, decay_alloc, 0); - ctx.builder.CreateStore(nel_unboxed, len_field); + ctx.builder.CreateAlignedStore(nel_unboxed, len_field, Align(sizeof(void*))); + auto aliasinfo = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_memorylen); + aliasinfo.decorateInst(len_store); // zeroinit pointers and unions if (zi) { Value *ptr_field = ctx.builder.CreateStructGEP(ctx.types().T_jlgenericmemory, decay_alloc, 1); diff --git a/src/llvm-alloc-opt.cpp b/src/llvm-alloc-opt.cpp index fd2ee4cccfb34..e0f5126c8bbe1 100644 --- a/src/llvm-alloc-opt.cpp +++ b/src/llvm-alloc-opt.cpp @@ -758,7 +758,7 @@ void Optimizer::moveToStack(CallInst *orig_inst, size_t sz, bool has_ref, AllocF return; } if (pass.gc_loaded_func == callee) { - call->replaceAllUsesWith(new_i); + call->replaceAllUsesWith(prolog_builder.CreateAddrSpaceCast(new_i, call->getCalledFunction()->getReturnType())); call->eraseFromParent(); return; } diff --git a/src/pipeline.cpp b/src/pipeline.cpp index 236be179e12c9..4961579b3eb08 100644 --- a/src/pipeline.cpp +++ b/src/pipeline.cpp @@ -543,6 +543,7 @@ static void buildIntrinsicLoweringPipeline(ModulePassManager &MPM, PassBuilder * JULIA_PASS(FPM.addPass(LateLowerGCPass())); JULIA_PASS(FPM.addPass(FinalLowerGCPass())); if (O.getSpeedupLevel() >= 2) { + FPM.addPass(DSEPass()); FPM.addPass(GVNPass()); FPM.addPass(SCCPPass()); FPM.addPass(DCEPass());