Skip to content

Commit

Permalink
[mono][interp] Reduce redundant moves with calls (#79905)
Browse files Browse the repository at this point in the history
We were marking INTERP_LOCAL_FLAG_NO_CALL_ARGS for source vars of non calls. With further optimizations, the var could end up being used only for the call but we never unset the flag. Reuse the ref count data, which is kept updated following optimizations, to achieve same thing. If cprop is not run then we always duplicate the args, but this is an unused scenario.
  • Loading branch information
BrzVlad authored Jan 27, 2023
1 parent 7cc9aed commit c50c745
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/mono/mono/mini/interp/transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -9194,11 +9194,6 @@ interp_cprop (TransformData *td)
}
} else {
cprop_sreg (td, ins, &sregs [i], local_defs);
// This var is used as a source to a normal instruction. In case this var will
// also be used as source to a call, make sure the offset allocator will create
// a new temporary call arg var and not use this one. Call arg vars have special
// semantics. They can be assigned only once and they die once the call is made.
td->locals [sregs [i]].flags |= INTERP_LOCAL_FLAG_NO_CALL_ARGS;
}
}

Expand Down Expand Up @@ -10389,9 +10384,12 @@ interp_alloc_offsets (TransformData *td)

while (var != -1) {
if (td->locals [var].flags & INTERP_LOCAL_FLAG_GLOBAL ||
!td->local_ref_count || td->local_ref_count [var] > 1 ||
td->locals [var].flags & INTERP_LOCAL_FLAG_NO_CALL_ARGS) {
// A global var is an argument to a call, which is not allowed. We need
// to copy the global var into a local var
// Some vars can't be allocated on the call args stack, since the constraint is that
// call args vars die after the call. This isn't necessarily true for global vars or
// vars that are used by other instructions aside from the call.
// We need to copy the var into a new tmp var
int new_var = create_interp_local (td, td->locals [var].type);
td->locals [new_var].call = ins;
td->locals [new_var].flags |= INTERP_LOCAL_FLAG_CALL_ARGS;
Expand Down

0 comments on commit c50c745

Please sign in to comment.