Skip to content

Commit c3fc367

Browse files
authored
codegen: improve our argument annotations (#35463)
Reflect that immutable struct parameters are readonly by the time LLVM can see them, even passed inside boxes. LLVM seems to require an explicit additional LICM call, to avoid regressions from this (observing the scheduling of fewer LICM calls).
1 parent ac09f10 commit c3fc367

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/aotcompile.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,7 @@ void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level,
676676
PM->add(createLowerSimdLoopPass()); // Annotate loop marked with "loopinfo" as LLVM parallel loop
677677
PM->add(createLICMPass());
678678
PM->add(createLoopUnswitchPass());
679+
PM->add(createLICMPass());
679680
// Subsequent passes not stripping metadata from terminator
680681
PM->add(createInstSimplifyLegacyPass());
681682
PM->add(createIndVarSimplifyPass());

src/codegen.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -4997,7 +4997,8 @@ static jl_returninfo_t get_specsig_function(jl_codectx_t &ctx, Module *M, String
49974997
jl_value_t *jt = jl_tparam(sig, i);
49984998
if (is_uniquerep_Type(jt))
49994999
continue;
5000-
Type *ty = deserves_argbox(jt) ? T_prjlvalue : julia_type_to_llvm(ctx, jt);
5000+
bool isboxed = deserves_argbox(jt);
5001+
Type *ty = isboxed ? T_prjlvalue : julia_type_to_llvm(ctx, jt);
50015002
if (type_is_ghost(ty))
50025003
continue;
50035004
unsigned argno = fsig.size();
@@ -5006,6 +5007,9 @@ static jl_returninfo_t get_specsig_function(jl_codectx_t &ctx, Module *M, String
50065007
attributes = attributes.addParamAttribute(jl_LLVMContext, argno, Attribute::ReadOnly);
50075008
ty = PointerType::get(ty, AddressSpace::Derived);
50085009
}
5010+
else if (isboxed && jl_is_immutable_datatype(jt)) {
5011+
attributes = attributes.addParamAttribute(jl_LLVMContext, argno, Attribute::ReadOnly);
5012+
}
50095013
fsig.push_back(ty);
50105014
}
50115015

@@ -5581,6 +5585,8 @@ static std::pair<std::unique_ptr<Module>, jl_llvm_functions_t>
55815585
if (isboxed) // e.g. is-pointer
55825586
maybe_mark_argument_dereferenceable(Arg, argType);
55835587
theArg = mark_julia_type(ctx, Arg, isboxed, argType);
5588+
if (theArg.tbaa == tbaa_immut)
5589+
theArg.tbaa = tbaa_const;
55845590
}
55855591
return theArg;
55865592
};

0 commit comments

Comments
 (0)