in[0] = new_rd_Mul(NULL, current_ir_graph, block, c, t1, mode);
in[1] = new_rd_Mul(NULL, current_ir_graph, block, c, t2, mode);
- mode = get_mode_from_ops(in[0], in[1]);
irn = optimize_node(new_ir_node(NULL, current_ir_graph, block, op, mode, 2, in));
/* In some cases it might happen that the new irn is equal the old one, for
/**
* Returns the earliest were a,b are available.
- * Note that we know that we know that a, b both dominate
+ * Note that we know that a, b both dominate
* the block of the previous operation, so one must dominate the other.
*
* If the earliest block is the start block, return curr_blk instead
ir_node *n = *node;
ir_op *op;
ir_node *l, *r, *a, *b, *c, *blk, *irn, *in[2];
- ir_mode *mode;
+ ir_mode *mode, *ma, *mb;
dbg_info *dbg;
l = get_binop_left(n);
return 0;
transform:
- /* check if a+b can be calculted in the same block is the old instruction */
+ /* In some cases a and b might be both of different integer mode, and c a SymConst.
+ * in that case we could either
+ * 1.) cast into unsigned mode
+ * 2.) ignore
+ * we implement the second here
+ */
+ ma = get_irn_mode(a);
+ mb = get_irn_mode(b);
+ if (ma != mb && mode_is_int(ma) && mode_is_int(mb))
+ return 0;
+
+ /* check if a+b can be calculated in the same block is the old instruction */
if (! block_dominates(get_nodes_block(a), blk))
return 0;
if (! block_dominates(get_nodes_block(b), blk))
in[0] = a;
in[1] = b;
- mode = get_mode_from_ops(in[0], in[1]);
+ mode = get_mode_from_ops(a, b);
in[0] = optimize_node(new_ir_node(dbg, current_ir_graph, blk, op, mode, 2, in));
if (op == op_Add || op == op_Sub) {
{
walker_t env;
irg_loopinfo_state state;
+ ir_graph *rem;
assert(get_irg_phase_state(irg) != phase_building);
assert(get_irg_pinned(irg) != op_pin_state_floats &&
if (!get_opt_reassociation() || !get_opt_constant_folding())
return;
+ rem = current_ir_graph;
+ current_ir_graph = irg;
+
/* we use dominance to detect dead blocks */
assure_doms(irg);
env.changes = 0;
env.wq = new_waitq();
- /* now we have collected enough information, optimize */
- irg_walk_graph(irg, NULL, wq_walker, &env);
- do_reassociation(&env);
+ /* disable some optimizations while reassoc is running to prevent endless loops */
+ set_reassoc_running(1);
+ {
+ /* now we have collected enough information, optimize */
+ irg_walk_graph(irg, NULL, wq_walker, &env);
+ do_reassociation(&env);
- /* reverse those rules that do not result in collapsed constants */
- irg_walk_graph(irg, NULL, reverse_rules, &env);
+ /* reverse those rules that do not result in collapsed constants */
+ irg_walk_graph(irg, NULL, reverse_rules, &env);
+ }
+ set_reassoc_running(0);
/* Handle graph state */
if (env.changes) {
}
del_waitq(env.wq);
+ current_ir_graph = rem;
} /* optimize_reassociation */
/* Sets the default reassociation operation for an ir_op_ops. */