Skip to content

Commit dbecbe8

Browse files
committed
fixes
1 parent aa5a376 commit dbecbe8

File tree

5 files changed

+16
-9
lines changed

5 files changed

+16
-9
lines changed

base/atomics.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ atomic_and!(x::Atomic, v) = (@atomic :acquire_release x.value & v).first
310310
atomic_or!(x::Atomic, v) = (@atomic :acquire_release x.value | v).first
311311
atomic_xor!(x::Atomic, v) = (@atomic :acquire_release x.value v).first
312312
atomic_nand!(x::Atomic, v) = (@atomic :acquire_release x.value nand v).first
313-
atomic_xchg!(x::Atomic, v) = (@atomic :acquire_release x.value ((old,new)->new) v).first
313+
atomic_xchg!(x::Atomic, v) = (@atomicswap :acquire_release x.value = v)
314314
atomic_min!(x::Atomic, v) = (@atomic :acquire_release x.value min v).first
315315
atomic_max!(x::Atomic, v) = (@atomic :acquire_release x.value max v).first
316316

src/aotcompile.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ static void resolve_workqueue(jl_codegen_params_t &params, egal_set &method_root
487487
}
488488
if (!preal_decl.empty()) {
489489
// merge and/or rename this prototype to the real function
490-
if (Function *specfun = cast<Function>(mod->getNamedValue(preal_decl))) {
490+
if (Function *specfun = cast_or_null<Function>(mod->getNamedValue(preal_decl))) {
491491
if (proto.decl != specfun) {
492492
proto.decl->replaceAllUsesWith(specfun);
493493
if (proto.decl->hasFnAttribute(Attribute::InlineHint))
@@ -512,7 +512,7 @@ static void resolve_workqueue(jl_codegen_params_t &params, egal_set &method_root
512512
assert(ocinvokeDecl != "jl_fptr_const_return");
513513
assert(ocinvokeDecl != "jl_fptr_sparam");
514514
// merge and/or rename this prototype to the real function
515-
if (Function *specfun = cast<Function>(mod->getNamedValue(ocinvokeDecl))) {
515+
if (Function *specfun = cast_or_null<Function>(mod->getNamedValue(ocinvokeDecl))) {
516516
if (proto.oc != specfun) {
517517
proto.oc->replaceAllUsesWith(specfun);
518518
if (proto.oc->hasFnAttribute(Attribute::InlineHint))

src/cgutils.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/jitlayers.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ static int jl_analyze_workqueue(jl_code_instance_t *callee, jl_codegen_params_t
463463
}
464464
if (!preal_decl.empty()) {
465465
// merge and/or rename this prototype to the real function
466-
if (Function *specfun = cast<Function>(mod->getNamedValue(preal_decl))) {
466+
if (Function *specfun = cast_or_null<Function>(mod->getNamedValue(preal_decl))) {
467467
if (proto.decl != specfun) {
468468
proto.decl->replaceAllUsesWith(specfun);
469469
if (!proto.decl->isDeclaration() && specfun->isDeclaration())
@@ -505,7 +505,7 @@ static int jl_analyze_workqueue(jl_code_instance_t *callee, jl_codegen_params_t
505505
assert(ocinvokeDecl != "jl_fptr_args");
506506
assert(ocinvokeDecl != "jl_fptr_sparam");
507507
// merge and/or rename this prototype to the real function
508-
if (Function *specfun = cast<Function>(mod->getNamedValue(ocinvokeDecl))) {
508+
if (Function *specfun = cast_or_null<Function>(mod->getNamedValue(ocinvokeDecl))) {
509509
if (proto.oc != specfun) {
510510
proto.oc->replaceAllUsesWith(specfun);
511511
proto.oc->eraseFromParent();

src/llvm-expand-atomic-modify.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ std::pair<Value *, Value *> insertRMWCmpXchgLoop(
112112
std::prev(BB->end())->eraseFromParent();
113113
Builder.SetInsertPoint(BB);
114114
LoadInst *InitLoaded = Builder.CreateAlignedLoad(ResultTy, Addr, AddrAlign);
115+
InitLoaded->setOrdering(AtomicOrdering::Unordered); // n.b. the original LLVM pass is missing this call so is actually mildly UB
115116
Builder.CreateBr(LoopBB);
116117

117118
// Start the main loop block now that we've taken care of the preliminaries.

0 commit comments

Comments
 (0)