Skip to content

Commit 2c4dc3f

Browse files
authored
[mono][interp] Add some missing opcodes for cfold (#99055)
This regression was introduced by SSA change. Before SSA change we were adding superinstructions at the very end of the compilation process, we would never encounter super instructions during cprop phase when cfolding takes place. This is no longer the case so we need to be able to fold patterns like `ct + add.imm`. Fixes Normalize ASCII regression from wasm bench suite
1 parent 806d11e commit 2c4dc3f

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

src/mono/mono/mini/interp/mintops.def

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -655,9 +655,6 @@ OPDEF(MINT_RET_I8_IMM, "ret.i8.imm", 2, 0, 0, MintOpShortInt)
655655
OPDEF(MINT_ADD_I4_IMM, "add.i4.imm", 4, 1, 1, MintOpShortInt)
656656
OPDEF(MINT_ADD_I8_IMM, "add.i8.imm", 4, 1, 1, MintOpShortInt)
657657

658-
OPDEF(MINT_ADD_MUL_I4_IMM, "add.mul.i4.imm", 5, 1, 1, MintOpTwoShorts)
659-
OPDEF(MINT_ADD_MUL_I8_IMM, "add.mul.i8.imm", 5, 1, 1, MintOpTwoShorts)
660-
661658
OPDEF(MINT_MUL_I4_IMM, "mul.i4.imm", 4, 1, 1, MintOpShortInt)
662659
OPDEF(MINT_MUL_I8_IMM, "mul.i8.imm", 4, 1, 1, MintOpShortInt)
663660

@@ -668,6 +665,9 @@ OPDEF(MINT_SHL_I8_IMM, "shl.i8.imm", 4, 1, 1, MintOpShortInt)
668665
OPDEF(MINT_SHR_I4_IMM, "shr.i4.imm", 4, 1, 1, MintOpShortInt)
669666
OPDEF(MINT_SHR_I8_IMM, "shr.i8.imm", 4, 1, 1, MintOpShortInt)
670667

668+
OPDEF(MINT_ADD_MUL_I4_IMM, "add.mul.i4.imm", 5, 1, 1, MintOpTwoShorts)
669+
OPDEF(MINT_ADD_MUL_I8_IMM, "add.mul.i8.imm", 5, 1, 1, MintOpTwoShorts)
670+
671671
OPDEF(MINT_SHL_AND_I4, "shl.i4.and", 4, 1, 2, MintOpNoArgs)
672672
OPDEF(MINT_SHL_AND_I8, "shl.i8.and", 4, 1, 2, MintOpNoArgs)
673673

src/mono/mono/mini/interp/mintops.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ typedef enum {
224224
#define MINT_IS_LDC_I8(op) ((op) >= MINT_LDC_I8_0 && (op) <= MINT_LDC_I8)
225225
#define MINT_IS_UNOP(op) ((op) >= MINT_ADD1_I4 && (op) <= MINT_CEQ0_I4)
226226
#define MINT_IS_BINOP(op) ((op) >= MINT_ADD_I4 && (op) <= MINT_CLT_UN_R8)
227+
#define MINT_IS_BINOP_IMM(op) ((op) >= MINT_ADD_I4_IMM && (op) <= MINT_SHR_I8_IMM)
227228
#define MINT_IS_BINOP_SHIFT(op) ((op) >= MINT_SHR_UN_I4 && (op) <= MINT_SHR_I8)
228229
#define MINT_IS_LDFLD(op) ((op) >= MINT_LDFLD_I1 && (op) <= MINT_LDFLD_O)
229230
#define MINT_IS_STFLD(op) ((op) >= MINT_STFLD_I1 && (op) <= MINT_STFLD_O)

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2130,6 +2130,12 @@ interp_get_mt_for_ldind (int ldind_op)
21302130
result.field = op val->field; \
21312131
break;
21322132

2133+
#define INTERP_FOLD_SHIFTOP_IMM(opcode,local_type,field,shift_op,cast_type) \
2134+
case opcode: \
2135+
result.type = local_type; \
2136+
result.field = (cast_type)val->field shift_op ins->data [0]; \
2137+
break;
2138+
21332139
#define INTERP_FOLD_CONV(opcode,val_type_dst,field_dst,val_type_src,field_src,cast_type) \
21342140
case opcode: \
21352141
result.type = val_type_dst; \
@@ -2169,6 +2175,19 @@ interp_fold_unop (TransformData *td, InterpInst *ins)
21692175
INTERP_FOLD_UNOP (MINT_NOT_I8, VAR_VALUE_I8, l, ~);
21702176
INTERP_FOLD_UNOP (MINT_CEQ0_I4, VAR_VALUE_I4, i, 0 ==);
21712177

2178+
INTERP_FOLD_UNOP (MINT_ADD_I4_IMM, VAR_VALUE_I4, i, ((gint32)(gint16)ins->data [0])+);
2179+
INTERP_FOLD_UNOP (MINT_ADD_I8_IMM, VAR_VALUE_I8, l, ((gint64)(gint16)ins->data [0])+);
2180+
2181+
INTERP_FOLD_UNOP (MINT_MUL_I4_IMM, VAR_VALUE_I4, i, ((gint32)(gint16)ins->data [0])*);
2182+
INTERP_FOLD_UNOP (MINT_MUL_I8_IMM, VAR_VALUE_I8, l, ((gint64)(gint16)ins->data [0])*);
2183+
2184+
INTERP_FOLD_SHIFTOP_IMM (MINT_SHR_UN_I4_IMM, VAR_VALUE_I4, i, >>, guint32);
2185+
INTERP_FOLD_SHIFTOP_IMM (MINT_SHR_UN_I8_IMM, VAR_VALUE_I8, l, >>, guint64);
2186+
INTERP_FOLD_SHIFTOP_IMM (MINT_SHL_I4_IMM, VAR_VALUE_I4, i, <<, gint32);
2187+
INTERP_FOLD_SHIFTOP_IMM (MINT_SHL_I8_IMM, VAR_VALUE_I8, l, <<, gint64);
2188+
INTERP_FOLD_SHIFTOP_IMM (MINT_SHR_I4_IMM, VAR_VALUE_I4, i, >>, gint32);
2189+
INTERP_FOLD_SHIFTOP_IMM (MINT_SHR_I8_IMM, VAR_VALUE_I8, l, >>, gint64);
2190+
21722191
INTERP_FOLD_CONV (MINT_CONV_I1_I4, VAR_VALUE_I4, i, VAR_VALUE_I4, i, gint8);
21732192
INTERP_FOLD_CONV (MINT_CONV_I1_I8, VAR_VALUE_I4, i, VAR_VALUE_I8, l, gint8);
21742193
INTERP_FOLD_CONV (MINT_CONV_U1_I4, VAR_VALUE_I4, i, VAR_VALUE_I4, i, guint8);
@@ -2902,7 +2921,7 @@ interp_cprop (TransformData *td)
29022921
td->var_values [dreg].type = VAR_VALUE_I4;
29032922
td->var_values [dreg].i = (gint32)td->data_items [ins->data [0]];
29042923
#endif
2905-
} else if (MINT_IS_UNOP (opcode)) {
2924+
} else if (MINT_IS_UNOP (opcode) || MINT_IS_BINOP_IMM (opcode)) {
29062925
ins = interp_fold_unop (td, ins);
29072926
} else if (MINT_IS_UNOP_CONDITIONAL_BRANCH (opcode)) {
29082927
ins = interp_fold_unop_cond_br (td, bb, ins);

0 commit comments

Comments
 (0)