Permalink
Browse files

[imcc] fix -O2 check types in constant propagation #1043

set reg, const is only a valid const setter ifregx and const have the same type,
otherwise the type are coerced, like set N0, 1 or set I1, 1.5.
Do not propagate such values.
Fixes t/op/jitn_13.pir [GH #1043]
  • Loading branch information...
1 parent 8c9f827 commit 03345bee87e84e3cac2ba3f3d7854434e8749bdf @rurban rurban committed Feb 28, 2014
Showing with 23 additions and 17 deletions.
  1. +8 −5 ChangeLog
  2. +13 −7 compilers/imcc/optimizer.c
  3. +2 −5 t/op/jitn.t
View
13 ChangeLog
@@ -4,12 +4,15 @@
-On -a -v -y -E -dxx. [GH #1033]
+ Fixed imcc -O1. Special-case get_global for branch_cond_loop_swap,
which broke nci tests [GH #1037]
- + Fix imcc part of -O2 to allow used_once elimination only for
+ + Fixed imcc for -O2 to allow used_once elimination only for
purely functional ops without side-effects [GH #1036]
- + Fixed most imcc -O2 errors in constant propagation leading to
- empty ins->op ptrs when deleting or skipping certain instruction
- [GH #1039] and a wrong logic leading to missed detecting writes
- from get_results [GH #1041]. Only 3 remaining -O2 test failures.
+ + Fixed most imcc -O2 errors in constant propagation
+ - leading to empty ins->op ptrs when deleting or skipping
+ certain instruction [GH #1039],
+ - a wrong logic leading to missed detecting writes
+ from get_results [GH #1041], and
+ - propagate only matching types in setters [GH #1043].
+ Only 2 remaining -O2 test failures.
- Build
+ Set emacs buffer-read-only:t tags in generated files [GH #1034]
+ Provide coda for generated include/*.pasm files [GH #1032]
View
20 compilers/imcc/optimizer.c
@@ -713,10 +713,13 @@ constant_propagation(ARGMOD(imc_info_t *imcc), ARGMOD(IMC_Unit *unit))
IMCC_info(imcc, 2, "\tconstant_propagation\n");
for (ins = unit->instructions; ins; ins = ins->next) {
int found = 0;
- if (STREQ(ins->opname, "set") &&
- ins->opsize == 3 && /* no keyed set */
- ins->symregs[1]->type == VTCONST &&
- ins->symregs[0]->set != 'P') { /* no PMC consts */
+ if ((STREQ(ins->opname, "set") || (0 == memcmp(ins->opname, "set_", 4))) &&
+ ins->opsize == 3 && /* no keyed set */
+ ins->symregs[1]->type == VTCONST && /* const rhs */
+ ins->symregs[0]->set != 'P' && /* no PMC consts */
+ /* skip type coercions, only same type GH #1043 */
+ ins->symregs[0]->set == ins->symregs[1]->set)
+ {
found = 1;
c = ins->symregs[1];
o = ins->symregs[0];
@@ -731,7 +734,7 @@ constant_propagation(ARGMOD(imc_info_t *imcc), ARGMOD(IMC_Unit *unit))
if (found) {
Instruction *ins2;
- IMCC_debug(imcc, DEBUG_OPT2, "propagating constant ");
+ IMCC_debug(imcc, DEBUG_OPT2, "propagating constant %s from ", c->name);
IMCC_debug_ins(imcc, DEBUG_OPT2, ins);
for (ins2 = ins->next; ins2; ins2 = ins2->next) {
int i;
@@ -746,7 +749,9 @@ constant_propagation(ARGMOD(imc_info_t *imcc), ARGMOD(IMC_Unit *unit))
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(imcc, DEBUG_OPT2,
+ " checking %s in register %i of ",
+ o->name, i);
IMCC_debug_ins(imcc, DEBUG_OPT2, ins2);
}
if (instruction_writes(ins2, ins2->symregs[i]))
@@ -756,7 +761,8 @@ constant_propagation(ARGMOD(imc_info_t *imcc), ARGMOD(IMC_Unit *unit))
SymReg *old;
op_info_t *oldop = ins2->op;
- IMCC_debug(imcc, DEBUG_OPT2, "\tpropagating into register %i: ", i);
+ IMCC_debug(imcc, DEBUG_OPT2,
+ "\tinto register %i of ", i);
IMCC_debug_ins(imcc, DEBUG_OPT2, ins2);
old = ins2->symregs[i];
ins2->symregs[i] = c;
View
7 t/op/jitn.t
@@ -309,10 +309,8 @@ CODE
-10
OUTPUT
-# rounding behavior, -O2 constant propagation type check
-TODO: {
- local $TODO = 'missing -O2 type check [GH #1043]' if $ENV{TEST_PROG_ARGS} =~ / -O2/;
- pir_output_is( <<'CODE', <<'OUT', "set_i_n testing" );
+# rounding behavior, -O2 constant propagation type check: GH #1043
+pir_output_is( <<'CODE', <<'OUT', "set_i_n testing" );
.sub _main :main
.local num n
.local int i
@@ -335,7 +333,6 @@ TODO: {
CODE
123
OUT
-}
$output = $PConfig{numvalsize} < 16 ? "zero\n" : "not zero\n";
pasm_output_is( <<'CODE', $output, "rounding due to mapped" );

0 comments on commit 03345be

Please sign in to comment.