@@ -2412,9 +2412,15 @@ static jl_cgval_t typed_store(jl_codectx_t &ctx,
24122412 instr = store;
24132413 }
24142414 else if (ismodifyfield && modifyop && !needlock && Order != AtomicOrdering::NotAtomic && !isboxed && realelty == elty && !intcast && elty->isIntegerTy () && !jl_type_hasptr (jltype)) {
2415- // emit this only if we have a possiblity of optimizing it
2415+ // emit this only if we have a possibility of optimizing it
24162416 if (Order == AtomicOrdering::Unordered)
24172417 Order = AtomicOrdering::Monotonic;
2418+ if (jl_is_pointerfree (rhs.typ ) && !rhs.isghost && (rhs.constant || rhs.isboxed || rhs.ispointer ())) {
2419+ // if this value can be loaded from memory, do that now so that it is sequenced before the atomicmodify
2420+ // and the IR is less dependent on what was emitted before now to create this rhs.
2421+ // Inlining should do okay to clean this up later if there are parts we don't need.
2422+ rhs = jl_cgval_t (emit_unbox (ctx, julia_type_to_llvm (ctx, rhs.typ ), rhs, rhs.typ ), rhs.typ , NULL );
2423+ }
24182424 bool gcstack_arg = JL_FEAT_TEST (ctx,gcstack_arg);
24192425 Function *op = emit_modifyhelper (ctx, cmpop, *modifyop, jltype, elty, rhs, fname, gcstack_arg);
24202426 std::string intr_name = " julia.atomicmodify.i" ;
@@ -2434,9 +2440,9 @@ static jl_cgval_t typed_store(jl_codectx_t &ctx,
24342440 Args.push_back (ctx.pgcstack );
24352441 auto oldnew = ctx.builder .CreateCall (intr, Args);
24362442 oldnew->addParamAttr (0 , Attribute::getWithAlignment (oldnew->getContext (), Align (alignment)));
2437- jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA (ctx, tbaa);
2438- ai.noalias = MDNode::concatenate (aliasscope, ai.noalias );
2439- ai.decorateInst (oldnew);
2443+ // jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, tbaa);
2444+ // ai.noalias = MDNode::concatenate(aliasscope, ai.noalias);
2445+ // ai.decorateInst(oldnew);
24402446 oldval = mark_julia_type (ctx, ctx.builder .CreateExtractValue (oldnew, 0 ), isboxed, jltype);
24412447 rhs = mark_julia_type (ctx, ctx.builder .CreateExtractValue (oldnew, 1 ), isboxed, jltype);
24422448 }
0 commit comments