Skip to content

Commit

Permalink
improve codegen of typecheck on first field of new structs
Browse files Browse the repository at this point in the history
prompted by #21323
  • Loading branch information
JeffBezanson committed Apr 11, 2017
1 parent df2438c commit ffcd934
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2315,24 +2315,24 @@ static jl_cgval_t emit_new_struct(jl_value_t *ty, size_t nargs, jl_value_t **arg
else
return mark_julia_slot(strct, ty, NULL, tbaa_stack);
}
Value *f1 = NULL;
bool have_f1_val = false;
jl_cgval_t f1_val;
size_t j = 0;
if (nf > 0 && jl_field_isptr(sty, 0) && nargs>1) {
// emit first field before allocating struct to save
// a couple store instructions. avoids initializing
// the first field to NULL, and sometimes the GC root
// for the new struct.
jl_cgval_t fval_info = emit_expr(args[1],ctx);
f1 = boxed(fval_info, ctx);
f1_val = emit_expr(args[1], ctx);
have_f1_val = true;
j++;
}
Value *strct = emit_allocobj(ctx, jl_datatype_size(sty),
literal_pointer_val((jl_value_t*)ty));
jl_cgval_t strctinfo = mark_julia_type(strct, true, ty, ctx);
if (f1) {
jl_cgval_t f1info = mark_julia_type(f1, true, jl_any_type, ctx);
emit_typecheck(f1info, jl_field_type(sty, 0), "new", ctx);
emit_setfield(sty, strctinfo, 0, f1info, ctx, false, false);
if (have_f1_val) {
emit_typecheck(f1_val, jl_field_type(sty, 0), "new", ctx);
emit_setfield(sty, strctinfo, 0, f1_val, ctx, false, false);
}
for (size_t i = j; i < nf; i++) {
if (jl_field_isptr(sty, i)) {
Expand Down

0 comments on commit ffcd934

Please sign in to comment.