Skip to content

Commit 7fa0d5b

Browse files
authored
[mono][interp] Expand compare + brfalse/brtrue with single conditional branch opcode (#80046)
* Add integer opcodes * Add floating-point opcodes * Check if local_ref_count is 1
1 parent ac2ffdf commit 7fa0d5b

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9823,20 +9823,42 @@ interp_super_instructions (TransformData *td)
98239823
gboolean negate = opcode == MINT_BRFALSE_I4;
98249824
int cond_sreg = ins->sregs [0];
98259825
InterpInst *def = td->locals [cond_sreg].def;
9826-
if (def != NULL) {
9826+
if (def != NULL && local_ref_count [cond_sreg] == 1) {
98279827
int replace_opcode = -1;
98289828
switch (def->opcode) {
98299829
case MINT_CEQ_I4: replace_opcode = negate ? MINT_BNE_UN_I4 : MINT_BEQ_I4; break;
98309830
case MINT_CEQ_I8: replace_opcode = negate ? MINT_BNE_UN_I8 : MINT_BEQ_I8; break;
9831+
case MINT_CGT_I4: replace_opcode = negate ? MINT_BLE_I4 : MINT_BGT_I4; break;
9832+
case MINT_CGT_I8: replace_opcode = negate ? MINT_BLE_I8 : MINT_BGT_I8; break;
9833+
case MINT_CLT_I4: replace_opcode = negate ? MINT_BGE_I4 : MINT_BLT_I4; break;
9834+
case MINT_CLT_I8: replace_opcode = negate ? MINT_BGE_I8 : MINT_BLT_I8; break;
9835+
case MINT_CGT_UN_I4: replace_opcode = negate ? MINT_BLE_UN_I4 : MINT_BGT_UN_I4; break;
9836+
case MINT_CGT_UN_I8: replace_opcode = negate ? MINT_BLE_UN_I8 : MINT_BGT_UN_I8; break;
9837+
case MINT_CLT_UN_I4: replace_opcode = negate ? MINT_BGE_UN_I4 : MINT_BLT_UN_I4; break;
9838+
case MINT_CLT_UN_I8: replace_opcode = negate ? MINT_BGE_UN_I8 : MINT_BLT_UN_I8; break;
9839+
case MINT_CEQ_R4: replace_opcode = negate ? MINT_BNE_UN_R4 : MINT_BEQ_R4; break;
9840+
case MINT_CEQ_R8: replace_opcode = negate ? MINT_BNE_UN_R8 : MINT_BEQ_R8; break;
9841+
case MINT_CGT_R4: replace_opcode = negate ? MINT_BLE_UN_R4 : MINT_BGT_R4; break;
9842+
case MINT_CGT_R8: replace_opcode = negate ? MINT_BLE_UN_R8 : MINT_BGT_R8; break;
9843+
case MINT_CLT_R4: replace_opcode = negate ? MINT_BGE_UN_R4 : MINT_BLT_R4; break;
9844+
case MINT_CLT_R8: replace_opcode = negate ? MINT_BGE_UN_R8 : MINT_BLT_R8; break;
9845+
case MINT_CGT_UN_R4: replace_opcode = negate ? MINT_BLE_R4 : MINT_BGT_UN_R4; break;
9846+
case MINT_CGT_UN_R8: replace_opcode = negate ? MINT_BLE_R8 : MINT_BGT_UN_R8; break;
9847+
case MINT_CLT_UN_R4: replace_opcode = negate ? MINT_BGE_R4 : MINT_BLT_UN_R4; break;
9848+
case MINT_CLT_UN_R8: replace_opcode = negate ? MINT_BGE_R8 : MINT_BLT_UN_R8; break;
9849+
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
98319850
// Add more opcodes
98329851
default:
98339852
break;
98349853
}
98359854
if (replace_opcode != -1) {
98369855
ins->opcode = replace_opcode;
98379856
ins->sregs [0] = def->sregs [0];
9838-
ins->sregs [1] = def->sregs [1];
9857+
if (def->opcode != MINT_CEQ0_I4)
9858+
ins->sregs [1] = def->sregs [1];
98399859
interp_clear_ins (def);
9860+
local_ref_count [cond_sreg]--;
9861+
mono_interp_stats.super_instructions++;
98409862
if (td->verbose_level) {
98419863
g_print ("superins: ");
98429864
dump_interp_inst (ins);

0 commit comments

Comments
 (0)