Browse files

[imcc] Fix most -O2 errors, restore ins2->op on failed const propag.

IMCC_subst_constants may return ok with an empty ins.
Restore the old ins2->op ptr then.
If !ok also restore the symregs.
 See GH #1039

Remaining -O2 fails:
/compilers/imcc/syn/macro.t      (Wstat: 512 Tests: 42 Failed: 2)
  Failed tests:  10-11
  Non-zero exit status: 2
t/op/calling.t                    (Wstat: 512 Tests: 104 Failed: 2)
  Failed tests:  30, 36
  Non-zero exit status: 2
t/op/exit.t                       (Wstat: 256 Tests: 9 Failed: 1)
  Failed test:  6
  Non-zero exit status: 1
t/op/jitn.t                       (Wstat: 256 Tests: 14 Failed: 1)
  Failed test:  13
  Non-zero exit status: 1
t/op/lexicals.t                   (Wstat: 256 Tests: 54 Failed: 1)
  Failed test:  42
  Non-zero exit status: 1
t/pmc/io.t                        (Wstat: 1024 Tests: 35 Failed: 4)
  Failed tests:  3-4, 13-14
  Non-zero exit status: 4
t/pmc/nci.t                       (Wstat: 256 Tests: 61 Failed: 1)
  Failed test:  50
  Non-zero exit status: 1
t/pmc/os.t                        (Wstat: 512 Tests: 36 Failed: 2)
  Failed tests:  3, 5
  Non-zero exit status: 2
Files=207, Tests=7199, 72 wallclock secs ( 1.46 usr  0.49 sys + 32.52 cusr 24.70 csys = 59.17 CPU)
Result: FAIL
  • Loading branch information...
1 parent 8272ff1 commit 64dc724861b6fea798ffffe7271438dab35711bc @rurban rurban committed Feb 27, 2014
Showing with 27 additions and 18 deletions.
  1. +18 −13 compilers/imcc/optimizer.c
  2. +9 −5 compilers/imcc/pbc.c
