X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fopt%2Freassoc.c;h=66174bb8e80dbbaac35f5a7c8bcde3cbac475855;hb=f274dcf35aa0d3f4748387dbddfe50e8d7d44951;hp=5e5a163d0cfba060dd96089e775fb1b7623b206c;hpb=a271fae214fe0c6111298477a7b02983ca7b46c4;p=libfirm diff --git a/ir/opt/reassoc.c b/ir/opt/reassoc.c index 5e5a163d0..66174bb8e 100644 --- a/ir/opt/reassoc.c +++ b/ir/opt/reassoc.c @@ -28,7 +28,7 @@ # include "irloop.h" # include "debug.h" -static firm_dbg_module_t *dbg; +DEBUG_ONLY(static firm_dbg_module_t *dbg;) typedef struct _walker_t { int changes; /* set, if a reassociation take place */ @@ -311,12 +311,23 @@ static int reassoc_Mul(ir_node **node) mode = get_mode_from_ops(in[0], in[1]); irn = optimize_node(new_ir_node(NULL, current_ir_graph, block, op, mode, 2, in)); - DBG((dbg, LEVEL_5, "Applied: (%n .%s. %n) %n %n => (%n %n %n) .%s. (%n %n %n)\n", - t1, get_op_name(op), t2, n, c, t1, n, c, get_op_name(op), t2, n, c)); - exchange(n, irn); - *node = irn; + /* In some cases it might happen that the new irn is equal the old one, for + * instance in: + * (x - 1) * y == x * y - y + * will be transformed back by simpler optimization + * We could switch simple optimizations off, but this only happens iff y + * is a loop-invariant expreassion and that it is not clear if the new form + * is better. + * So, we let the old one. + */ + if (irn != n) { + DBG((dbg, LEVEL_5, "Applied: (%n .%s. %n) %n %n => (%n %n %n) .%s. (%n %n %n)\n", + t1, get_op_name(op), t2, n, c, t1, n, c, get_op_name(op), t2, n, c)); + exchange(n, irn); + *node = irn; - return 1; + return 1; + } } } return 0; @@ -413,5 +424,5 @@ ir_op_ops *firm_set_default_reassoc(opcode code, ir_op_ops *ops) /* initialize the reassociation by adding operations to some opcodes */ void firm_init_reassociation(void) { - dbg = firm_dbg_register("firm.opt.reassoc"); + FIRM_DBG_REGISTER(dbg, "firm.opt.reassoc"); }