Skip to content

Commit

Permalink
[release/8.0-rc1] [mini] Fix typo in mono_decompose_vtype_opts (#90832)
Browse files Browse the repository at this point in the history
* Fix typo in mono_decompose_vtype_opts

Without this, if some previous instruction already created a vreg for
ins->dest (for example if we are doing multiple passes over the basic
block because `restart == TRUE`) we will use an incorrect vreg when
decomposing the current VMOVE

Fixes #90800

* Only emit an OP_LDTOKEN_FIELD if we loaded a field token

This is used by a CreateSpan optimization that needs access to the
MonoClassField*

For other cases of a bare LDTOKEN (such as hand-written IL that calls
LDTOKEN on a type but doesn't follow it up with a call to
`GetTypeFromHandle` leave the opcode as a VMOVE (from the
`EMIT_NEW_TEMPLOAD` above))

---------

Co-authored-by: Aleksey Kliger <[email protected]>
  • Loading branch information
github-actions[bot] and lambdageek authored Aug 19, 2023
1 parent f8e2a9b commit 6aef01d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/mono/mono/mini/decompose.c
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,7 @@ mono_decompose_vtype_opts (MonoCompile *cfg)
dest_var = get_vreg_to_inst (cfg, ins->dreg);

if (!src_var)
src_var = mono_compile_create_var_for_vreg (cfg, m_class_get_byval_arg (ins->klass), OP_LOCAL, ins->dreg);
src_var = mono_compile_create_var_for_vreg (cfg, m_class_get_byval_arg (ins->klass), OP_LOCAL, ins->sreg1);

if (!dest_var)
dest_var = mono_compile_create_var_for_vreg (cfg, m_class_get_byval_arg (ins->klass), OP_LOCAL, ins->dreg);
Expand Down
13 changes: 8 additions & 5 deletions src/mono/mono/mini/method-to-ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -10840,12 +10840,15 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
EMIT_NEW_TEMPLOADA (cfg, addr, vtvar->inst_c0);
MONO_EMIT_NEW_STORE_MEMBASE (cfg, OP_STORE_MEMBASE_REG, addr->dreg, 0, ins->dreg);
EMIT_NEW_TEMPLOAD (cfg, ins, vtvar->inst_c0);
ins->opcode = OP_LDTOKEN_FIELD;
ins->inst_c0 = n;
ins->inst_p1 = handle;
if (handle_class == mono_defaults.fieldhandle_class) {
ins->opcode = OP_LDTOKEN_FIELD;
ins->inst_c0 = n;
ins->inst_p1 = handle;

cfg->flags |= MONO_CFG_NEEDS_DECOMPOSE;
cfg->cbb->needs_decompose = TRUE;
}

cfg->flags |= MONO_CFG_NEEDS_DECOMPOSE;
cfg->cbb->needs_decompose = TRUE;
}
}

Expand Down

0 comments on commit 6aef01d

Please sign in to comment.