-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Avoid boxing variables that may be used undef #18732
Conversation
@@ -490,6 +490,9 @@ struct jl_varinfo_t { | |||
#else | |||
DIVariable dinfo; | |||
#endif | |||
// if the variable might be used undefined and is not boxed | |||
// this i1 flag is true when it is defined | |||
Value *undefFlag; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest calling it defFlag
to avoid double negatives :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, that was gratuitously confusing
Awesome; this has been a long time coming. |
static void alloc_undef_flag(jl_varinfo_t& vi, jl_codectx_t* ctx) | ||
{ | ||
if (vi.usedUndef) { | ||
vi.undefFlag = emit_static_alloca(T_int1, ctx); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only need this if the slot is a isbits
type right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or a constant. It should only be called in those cases. I'll add an assertion.
we need to remember to do this more often: @nanosoldier |
Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @jrevels |
@@ -737,6 +741,22 @@ static jl_sym_t *slot_symbol(int s, jl_codectx_t *ctx) | |||
return (jl_sym_t*)jl_array_ptr_ref(ctx->source->slotnames, s); | |||
} | |||
|
|||
static void store_undef_flag(const jl_varinfo_t &vi, bool val) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't these accessors be called store_def_flag
now?
builder.CreateStore(ConstantInt::get(T_int1, val), vi.defFlag); | ||
} | ||
|
||
static void alloc_undef_flag(jl_varinfo_t& vi, jl_codectx_t* ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same: alloc_undef_flag
=> alloc_def_flag
Bump. Just needs a bit more renaming, then good to go. |
f659d26
to
9231c93
Compare
Ok, did it myself :P |
Fixes #6914 |
I think there was a bug in this.
CodeInfo(code=Array{Any, 1}[
# line 312,
Expr(:meta, :push_loc, :multidimensional.jl)::Any,
# line 315,
SlotNumber(id=10) = SlotNumber(id=3),
SlotNumber(id=8) = SlotNumber(id=1),
SlotNumber(id=9) = SlotNumber(id=2),
SlotNumber(id=11) = SlotNumber(id=4),
SlotNumber(id=5) = Expr(:call, Base.to_index, Expr(:call, Base.getindex, SlotNumber(id=11), 1)::Any)::Any,
# line 316,
SlotNumber(id=6) = Expr(:call, Base.index_shape, SlotNumber(id=10), SlotNumber(id=5))::Any,
# line 317,
SlotNumber(id=7) = Expr(:call, Base.similar, SlotNumber(id=10), SlotNumber(id=6))::Any,
# line 318,
SSAValue(0) = Expr(:call, Base.==, Expr(:call, Base.map, Base.unsafe_length, Expr(:call, Base.indices, SlotNumber(id=7))::Any)::Any, Expr(:call, Base.map, Base.unsafe_length, SlotNumber(id=6))::Any)::Any,
Expr(:gotoifnot, SSAValue(0), 17)::Any,
goto 19,
17:,
Expr(:call, Base.throw_checksize_error, SlotNumber(id=7), SlotNumber(id=6))::Any,
19:,
# line 319,
SSAValue(1) = Expr(:call, Base._unsafe_getindex!, SlotNumber(id=7), SlotNumber(id=10), SlotNumber(id=5))::Any,
Expr(:meta, :pop_loc)::Any,
Expr(:return, SSAValue(1))::Any], slottypes=nothing, ssavaluetypes=2, slotnames=Array{Any, 1}[
:#self#,
:#unused#,
:A,
:I,
:I_1,
:shape,
:dest,
:#self#,
:#unused#,
:A,
:I], slotflags=Array{UInt8, 1}[0x02, 0x02, 0x02, 0x02, 0x12, 0x12, 0x12, 0x02, 0x02, 0x02, 0x02], inferred=false, inlineable=false, propagate_inbounds=false, pure=false) |
I have a fix. |
use a separate
i1
flag so that we avoid boxing and give visibility to llvm in the defined/undefined dataflow, to remove redundant branches etcgives