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

LLVM assertion failure caused by exct modeling #52808

Closed
maleadt opened this issue Jan 8, 2024 · 7 comments
Closed

LLVM assertion failure caused by exct modeling #52808

maleadt opened this issue Jan 8, 2024 · 7 comments
Labels
compiler:codegen Generation of LLVM IR and native code regression Regression in behavior compared to a previous version
Milestone

Comments

@maleadt
Copy link
Member

maleadt commented Jan 8, 2024

As seen on PkgEval during testing of SLEEFPirates.jl: https://s3.amazonaws.com/julialang-reports/nanosoldier/pkgeval/by_date/2024-01/07/SLEEFPirates.primary.log

julia: /source/src/codegen.cpp:8808: jl_llvm_functions_t emit_function(llvm::orc::ThreadSafeModule&, jl_method_instance_t*, jl_code_info_t*, jl_value_t*, jl_codegen_params_t&): Assertion `jl_egal_((value), (jl_array_ptr_ref(values, j)))' failed.

[2958221] signal 6 (-6): Aborted
in expression starting at /home/maleadt/julia/wip.jl:29
pthread_kill at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
raise at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
abort at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
unknown function (ip: 0x7fe693e9771a)
__assert_fail at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
emit_function at /source/src/codegen.cpp:8808
jl_emit_code at /source/src/codegen.cpp:9090
jl_emit_codeinst at /source/src/codegen.cpp:9173
_jl_compile_codeinst at /source/src/jitlayers.cpp:220
jl_generate_fptr_impl at /source/src/jitlayers.cpp:525
jl_compile_method_internal at /source/src/gf.c:2493 [inlined]
jl_compile_method_internal at /source/src/gf.c:2381
_jl_invoke at /source/src/gf.c:2896 [inlined]
ijl_apply_generic at /source/src/gf.c:3086

MWE:

struct Double{T}
  hi::T
  lo
end
@inline function bar(::Double{V}, x::Double{V}) where V
  T = s = x.hi
  t = x
  if T <: Float64
    t = ifelse(s < 0, s, t)
  end
  0 * t
end
function foo()
  bar(Double(0,0), wat)
end
foo()

Bisected to #51754; cc @Keno.

@maleadt maleadt added regression Regression in behavior compared to a previous version compiler:codegen Generation of LLVM IR and native code labels Jan 8, 2024
@maleadt maleadt added this to the 1.11 milestone Jan 8, 2024
@oscardssmith
Copy link
Member

I can't reproduce this on 5 day old master. Is it possibly already fixed?

@maleadt
Copy link
Member Author

maleadt commented Jan 8, 2024

Are you using an assertions build?

@oscardssmith
Copy link
Member

that would be the reason.

@gbaraldi
Copy link
Member

gbaraldi commented Jan 9, 2024

So weirdly, if I do a debug assert+llvm_assert I get

Internal error: during type inference of
foo()
Encountered unexpected error in runtime:
ErrorException("")
error at ./error.jl:35
verify_ir at ./compiler/ssair/verify.jl:277
run_passes_ipo_safe at ./compiler/optimize.jl:938
run_passes_ipo_safe at ./compiler/optimize.jl:923 [inlined]
optimize at ./compiler/optimize.jl:897
jfptr_optimize_38647 at /home/gabrielbaraldi/julia5/usr/lib/julia/sys-debug.so (unknown line)
_jl_invoke at /home/gabrielbaraldi/julia5/src/gf.c:2902
ijl_apply_generic at /home/gabrielbaraldi/julia5/src/gf.c:3098
_typeinf at ./compiler/typeinfer.jl:264
typeinf at ./compiler/typeinfer.jl:216
typeinf_edge at ./compiler/typeinfer.jl:870
abstract_call_method at ./compiler/abstractinterpretation.jl:654
abstract_call_gf_by_type at ./compiler/abstractinterpretation.jl:102
abstract_call_known at ./compiler/abstractinterpretation.jl:2168
abstract_call at ./compiler/abstractinterpretation.jl:2250
abstract_call at ./compiler/abstractinterpretation.jl:2243
abstract_call at ./compiler/abstractinterpretation.jl:2388
abstract_eval_call at ./compiler/abstractinterpretation.jl:2403
abstract_eval_statement_expr at ./compiler/abstractinterpretation.jl:2419
abstract_eval_statement at ./compiler/abstractinterpretation.jl:2724
abstract_eval_basic_statement at ./compiler/abstractinterpretation.jl:3035
typeinf_local at ./compiler/abstractinterpretation.jl:3289
typeinf_nocycle at ./compiler/abstractinterpretation.jl:3365
_typeinf at ./compiler/typeinfer.jl:246
typeinf at ./compiler/typeinfer.jl:216
typeinf_ext at ./compiler/typeinfer.jl:1042
typeinf_ext_toplevel at ./compiler/typeinfer.jl:1080
typeinf_ext_toplevel at ./compiler/typeinfer.jl:1076
...

With

Edge 1 of φ node 6 not in predecessor list
2 1%1  = Base.getfield(_3, :hi)::Int64                                                                                                    │╻ getproperty
4 └──       (%1 <: Main.Float64)::Core.Const(true)                                                                                           │ 
5 2%3  = Base.slt_int(%1, 0)::Bool                                                                                                        │╻ <%4  = Core.ifelse(%3, %1, _3)::Union{Int64, Double{Int64}}                                                                             │╻ ifelse
  └── %5  = Core.ifelse(%3, true, false)::Bool                                                                                               ││
7 3%6  = φ (#2 => %5, #1 => false)::Bool                                                                                                  │ %7  = φ (#2 => %4, #1 => _3)::Union{Int64, Double{Int64}}                                                                              │ 
  └──       goto #5 if not %6                                                                                                                │ 
  4%9  = π (%7, Int64)                                                                                                                    │ 
  │   %10 = Base.mul_int(0, %9)::Int64                                                                                                       │╻ *
  └──       goto #6                                                                                                                          │ 
  5%12 = (0 * %7)::Int64                                                                                                                  │ 
  └──       goto #6                                                                                                                          │ 
  6%14 = φ (#4 => %10, #5 => %12)::Int64                                                                                                  │ 
  └──       return %14   

@maleadt
Copy link
Member Author

maleadt commented Jan 9, 2024

So weirdly, if I do a debug assert+llvm_assert I get

That's not weird; IR verification is only enabled on a debug build (which defaults to -g2):

if JLOptions().debug_level == 2
@timeit "verify 3" (verify_ir(ir, true, false, optimizer_lattice(sv.inlining.interp)); verify_linetable(ir.linetable))
end

@gbaraldi
Copy link
Member

gbaraldi commented Jan 9, 2024

Hmm, that seems like a weird thing to switch on. Maybe we should check if FORCE_ASSERTIONS was on instead?

@maleadt
Copy link
Member Author

maleadt commented Jan 12, 2024

Fixed on master; probably by #52853

@maleadt maleadt closed this as completed Jan 12, 2024
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 regression Regression in behavior compared to a previous version
Projects
None yet
Development

No branches or pull requests

3 participants