Commit 69c7e43b authored by Christoph Mallon's avatar Christoph Mallon
Browse files

When making a 'Minus', automatically infer its mode from its operand.

parent fbe6b518
......@@ -363,8 +363,7 @@ ir_node *duplicate_subgraph(dbg_info *dbg, ir_node *n, ir_node *block)
mode);
case iro_Minus:
return new_rd_Minus(dbg, block,
duplicate_subgraph(dbg, get_Minus_op(n), block),
mode);
duplicate_subgraph(dbg, get_Minus_op(n), block));
case iro_Not:
return new_rd_Not(dbg, block,
duplicate_subgraph(dbg, get_Not_op(n), block));
......
......@@ -173,7 +173,7 @@ int i_mapper_abs(ir_node *call)
ir_node *zero = new_r_Const_null(irg, mode);
ir_node *cmp = new_rd_Cmp(dbg, block, op, zero, ir_relation_less);
ir_node *minus_op = new_rd_Minus(dbg, block, op, mode);
ir_node *minus_op = new_rd_Minus(dbg, block, op);
ir_node *mux;
arch_allow_ifconv_func allow_ifconv = be_get_backend_param()->allow_ifconv;
......@@ -802,7 +802,7 @@ replace_by_call:
if (v == right) {
/* negate in the ("", s) case */
irn = new_rd_Minus(dbg, block, irn, mode);
irn = new_rd_Minus(dbg, block, irn);
}
}
}
......
......@@ -3341,7 +3341,7 @@ static ir_node *transform_node_Sub(ir_node *n)
ir_node *left = get_Minus_op(a);
ir_node *add = new_rd_Add(dbg, block, left, b, mode);
n = new_rd_Minus(dbg, block, add, mode);
n = new_rd_Minus(dbg, block, add);
DBG_OPT_ALGSIM0(oldn, n);
return n;
}
......@@ -3386,7 +3386,7 @@ static ir_node *transform_node_Sub(ir_node *n)
/* Beware of Sub(P, P) which cannot be optimized into a simple Minus ... */
if (mode_is_num(mode) && mode == get_irn_mode(a) && is_Const(a) && is_Const_null(a)) {
n = new_rd_Minus(get_irn_dbg_info(n), get_nodes_block(n), b, mode);
n = new_rd_Minus(get_irn_dbg_info(n), get_nodes_block(n), b);
DBG_OPT_ALGSIM0(oldn, n);
return n;
}
......@@ -3417,20 +3417,16 @@ static ir_node *transform_node_Sub(ir_node *n)
/* FIXME: Does the Conv's work only for two complement or generally? */
if (left == a) {
ir_mode *r_mode = get_irn_mode(right);
n = new_r_Minus(get_nodes_block(n), right, r_mode);
n = new_r_Minus(get_nodes_block(n), right);
/* This Sub is an effective Cast */
if (mode != r_mode)
if (mode != get_irn_mode(right))
n = new_r_Conv(get_nodes_block(n), n, mode);
DBG_OPT_ALGSIM1(oldn, a, b, n);
return n;
} else if (right == a) {
ir_mode *l_mode = get_irn_mode(left);
n = new_r_Minus(get_nodes_block(n), left, l_mode);
n = new_r_Minus(get_nodes_block(n), left);
/* This Sub is an effective Cast */
if (mode != l_mode)
if (mode != get_irn_mode(left))
n = new_r_Conv(get_nodes_block(n), n, mode);
DBG_OPT_ALGSIM1(oldn, a, b, n);
return n;
......@@ -3534,7 +3530,7 @@ static ir_node *transform_node_Sub(ir_node *n)
ir_tarval *const tv_not = tarval_not(tv);
ir_node *const not_c = new_rd_Const(dbgi, irg, tv_not);
ir_node *const and = new_rd_And(dbgi, block, other, not_c, mode);
ir_node *const minus = new_rd_Minus(dbgi, block, and, mode);
ir_node *const minus = new_rd_Minus(dbgi, block, and);
return minus;
}
}
......@@ -3736,7 +3732,7 @@ static ir_node *transform_node_Mul(ir_node *n)
|| (mode_is_float(mode) && tarval_is_minus_one(c1))) {
dbg_info *dbgi = get_irn_dbg_info(n);
ir_node *block = get_nodes_block(n);
return new_rd_Minus(dbgi, block, a, mode);
return new_rd_Minus(dbgi, block, a);
} else if (arith == irma_twos_complement
&& get_tarval_popcount(c1) == 1) {
/* multiplication behaves Shl-like */
......@@ -3763,7 +3759,7 @@ static ir_node *transform_node_Mul(ir_node *n)
/* a * (b & 1) -> a & -(b & 1) */
dbg_info *dbgi = get_irn_dbg_info(n);
ir_node *block = get_nodes_block(n);
ir_node *minus = new_rd_Minus(dbgi, block, bit, mode);
ir_node *minus = new_rd_Minus(dbgi, block, bit);
return new_rd_And(dbgi, block, other, minus, mode);
}
}
......@@ -3929,7 +3925,7 @@ static ir_node *transform_node_Div(ir_node *n)
if (tarval_is_all_one(tv)) {
/* a / -1 */
value = new_rd_Minus(get_irn_dbg_info(n), get_nodes_block(n), a, mode);
value = new_rd_Minus(get_irn_dbg_info(n), get_nodes_block(n), a);
DBG_OPT_CSTEVAL(n, value);
goto make_tuple;
}
......@@ -6942,7 +6938,7 @@ static ir_node *transform_node_Mux(ir_node *n)
if (rel_eq == ir_relation_equal ? is_Const_one(cmp_r) : is_Const_null(cmp_r)) {
/* Mux((a & 1) != 0, 0, b) => -a & b */
cmp_l = new_rd_Minus(dbgi, block, cmp_l, mode);
cmp_l = new_rd_Minus(dbgi, block, cmp_l);
} else {
/* Mux((a & 1) == 0, 0, b) => (a - 1) & b */
ir_node *one = new_rd_Const_one(dbgi, irg, mode);
......
......@@ -1418,7 +1418,7 @@ static ir_node *new_Abs(ir_node *const op, ir_mode *const mode)
ir_graph *const irg = get_irn_irg(op);
ir_node *const zero = new_r_Const_null(irg, mode);
ir_node *const cmp = new_r_Cmp(block, op, zero, ir_relation_less);
ir_node *const minus_op = new_r_Minus(block, op, mode);
ir_node *const minus_op = new_r_Minus(block, op);
ir_node *const mux = new_r_Mux(block, cmp, op, minus_op, mode);
return mux;
}
......
......@@ -1861,7 +1861,7 @@ static void rebuild(multi_op_env *multi_env)
}
if (!curr) {
curr = new_rd_Minus(dbgi, block, inner, mode);
curr = new_rd_Minus(dbgi, block, inner);
} else {
curr = new_rd_Sub(dbgi, block, curr, inner, mode);
}
......
......@@ -548,6 +548,7 @@ class Load(Node):
@op
class Minus(Node):
"""returns the additive inverse of its operand"""
mode = "get_irn_mode(irn_op)"
flags = []
ins = [
("op", "operand")
......
Markdown is supported
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