View
31 compilers/imcc/optimizer.c
@@ -746,6 +746,7 @@ constant_propagation(ARGMOD(imc_info_t *imcc), ARGMOD(IMC_Unit *unit))
else if (instruction_reads(ins2, ins2->symregs[i])) {
Instruction *tmp;
SymReg *old;
+ op_info_t *oldop = ins2->op;
IMCC_debug(imcc, DEBUG_OPT2, "\tpropagating into register %i: ", i);
IMCC_debug_ins(imcc, DEBUG_OPT2, ins2);
@@ -758,16 +759,15 @@ constant_propagation(ARGMOD(imc_info_t *imcc), ARGMOD(IMC_Unit *unit))
if (found) {
const Instruction * const prev = ins2->prev;
if (prev) {
- if (tmp) /* see syn/clash_1.pir */
+ if (tmp) { /* see syn/clash_1.pir or syn/const_31.pir */
subst_ins(unit, ins2, tmp, 1);
- any = 1;
- if (tmp) {
+ any = 1;
IMCC_debug(imcc, DEBUG_OPT2, " reduced to ");
IMCC_debug_ins(imcc, DEBUG_OPT2, tmp);
}
else {
- --old->use_count;
- IMCC_debug(imcc, DEBUG_OPT2, " deleted\n");
+ ins2->op = oldop;
+ IMCC_debug(imcc, DEBUG_OPT2, " no const op for %s\n", ins2->opname);
}
ins2 = prev->next;
}
@@ -777,9 +777,11 @@ constant_propagation(ARGMOD(imc_info_t *imcc), ARGMOD(IMC_Unit *unit))
check_op(imcc, &ins2->op, fullname, ins2->opname,
ins2->symregs, ins2->symreg_count, ins2->keys);
if (!ins2->op) {
+ ins2->op = oldop;
ins2->symregs[i] = old;
IMCC_debug(imcc, DEBUG_OPT2,
- " - no %s\n", fullname);
+ "\t- no %s ", fullname);
+ IMCC_debug_ins(imcc, DEBUG_OPT2, ins2);
}
else {
--old->use_count;
@@ -969,8 +971,9 @@ IMCC_subst_constants(ARGMOD(imc_info_t *imcc), ARGMOD(IMC_Unit *unit),
size_t i;
const char *fmt;
char op[20];
- const char *debug_fmt = NULL; /* gcc -O uninit warn */
+ const char *debug_fmt = NULL;
int found = 0, branched;
+ *ok = 0;
/* construct a FLOATVAL_FMT with needed precision.
TT #308 XXX Should use Configure.pl to figure these out,
@@ -1049,7 +1052,6 @@ IMCC_subst_constants(ARGMOD(imc_info_t *imcc), ARGMOD(IMC_Unit *unit),
}
if (!found) {
- *ok = 0;
return NULL;
}
@@ -1058,13 +1060,13 @@ IMCC_subst_constants(ARGMOD(imc_info_t *imcc), ARGMOD(IMC_Unit *unit),
/* we construct a parrot instruction
* here and let parrot do the calculation in a
* separate context and make a constant
- * from the result
+ * from the result.
*/
branched = eval_ins(imcc, op, found, r);
if (branched == -1) {
/* Don't set ok
* (See http://rt.perl.org/rt3/Ticket/Display.html?id=43048 for info) */
- return NULL;
+ return NULL;
}
/*
* for math ops result is in I0/N0
@@ -1076,9 +1078,12 @@ IMCC_subst_constants(ARGMOD(imc_info_t *imcc), ARGMOD(IMC_Unit *unit),
if (branched) {
r[0] = r[found];
tmp = INS(imcc, unit, "branch", "", r, 1, 0, 0);
+ if (tmp)
+ *ok = 1;
}
else {
IMCC_debug(imcc, DEBUG_OPT1, "deleted\n");
+ *ok = 1;
}
}
else {
@@ -1110,11 +1115,11 @@ IMCC_subst_constants(ARGMOD(imc_info_t *imcc), ARGMOD(IMC_Unit *unit),
break;
}
tmp = INS(imcc, unit, "set", "", r, 2, 0, 0);
+ if (tmp)
+ *ok = 1;
}
- if (tmp) {
+ if (tmp)
IMCC_debug_ins(imcc, DEBUG_OPT1, tmp);
- }
- *ok = 1;
return tmp;
}
View
14 compilers/imcc/pbc.c
@@ -2474,13 +2474,16 @@ e_pbc_emit(ARGMOD(imc_info_t * imcc), SHIM(void *param), ARGIN(const IMC_Unit *u
op_info = ins->op;
if (!op_info) {
+#if 0
if (imcc->optimizer_level & OPT_CFG) { /* known issue GH #1039 */
- IMCC_warning(imcc, "e_emit_pbc: empty op %d ", imcc->npc);
+ IMCC_info(imcc, 0, "** e_emit_pbc: empty op %d 0x%x ", imcc->npc, ins);
IMCC_debug_ins(imcc, 0, ins);
+ IMCC_print_inc(imcc);
+ IMCC_info(imcc, 0, "\n");
return 0;
- } else {
- IMCC_fatal(imcc, 1, "e_emit_pbc: empty op %d %x", imcc->npc, ins);
- }
+ } else
+#endif
+ IMCC_fatal(imcc, 1, "e_emit_pbc: empty op %d 0x%x\n", imcc->npc, ins);
}
IMCC_debug(imcc, DEBUG_PBC, "%d %s", imcc->npc, op_info->full_name);
@@ -2553,7 +2556,8 @@ e_pbc_emit(ARGMOD(imc_info_t * imcc), SHIM(void *param), ARGIN(const IMC_Unit *u
}
}
- IMCC_debug(imcc, DEBUG_PBC, "\t%d\n", ins);
+ IMCC_debug(imcc, DEBUG_PBC, "\t");
+ IMCC_debug_ins(imcc, DEBUG_PBC, ins);
imcc->npc += ins->opsize;
}

0 comments on commit 64dc724

Please sign in to comment.