Skip to content

Commit

Permalink
[mono][interp] Expand compare + brfalse/brtrue with single conditiona…
Browse files Browse the repository at this point in the history
…l branch opcode (#80046)

* Add integer opcodes

* Add floating-point opcodes

* Check if local_ref_count is 1
  • Loading branch information
kotlarmilos authored Jan 3, 2023
1 parent ac2ffdf commit 7fa0d5b
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/mono/mono/mini/interp/transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -9823,20 +9823,42 @@ interp_super_instructions (TransformData *td)
gboolean negate = opcode == MINT_BRFALSE_I4;
int cond_sreg = ins->sregs [0];
InterpInst *def = td->locals [cond_sreg].def;
if (def != NULL) {
if (def != NULL && local_ref_count [cond_sreg] == 1) {
int replace_opcode = -1;
switch (def->opcode) {
case MINT_CEQ_I4: replace_opcode = negate ? MINT_BNE_UN_I4 : MINT_BEQ_I4; break;
case MINT_CEQ_I8: replace_opcode = negate ? MINT_BNE_UN_I8 : MINT_BEQ_I8; break;
case MINT_CGT_I4: replace_opcode = negate ? MINT_BLE_I4 : MINT_BGT_I4; break;
case MINT_CGT_I8: replace_opcode = negate ? MINT_BLE_I8 : MINT_BGT_I8; break;
case MINT_CLT_I4: replace_opcode = negate ? MINT_BGE_I4 : MINT_BLT_I4; break;
case MINT_CLT_I8: replace_opcode = negate ? MINT_BGE_I8 : MINT_BLT_I8; break;
case MINT_CGT_UN_I4: replace_opcode = negate ? MINT_BLE_UN_I4 : MINT_BGT_UN_I4; break;
case MINT_CGT_UN_I8: replace_opcode = negate ? MINT_BLE_UN_I8 : MINT_BGT_UN_I8; break;
case MINT_CLT_UN_I4: replace_opcode = negate ? MINT_BGE_UN_I4 : MINT_BLT_UN_I4; break;
case MINT_CLT_UN_I8: replace_opcode = negate ? MINT_BGE_UN_I8 : MINT_BLT_UN_I8; break;
case MINT_CEQ_R4: replace_opcode = negate ? MINT_BNE_UN_R4 : MINT_BEQ_R4; break;
case MINT_CEQ_R8: replace_opcode = negate ? MINT_BNE_UN_R8 : MINT_BEQ_R8; break;
case MINT_CGT_R4: replace_opcode = negate ? MINT_BLE_UN_R4 : MINT_BGT_R4; break;
case MINT_CGT_R8: replace_opcode = negate ? MINT_BLE_UN_R8 : MINT_BGT_R8; break;
case MINT_CLT_R4: replace_opcode = negate ? MINT_BGE_UN_R4 : MINT_BLT_R4; break;
case MINT_CLT_R8: replace_opcode = negate ? MINT_BGE_UN_R8 : MINT_BLT_R8; break;
case MINT_CGT_UN_R4: replace_opcode = negate ? MINT_BLE_R4 : MINT_BGT_UN_R4; break;
case MINT_CGT_UN_R8: replace_opcode = negate ? MINT_BLE_R8 : MINT_BGT_UN_R8; break;
case MINT_CLT_UN_R4: replace_opcode = negate ? MINT_BGE_R4 : MINT_BLT_UN_R4; break;
case MINT_CLT_UN_R8: replace_opcode = negate ? MINT_BGE_R8 : MINT_BLT_UN_R8; break;
case MINT_CEQ0_I4: replace_opcode = negate ? MINT_BRTRUE_I4 : MINT_BRFALSE_I4; break; // If def->opcode is MINT_CEQ0_I4 ins->opcode is inverted
// Add more opcodes
default:
break;
}
if (replace_opcode != -1) {
ins->opcode = replace_opcode;
ins->sregs [0] = def->sregs [0];
ins->sregs [1] = def->sregs [1];
if (def->opcode != MINT_CEQ0_I4)
ins->sregs [1] = def->sregs [1];
interp_clear_ins (def);
local_ref_count [cond_sreg]--;
mono_interp_stats.super_instructions++;
if (td->verbose_level) {
g_print ("superins: ");
dump_interp_inst (ins);
Expand Down

0 comments on commit 7fa0d5b

Please sign in to comment.