Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues related to the purity modeling PR #44314

Open
gbaraldi opened this issue Feb 23, 2022 · 6 comments
Open

Issues related to the purity modeling PR #44314

gbaraldi opened this issue Feb 23, 2022 · 6 comments
Labels
compiler:codegen Generation of LLVM IR and native code domain:building Build system, or building Julia or its dependencies system:apple silicon Affects Apple Silicon only (Darwin/ARM64) - e.g. M1 and other M-series chips

Comments

@gbaraldi
Copy link
Member

gbaraldi commented Feb 23, 2022

This is more of a reminding issue than something to hold up development.

The PR causes an LLVM error in the CodeInstances ccall in boot.jl when building in the M1, this might be related to the fact that the codeinstances struct uses a nested anonymous union. (This has a hacky fix for now, see #44279 and #44107 for details)

The same union also causes warnings when building with clang and apparently violates TBAA. (see #44255)

Edit:

This is what tells LLVM that it can't do a tailcall for the CodeInstances ccall https://github.com/JuliaLang/llvm-project/blob/bc5644ee74f4cb42042257ac129d2be1c252e3f2/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp#L5935

@gbaraldi
Copy link
Member Author

To debug the M1 issue I used an llvm build with some debug prints added, see Make.user:

override LLVM_SHA1=8480406c80c0bf5f7288b07d0df4a030319c5a14
USE_BINARYBUILDER_LLVM=0
LLVM_GIT_URL=https://github.com/gbaraldi/llvm-project.git
LLVM_BRANCH=add-debug
LLVM_ASSERTIONS=1
LLVM_DEBUG=Release

@JeffBezanson
Copy link
Sponsor Member

Could you paste the error output? I'm also not sure what you mean about CodeInstance:

julia> fieldtypes(Core.CodeInstance)
(Core.MethodInstance, Core.CodeInstance, UInt64, UInt64, Any, Any, Any, UInt8, UInt8, Any, Bool, Bool, Ptr{Nothing}, Ptr{Nothing}, UInt8)

What is the union you're referring to?

@gbaraldi
Copy link
Member Author

gbaraldi commented Feb 23, 2022

The union is in C

julia/src/julia.h

Lines 377 to 426 in 1b47efb

typedef struct _jl_code_instance_t {
JL_DATA_TYPE
jl_method_instance_t *def; // method this is specialized from
_Atomic(struct _jl_code_instance_t*) next; // pointer to the next cache entry
// world range for which this object is valid to use
size_t min_world;
size_t max_world;
// inference state cache
jl_value_t *rettype; // return type for fptr
jl_value_t *rettype_const; // inferred constant return value, or null
jl_value_t *inferred; // inferred jl_code_info_t, or jl_nothing, or null
//TODO: jl_array_t *edges; // stored information about edges from this object
//TODO: uint8_t absolute_max; // whether true max world is unknown
// purity results
union {
uint8_t ipo_purity_bits;
struct {
uint8_t ipo_consistent:2;
uint8_t ipo_effect_free:2;
uint8_t ipo_nothrow:2;
uint8_t ipo_terminates:2;
} ipo_purity_flags;
};
union {
uint8_t purity_bits;
struct {
uint8_t consistent:2;
uint8_t effect_free:2;
uint8_t nothrow:2;
uint8_t terminates:2;
} purity_flags;
};
jl_value_t *argescapes; // escape information of call arguments
// compilation state cache
uint8_t isspecsig; // if specptr is a specialized function signature for specTypes->rettype
_Atomic(uint8_t) precompile; // if set, this will be added to the output system image
_Atomic(jl_callptr_t) invoke; // jlcall entry point
union _jl_generic_specptr_t {
_Atomic(void*) fptr;
_Atomic(jl_fptr_args_t) fptr1;
// 2 constant
_Atomic(jl_fptr_sparam_t) fptr3;
// 4 interpreter
} specptr; // private data for `jlcall entry point
uint8_t relocatability; // nonzero if all roots are built into sysimg or tagged by module key
} jl_code_instance_t;
and it used to fail when this was called

julia/base/boot.jl

Lines 421 to 431 in 1b47efb

function CodeInstance(
mi::MethodInstance, @nospecialize(rettype), @nospecialize(inferred_const),
@nospecialize(inferred), const_flags::Int32, min_world::UInt, max_world::UInt,
ipo_effects::UInt8, effects::UInt8, @nospecialize(argescapes#=::Union{Nothing,Vector{ArgEscapeInfo}}=#),
relocatability::UInt8)
return ccall(:jl_new_codeinst, Ref{CodeInstance},
(Any, Any, Any, Any, Int32, UInt, UInt, UInt8, UInt8, Any, UInt8),
mi, rettype, inferred_const, inferred, const_flags, min_world, max_world,
ipo_effects, effects, argescapes,
relocatability)
end

The error output came from deep in LLVM but it's

LLVM ERROR: failed to perform tail call elimination on a call site marked musttail

@JeffBezanson
Copy link
Sponsor Member

Thanks.

@ViralBShah ViralBShah added system:apple silicon Affects Apple Silicon only (Darwin/ARM64) - e.g. M1 and other M-series chips domain:building Build system, or building Julia or its dependencies compiler:codegen Generation of LLVM IR and native code labels Feb 24, 2022
@giordano
Copy link
Contributor

giordano commented Apr 6, 2022

@gbaraldi can you check whether #44807 helps?

@gbaraldi
Copy link
Member Author

gbaraldi commented Apr 6, 2022

It does not unfortunately

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:codegen Generation of LLVM IR and native code domain:building Build system, or building Julia or its dependencies system:apple silicon Affects Apple Silicon only (Darwin/ARM64) - e.g. M1 and other M-series chips
Projects
None yet
Development

No branches or pull requests

4 participants