Permalink
Browse files

[imcc] Fix one more -O2 bug #1041 get_results write

correctly detect get_results writes to a reg.
skip constant propagation then.

There was an old wrong in instruction_writes for exception handling
before get_results. exceptions are now proper PMCs.

Also add more debug prints for -d41 in constant propagation.

Fixes all testO2 testcases but 3:
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/pmc/exception-old.t             (Wstat: 256 Tests: 22 Failed: 1)
  Failed test:  19
  Non-zero exit status: 1
  • Loading branch information...
1 parent d835140 commit 5ee237a55d446dc8c15c5e65a8ac93f6b4e6f346 Reini Urban committed Feb 28, 2014
Showing with 14 additions and 5 deletions.
  1. +6 −5 compilers/imcc/instructions.c
  2. +8 −0 compilers/imcc/optimizer.c
@@ -173,13 +173,14 @@ instruction_writes(ARGIN(const Instruction *ins), ARGIN(const SymReg *r))
/* a get_results opcode occurs after the actual sub call */
if (ins->op == &core_ops->op_info_table[PARROT_OP_get_results_pc]) {
int i;
-
- /* but only if it isn't the get_results opcode of
- * an ExceptionHandler, which doesn't have
- * a call next
- */
+ /* Old assumption: But only if it isn't the get_results opcode
+ * of an ExceptionHandler, which doesn't have a call next.
+ *
+ * Not with GH #1041: invokecc vs exception handler:
+ * invokecc + get_results x, $I0 does write to $I0
if (ins->prev && (ins->prev->type & ITPCCSUB))
return 0;
+ */
for (i = ins->symreg_count - 1; i >= 0; --i) {
if (ins->symregs[i] == r)
@@ -738,9 +738,17 @@ constant_propagation(ARGMOD(imc_info_t *imcc), ARGMOD(IMC_Unit *unit))
if (ins2->bbindex != ins->bbindex)
/* restrict to within a basic block */
goto next_constant;
+ if (imcc->verbose) {
+ IMCC_debug(imcc, DEBUG_OPT2, "\tchecking op ");
+ IMCC_debug_ins(imcc, DEBUG_OPT2, ins2);
+ }
/* was opsize - 2, changed to n_r - 1 */
for (i = ins2->symreg_count - 1; i >= 0; i--) {
if (STREQ(o->name, ins2->symregs[i]->name)) {
+ if (imcc->verbose) {
+ IMCC_debug(imcc, DEBUG_OPT2, " checking register %i ", i);
+ IMCC_debug_ins(imcc, DEBUG_OPT2, ins2);
+ }
if (instruction_writes(ins2, ins2->symregs[i]))
goto next_constant;
else if (instruction_reads(ins2, ins2->symregs[i])) {

0 comments on commit 5ee237a

Please sign in to comment.