Commit da38cf48 authored by Matthias Braun's avatar Matthias Braun
Browse files

normalize x+x to x << 1 in later compiler phases

Also added a new matcher for the ia32 backend matching Shl(x,1) to
Lea(x,x).
parent 9ebabcf3
...@@ -1764,6 +1764,19 @@ static ir_node *gen_Shl(ir_node *node) ...@@ -1764,6 +1764,19 @@ static ir_node *gen_Shl(ir_node *node)
ir_node *left = get_Shl_left(node); ir_node *left = get_Shl_left(node);
ir_node *right = get_Shl_right(node); ir_node *right = get_Shl_right(node);
/* special case Shl x,1 => Lea x,x because Lea has fewer register
* constraints */
if (is_Const_1(right)) {
dbg_info *dbgi = get_irn_dbg_info(node);
ir_node *block = get_nodes_block(node);
ir_node *new_block = be_transform_node(block);
ir_node *new_left = be_transform_node(left);
ir_node *new_node
= new_bd_ia32_Lea(dbgi, new_block, new_left, new_left);
SET_IA32_ORIG_NODE(new_node, node);
return new_node;
}
return gen_shift_binop(node, left, right, new_bd_ia32_Shl, return gen_shift_binop(node, left, right, new_bd_ia32_Shl,
match_mode_neutral | match_immediate); match_mode_neutral | match_immediate);
} }
......
...@@ -2364,18 +2364,25 @@ static ir_node *transform_node_Add(ir_node *n) ...@@ -2364,18 +2364,25 @@ static ir_node *transform_node_Add(ir_node *n)
ir_graph *irg = get_irn_irg(n); ir_graph *irg = get_irn_irg(n);
/* the following code leads to endless recursion when Mul are replaced /* the following code leads to endless recursion when Mul are replaced
* by a simple instruction chain */ * by a simple instruction chain */
if (!irg_is_constrained(irg, IR_GRAPH_CONSTRAINT_ARCH_DEP) if (a == b) {
&& a == b && mode_is_int(mode)) { if (!irg_is_constrained(irg, IR_GRAPH_CONSTRAINT_ARCH_DEP)) {
ir_node *block = get_nodes_block(n); ir_node *block = get_nodes_block(n);
n = new_rd_Mul( n = new_rd_Mul(
get_irn_dbg_info(n), get_irn_dbg_info(n),
block, block,
a, a,
new_r_Const_long(irg, mode, 2), new_r_Const_long(irg, mode, 2),
mode); mode);
DBG_OPT_ALGSIM0(oldn, n, FS_OPT_ADD_A_A); DBG_OPT_ALGSIM0(oldn, n, FS_OPT_ADD_A_A);
return n; return n;
} else {
dbg_info *dbgi = get_irn_dbg_info(n);
ir_node *block = get_nodes_block(n);
ir_node *one = new_r_Const(irg, get_mode_one(mode_Iu));
n = new_rd_Shl(dbgi, block, a, one, mode);
return n;
}
} }
if (is_Minus(a)) { if (is_Minus(a)) {
n = new_rd_Sub( n = new_rd_Sub(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment