Skip to content

Commit d7205fe

Browse files
committed
[mono][interp] Reduce redundant moves with calls
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.
1 parent 7ec3634 commit d7205fe

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/mono/mono/mini/interp/transform.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9187,11 +9187,6 @@ interp_cprop (TransformData *td)
91879187
}
91889188
} else {
91899189
cprop_sreg (td, ins, &sregs [i], local_defs);
9190-
// This var is used as a source to a normal instruction. In case this var will
9191-
// also be used as source to a call, make sure the offset allocator will create
9192-
// a new temporary call arg var and not use this one. Call arg vars have special
9193-
// semantics. They can be assigned only once and they die once the call is made.
9194-
td->locals [sregs [i]].flags |= INTERP_LOCAL_FLAG_NO_CALL_ARGS;
91959190
}
91969191
}
91979192

@@ -10395,9 +10390,12 @@ interp_alloc_offsets (TransformData *td)
1039510390

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

0 commit comments

Comments
 (0)