-
Notifications
You must be signed in to change notification settings - Fork 5.5k
[mono][interp] Lower div.un to shr.un.imm #83498
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2119,7 +2119,17 @@ interp_handle_intrinsics (TransformData *td, MonoMethod *target_method, MonoClas | |
| } else if (!strcmp (tm, "AreSame")) { | ||
| *op = MINT_CEQ_P; | ||
| } else if (!strcmp (tm, "ByteOffset")) { | ||
| *op = MINT_INTRINS_UNSAFE_BYTE_OFFSET; | ||
| #if SIZEOF_VOID_P == 4 | ||
| interp_add_ins (td, MINT_SUB_I4); | ||
| #else | ||
| interp_add_ins (td, MINT_SUB_I8); | ||
| #endif | ||
| td->sp -= 2; | ||
| interp_ins_set_sregs2 (td->last_ins, td->sp [1].local, td->sp [0].local); | ||
| push_simple_type (td, STACK_TYPE_I); | ||
| interp_ins_set_dreg (td->last_ins, td->sp [-1].local); | ||
| td->ip += 5; | ||
| return TRUE; | ||
| } else if (!strcmp (tm, "Unbox")) { | ||
| MonoGenericContext *ctx = mono_method_get_context (target_method); | ||
| g_assert (ctx); | ||
|
|
@@ -9873,6 +9883,39 @@ interp_super_instructions (TransformData *td) | |
| dump_interp_inst (new_inst); | ||
| } | ||
| } | ||
| } else if (opcode == MINT_DIV_UN_I4 || opcode == MINT_DIV_UN_I8) { | ||
| // ldc + div.un -> shr.imm | ||
| int sreg_imm = ins->sregs [1]; | ||
| InterpInst *def = td->locals [sreg_imm].def; | ||
| if (def != NULL && td->local_ref_count [sreg_imm] == 1) { | ||
| int power2 = -1; | ||
| if (MINT_IS_LDC_I4 (def->opcode)) { | ||
| guint32 ct = interp_get_const_from_ldc_i4 (def); | ||
| power2 = mono_is_power_of_two ((guint32)ct); | ||
| } else if (MINT_IS_LDC_I8 (def->opcode)) { | ||
| guint64 ct = interp_get_const_from_ldc_i8 (def); | ||
| if (ct < G_MAXUINT32) | ||
| power2 = mono_is_power_of_two ((guint32)ct); | ||
| } | ||
| if (power2 > 0) { | ||
| InterpInst *new_inst; | ||
| if (opcode == MINT_DIV_UN_I4) | ||
| new_inst = interp_insert_ins (td, ins, MINT_SHR_UN_I4_IMM); | ||
| else | ||
| new_inst = interp_insert_ins (td, ins, MINT_SHR_UN_I8_IMM); | ||
| new_inst->dreg = ins->dreg; | ||
| new_inst->sregs [0] = ins->sregs [0]; | ||
| new_inst->data [0] = power2; | ||
|
|
||
| interp_clear_ins (def); | ||
| interp_clear_ins (ins); | ||
| local_ref_count [sreg_imm]--; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some of these stats are not that useful anymore, I will probably get rid of them in the future. Also this is more of a peephole optimization. This pass will probably end up being rebranded. |
||
| if (td->verbose_level) { | ||
| g_print ("lower div.un: "); | ||
| dump_interp_inst (new_inst); | ||
| } | ||
| } | ||
| } | ||
| } else if (MINT_IS_LDIND_INT (opcode)) { | ||
| int sreg_base = ins->sregs [0]; | ||
| InterpInst *def = td->locals [sreg_base].def; | ||
|
|
||
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.
The original interp opcode looks like it was storing the result of a signed pointer subtraction into an unsigned int (mono_u), but I assume this will behave correctly as-is?