Author: zoltan
Date: 2006-03-20 19:21:41 -0500 (Mon, 20 Mar 2006)
New Revision: 58208
Modified:
branches/vargaz/mini-linear-il/mono/mono/mini/cfold.c
branches/vargaz/mini-linear-il/mono/mono/mini/method-to-ir.c
branches/vargaz/mini-linear-il/mono/mono/mini/mini-x86.c
Log:
Small vtype optimizations.
Modified: branches/vargaz/mini-linear-il/mono/mono/mini/cfold.c
===================================================================
--- branches/vargaz/mini-linear-il/mono/mono/mini/cfold.c 2006-03-20
21:58:43 UTC (rev 58207)
+++ branches/vargaz/mini-linear-il/mono/mono/mini/cfold.c 2006-03-21
00:21:41 UTC (rev 58208)
@@ -465,6 +465,12 @@
ins->inst_c0 = arg1->inst_c0;
}
break;
+ case OP_VMOVE:
+ if (arg1->opcode == OP_VZERO) {
+ ins->opcode = OP_VZERO;
+ ins->sreg1 = -1;
+ }
+ break;
case OP_COMPARE:
case OP_ICOMPARE:
case OP_COMPARE_IMM:
@@ -708,6 +714,13 @@
NEW_ICONST (cfg, dest, arg1->inst_c0);
}
break;
+ case OP_VMOVE:
+ if (arg1->opcode == OP_VZERO) {
+ NEW_ICONST (cfg, dest, 0);
+ dest->opcode = OP_VZERO;
+ dest->sreg1 = -1;
+ }
+ break;
case OP_COMPARE:
case OP_ICOMPARE:
case OP_COMPARE_IMM:
Modified: branches/vargaz/mini-linear-il/mono/mono/mini/method-to-ir.c
===================================================================
--- branches/vargaz/mini-linear-il/mono/mono/mini/method-to-ir.c
2006-03-20 21:58:43 UTC (rev 58207)
+++ branches/vargaz/mini-linear-il/mono/mono/mini/method-to-ir.c
2006-03-21 00:21:41 UTC (rev 58208)
@@ -542,7 +542,7 @@
(dest)->klass = var->klass; \
(dest)->sreg1 = var->dreg; \
(dest)->dreg = alloc_dreg ((cfg), (dest)->type); \
- if ((dest)->opcode == OP_VMOVE) { /* FIXME: */ if (!get_vreg_to_inst
(cfg, (dest)->dreg)) mono_compile_create_var_for_vreg ((cfg), (vartype),
OP_LOCAL, (dest)->dreg); } \
+ if ((dest)->opcode == OP_VMOVE) (dest)->klass =
mono_class_from_mono_type ((vartype)); \
} while (0)
#define NEW_VARLOADA(cfg,dest,var,vartype) do { \
@@ -562,7 +562,7 @@
(dest)->klass = (var)->klass; \
(dest)->sreg1 = (inst)->dreg; \
(dest)->dreg = (var)->dreg; \
- if ((dest)->opcode == OP_VMOVE) { /* FIXME: */ if (!get_vreg_to_inst
(cfg, (dest)->sreg1)) mono_compile_create_var_for_vreg ((cfg), (vartype),
OP_LOCAL, (dest)->sreg1); } \
+ if ((dest)->opcode == OP_VMOVE) (dest)->klass =
mono_class_from_mono_type ((vartype)); \
} while (0)
#define NEW_TEMPLOAD(cfg,dest,num) NEW_VARLOAD ((cfg), (dest), (cfg)->varinfo
[(num)], (cfg)->varinfo [(num)]->inst_vtype)
@@ -5207,9 +5207,14 @@
src_var = get_vreg_to_inst (cfg, ins->sreg1);
dest_var = get_vreg_to_inst (cfg, ins->dreg);
- // FIXME:
- g_assert (src_var && dest_var);
+ g_assert (ins->klass);
+ if (!src_var)
+ src_var =
mono_compile_create_var_for_vreg (cfg, &ins->klass->byval_arg, OP_LOCAL,
ins->dreg);
+
+ if (!dest_var)
+ dest_var =
mono_compile_create_var_for_vreg (cfg, &ins->klass->byval_arg, OP_LOCAL,
ins->dreg);
+
// FIXME:
if (src_var->unused)
dest_var->unused = 1;
@@ -5223,8 +5228,11 @@
case OP_VZERO: {
dest_var = get_vreg_to_inst (cfg, ins->dreg);
- g_assert (dest_var);
+ g_assert (ins->klass);
+ if (!dest_var)
+ dest_var =
mono_compile_create_var_for_vreg (cfg, &ins->klass->byval_arg, OP_LOCAL,
ins->dreg);
+
EMIT_NEW_VARLOADA (cfg, dest, dest_var,
dest_var->inst_vtype);
handle_initobj (cfg, dest, NULL,
dest_var->klass, NULL, NULL);
break;
@@ -5232,7 +5240,10 @@
case OP_STOREV_MEMBASE: {
src_var = get_vreg_to_inst (cfg, ins->sreg1);
- g_assert (src_var);
+ if (!src_var) {
+ g_assert (ins->klass);
+ src_var =
mono_compile_create_var_for_vreg (cfg, &ins->klass->byval_arg, OP_LOCAL,
ins->sreg1);
+ }
EMIT_NEW_VARLOADA ((cfg), (src), src_var,
src_var->inst_vtype);
@@ -6378,25 +6389,13 @@
g_assert (!return_var);
CHECK_STACK (1);
--sp;
- MONO_INST_NEW (cfg, ins, OP_NOP);
- ins->opcode = mono_type_to_stind
(ret_type);
- if (ins->opcode == CEE_STOBJ) {
- MonoInst *src_var =
get_vreg_to_inst (cfg, (*sp)->dreg);
- MonoInst *src;
+ if (mono_type_to_stind (ret_type) ==
CEE_STOBJ) {
+ MonoInst *ret_addr;
- // FIXME: Make this use VMOVE
too
- if (!src_var)
- src_var =
mono_compile_create_var_for_vreg (cfg, ret_type, OP_LOCAL, (*sp)->dreg);
+ EMIT_NEW_RETLOADA (cfg,
ret_addr);
- EMIT_NEW_VARLOADA ((cfg),
(src), src_var, src_var->inst_vtype);
-
- EMIT_NEW_RETLOADA (cfg, ins);
-
- /*
- * cfg->ret is a scalar
variable, so can't use its
- * class field.
- */
- emit_stobj (cfg, ins, src, ip,
mono_class_from_mono_type (ret_type), FALSE);
+ EMIT_NEW_STORE_MEMBASE (cfg,
ins, OP_STOREV_MEMBASE, ret_addr->dreg, 0, (*sp)->dreg);
+ ins->klass =
mono_class_from_mono_type (ret_type);
} else {
mono_arch_emit_setret (cfg,
method, *sp);
}
@@ -6926,8 +6925,8 @@
if ((loc_index != -1) && ip_in_bb (cfg, bblock, ip +
5)) {
CHECK_LOCAL (loc_index);
- EMIT_NEW_LOCLOADA (cfg, ins, loc_index);
- emit_stobj (cfg, ins, *sp, ip, klass, FALSE);
+ EMIT_NEW_LOAD_MEMBASE (cfg, ins,
OP_LOADV_MEMBASE, cfg->locals [loc_index]->dreg, sp [0]->dreg, 0);
+ ins->klass = klass;
ip += 5;
ip += stloc_len;
break;
@@ -8791,10 +8790,6 @@
} else if ((t == MONO_TYPE_VALUETYPE) || (t ==
MONO_TYPE_TYPEDBYREF) ||
+ ((t == MONO_TYPE_GENERICINST) &&
mono_type_generic_inst_is_valuetype (ptype))) {
MONO_EMIT_NEW_VZERO (cfg, dreg,
mono_class_from_mono_type (ptype));
- /*
- EMIT_NEW_LOCLOADA (cfg, ins, i);
- handle_initobj (cfg, ins, NULL,
mono_class_from_mono_type (ptype), NULL, NULL);
- */
} else {
MONO_EMIT_NEW_PCONST (cfg, dreg, NULL);
}
@@ -9460,16 +9455,6 @@
ins->sreg1 = var->inst_basereg;
ins->inst_imm = var->inst_offset;
-#if defined(__i386__)
- if ((ins->sreg1 == X86_EBP) && (ins->dreg !=
X86_EBP)) {
- /* LEA is ADD but without the
sreg1==dreg restriction */
- /* FIXME: amd64 and generalize this */
- /* FIXME: Why does this lead to code
growth in mcs ? */
- ins->opcode = OP_X86_LEA_MEMBASE;
- ins->inst_basereg = ins->sreg1;
- }
-#endif
-
spec = ins_info [ins->opcode - OP_START - 1];
}
@@ -9726,8 +9711,10 @@
* - vtype cleanups:
* - add a NEW_VARLOADA_VREG macro
* - refactor the replacemenent code from the decompose_x_opts () functions
- * - get rid of the if (opcode == LDOBJ/STOBJ) stuff
+ * - the vtype optimizations are blocked by the LDADDR opcodes generated for
+ * accessing vtype fields and passing/receiving them in calls.
* - in the managed->native wrappers, place a pop before the call to
interrupt_checkpoint
+ * - port the lea optimization to amd64
* - LAST MERGE: 57988.
*/
Modified: branches/vargaz/mini-linear-il/mono/mono/mini/mini-x86.c
===================================================================
--- branches/vargaz/mini-linear-il/mono/mono/mini/mini-x86.c 2006-03-20
21:58:43 UTC (rev 58207)
+++ branches/vargaz/mini-linear-il/mono/mono/mini/mini-x86.c 2006-03-21
00:21:41 UTC (rev 58208)
@@ -1083,11 +1083,6 @@
g_assert (in->klass);
// FIXME:
- if (in->opcode == OP_LDADDR) {
- src_var = in->inst_p0;
- }
-
- // FIXME:
if (!src_var)
src_var = mono_compile_create_var_for_vreg
(cfg, &in->klass->byval_arg, OP_LOCAL, in->dreg);
@@ -1482,7 +1477,231 @@
#define INST_IGNORES_CFLAGS(opcode) (((opcode) == CEE_BR) || ((opcode) ==
OP_BR) || ((opcode) == OP_STORE_MEMBASE_IMM) || ((opcode) ==
OP_STOREI4_MEMBASE_IMM) || ((opcode) == OP_STOREI4_MEMBASE_REG) || ((opcode) ==
OP_STOREI1_MEMBASE_REG) || ((opcode) == OP_STOREI1_MEMBASE_IMM) || ((opcode) ==
OP_STOREI2_MEMBASE_REG) || ((opcode) == OP_STOREI2_MEMBASE_IMM) || ((opcode) ==
OP_IXOR) || ((opcode) == OP_MOVE) || ((opcode) == OP_ICONST) || ((opcode) ==
OP_IADD) || ((opcode) == OP_X86_PUSH) || ((opcode) == OP_X86_PUSH_IMM) ||
((opcode) == OP_X86_PUSH_MEMBASE) || ((opcode) == OP_COMPARE_IMM) || ((opcode)
== OP_ICOMPARE_IMM) || ((opcode) == OP_LOAD_MEMBASE) || ((opcode) ==
OP_LOADI4_MEMBASE))
*/
+/*
+ * peephole_pass_1:
+ *
+ * Perform peephole opts which should/can be performed before local regalloc
+ */
static void
+peephole_pass_1 (MonoCompile *cfg, MonoBasicBlock *bb)
+{
+ MonoInst *ins, *last_ins = NULL;
+ ins = bb->code;
+
+ while (ins) {
+ switch (ins->opcode) {
+ case OP_MUL_IMM:
+ case OP_IMUL_IMM:
+ /* remove unnecessary multiplication with 1 */
+ if (ins->inst_imm == 1) {
+ if (ins->dreg != ins->sreg1) {
+ ins->opcode = OP_MOVE;
+ } else {
+ last_ins->next = ins->next;
+ ins = ins->next;
+ continue;
+ }
+ }
+ break;
+ case OP_IADD_IMM:
+ case OP_ADD_IMM:
+ if (ins->sreg1 == X86_EBP) {
+ /*
+ * X86_LEA is like ADD, but doesn't have the
+ * sreg1==dreg restriction.
+ */
+ ins->opcode = OP_X86_LEA_MEMBASE;
+ ins->inst_basereg = ins->sreg1;
+ } else if ((ins->inst_imm == 1) && (ins->dreg ==
ins->sreg1))
+ ins->opcode = OP_X86_INC_REG;
+ break;
+ case OP_ISUB_IMM:
+ case OP_SUB_IMM:
+ if ((ins->inst_imm == 1) && (ins->dreg == ins->sreg1))
+ ins->opcode = OP_X86_DEC_REG;
+ break;
+ case OP_COMPARE_IMM:
+ case OP_ICOMPARE_IMM:
+ /* OP_COMPARE_IMM (reg, 0)
+ * -->
+ * OP_X86_TEST_NULL (reg)
+ */
+ if (!ins->inst_imm)
+ ins->opcode = OP_X86_TEST_NULL;
+ break;
+ case OP_X86_COMPARE_MEMBASE_IMM:
+ /*
+ * OP_STORE_MEMBASE_REG reg, offset(basereg)
+ * OP_X86_COMPARE_MEMBASE_IMM offset(basereg), imm
+ * -->
+ * OP_STORE_MEMBASE_REG reg, offset(basereg)
+ * OP_COMPARE_IMM reg, imm
+ *
+ * Note: if imm = 0 then OP_COMPARE_IMM replaced with
OP_X86_TEST_NULL
+ */
+ if (last_ins && (last_ins->opcode ==
OP_STOREI4_MEMBASE_REG) &&
+ ins->inst_basereg == last_ins->inst_destbasereg &&
+ ins->inst_offset == last_ins->inst_offset) {
+ ins->opcode = OP_COMPARE_IMM;
+ ins->sreg1 = last_ins->sreg1;
+
+ /* check if we can remove cmp reg,0
with test null */
+ if (!ins->inst_imm)
+ ins->opcode = OP_X86_TEST_NULL;
+ }
+
+ break;
+ case OP_LOAD_MEMBASE:
+ case OP_LOADI4_MEMBASE:
+ /*
+ * Note: if reg1 = reg2 the load op is removed
+ *
+ * OP_STORE_MEMBASE_REG reg1, offset(basereg)
+ * OP_LOAD_MEMBASE offset(basereg), reg2
+ * -->
+ * OP_STORE_MEMBASE_REG reg1, offset(basereg)
+ * OP_MOVE reg1, reg2
+ */
+ if (last_ins && (last_ins->opcode ==
OP_STOREI4_MEMBASE_REG
+ || last_ins->opcode ==
OP_STORE_MEMBASE_REG) &&
+ ins->inst_basereg == last_ins->inst_destbasereg &&
+ ins->inst_offset == last_ins->inst_offset) {
+ if (ins->dreg == last_ins->sreg1) {
+ last_ins->next = ins->next;
+ ins = ins->next;
+ continue;
+ } else {
+ //static int c = 0; printf ("MATCHX %s
%d\n", cfg->method->name,c++);
+ ins->opcode = OP_MOVE;
+ ins->sreg1 = last_ins->sreg1;
+ }
+
+ /*
+ * Note: reg1 must be different from the basereg in the
second load
+ * Note: if reg1 = reg2 is equal then second load is
removed
+ *
+ * OP_LOAD_MEMBASE offset(basereg), reg1
+ * OP_LOAD_MEMBASE offset(basereg), reg2
+ * -->
+ * OP_LOAD_MEMBASE offset(basereg), reg1
+ * OP_MOVE reg1, reg2
+ */
+ } if (last_ins && (last_ins->opcode == OP_LOADI4_MEMBASE
+ || last_ins->opcode ==
OP_LOAD_MEMBASE) &&
+ ins->inst_basereg != last_ins->dreg &&
+ ins->inst_basereg == last_ins->inst_basereg &&
+ ins->inst_offset == last_ins->inst_offset) {
+
+ if (ins->dreg == last_ins->dreg) {
+ last_ins->next = ins->next;
+ ins = ins->next;
+ continue;
+ } else {
+ ins->opcode = OP_MOVE;
+ ins->sreg1 = last_ins->dreg;
+ }
+
+ //g_assert_not_reached ();
+
+#if 0
+ /*
+ * OP_STORE_MEMBASE_IMM imm, offset(basereg)
+ * OP_LOAD_MEMBASE offset(basereg), reg
+ * -->
+ * OP_STORE_MEMBASE_IMM imm, offset(basereg)
+ * OP_ICONST reg, imm
+ */
+ } else if (last_ins && (last_ins->opcode ==
OP_STOREI4_MEMBASE_IMM
+ || last_ins->opcode ==
OP_STORE_MEMBASE_IMM) &&
+ ins->inst_basereg ==
last_ins->inst_destbasereg &&
+ ins->inst_offset == last_ins->inst_offset) {
+ //static int c = 0; printf ("MATCHX %s %d\n",
cfg->method->name,c++);
+ ins->opcode = OP_ICONST;
+ ins->inst_c0 = last_ins->inst_imm;
+ g_assert_not_reached (); // check this rule
+#endif
+ }
+ break;
+ case OP_LOADU1_MEMBASE:
+ case OP_LOADI1_MEMBASE:
+ /*
+ * OP_STORE_MEMBASE_REG reg1, offset(basereg)
+ * OP_LOAD_MEMBASE offset(basereg), reg2
+ * -->
+ * OP_STORE_MEMBASE_REG reg1, offset(basereg)
+ * CONV_I2/U2 reg1, reg2
+ */
+ if (last_ins && X86_IS_BYTE_REG (last_ins->sreg1) &&
+ (last_ins->opcode == OP_STOREI1_MEMBASE_REG) &&
+ ins->inst_basereg ==
last_ins->inst_destbasereg &&
+ ins->inst_offset ==
last_ins->inst_offset) {
+ ins->opcode = (ins->opcode ==
OP_LOADI1_MEMBASE) ? CEE_CONV_I1 : CEE_CONV_U1;
+ ins->sreg1 = last_ins->sreg1;
+ }
+ break;
+ case OP_LOADU2_MEMBASE:
+ case OP_LOADI2_MEMBASE:
+ /*
+ * OP_STORE_MEMBASE_REG reg1, offset(basereg)
+ * OP_LOAD_MEMBASE offset(basereg), reg2
+ * -->
+ * OP_STORE_MEMBASE_REG reg1, offset(basereg)
+ * CONV_I2/U2 reg1, reg2
+ */
+ if (last_ins && (last_ins->opcode ==
OP_STOREI2_MEMBASE_REG) &&
+ ins->inst_basereg ==
last_ins->inst_destbasereg &&
+ ins->inst_offset ==
last_ins->inst_offset) {
+ ins->opcode = (ins->opcode ==
OP_LOADI2_MEMBASE) ? CEE_CONV_I2 : CEE_CONV_U2;
+ ins->sreg1 = last_ins->sreg1;
+ }
+ break;
+ case CEE_CONV_I4:
+ case CEE_CONV_U4:
+ case OP_ICONV_TO_I4:
+ case OP_MOVE:
+ /*
+ * Removes:
+ *
+ * OP_MOVE reg, reg
+ */
+ if (ins->dreg == ins->sreg1) {
+ if (last_ins)
+ last_ins->next = ins->next;
+ ins = ins->next;
+ continue;
+ }
+ /*
+ * Removes:
+ *
+ * OP_MOVE sreg, dreg
+ * OP_MOVE dreg, sreg
+ */
+ if (last_ins && last_ins->opcode == OP_MOVE &&
+ ins->sreg1 == last_ins->dreg &&
+ ins->dreg == last_ins->sreg1) {
+ last_ins->next = ins->next;
+ ins = ins->next;
+ continue;
+ }
+ break;
+
+ case OP_X86_PUSH_MEMBASE:
+ if (last_ins && (last_ins->opcode ==
OP_STOREI4_MEMBASE_REG ||
+ last_ins->opcode ==
OP_STORE_MEMBASE_REG) &&
+ ins->inst_basereg == last_ins->inst_destbasereg &&
+ ins->inst_offset == last_ins->inst_offset) {
+ ins->opcode = OP_X86_PUSH;
+ ins->sreg1 = last_ins->sreg1;
+ }
+ break;
+ }
+ last_ins = ins;
+ ins = ins->next;
+ }
+ bb->last_ins = last_ins;
+}
+
+static void
peephole_pass (MonoCompile *cfg, MonoBasicBlock *bb)
{
MonoInst *ins, *last_ins = NULL;
@@ -1522,19 +1741,6 @@
}
}
break;
- case OP_MUL_IMM:
- case OP_IMUL_IMM:
- /* remove unnecessary multiplication with 1 */
- if (ins->inst_imm == 1) {
- if (ins->dreg != ins->sreg1) {
- ins->opcode = OP_MOVE;
- } else {
- last_ins->next = ins->next;
- ins = ins->next;
- continue;
- }
- }
- break;
case OP_IADD_IMM:
case OP_ADD_IMM:
if ((ins->inst_imm == 1) && (ins->dreg == ins->sreg1))
@@ -1545,15 +1751,6 @@
if ((ins->inst_imm == 1) && (ins->dreg == ins->sreg1))
ins->opcode = OP_X86_DEC_REG;
break;
- case OP_COMPARE_IMM:
- case OP_ICOMPARE_IMM:
- /* OP_COMPARE_IMM (reg, 0)
- * -->
- * OP_X86_TEST_NULL (reg)
- */
- if (!ins->inst_imm)
- ins->opcode = OP_X86_TEST_NULL;
- break;
case OP_X86_COMPARE_MEMBASE_IMM:
/*
* OP_STORE_MEMBASE_REG reg, offset(basereg)
@@ -1709,7 +1906,6 @@
continue;
}
break;
-
case OP_X86_PUSH_MEMBASE:
if (last_ins && (last_ins->opcode ==
OP_STOREI4_MEMBASE_REG ||
last_ins->opcode ==
OP_STORE_MEMBASE_REG) &&
@@ -1739,6 +1935,9 @@
void
mono_arch_local_regalloc (MonoCompile *cfg, MonoBasicBlock *bb)
{
+ if (cfg->opt & MONO_OPT_PEEPHOLE)
+ peephole_pass_1 (cfg, bb);
+
mono_local_regalloc (cfg, bb);
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches