tarval_add(ta, tb);
return tarval_carry() ? get_mode_one(m) : get_mode_null(m);
} else {
- if ( (classify_tarval(ta) == TV_CLASSIFY_NULL)
- || (classify_tarval(tb) == TV_CLASSIFY_NULL))
+ if (tarval_is_null(ta) || tarval_is_null(tb))
return get_mode_null(m);
}
return tarval_bad;
if ((ta != tarval_bad) && (tb != tarval_bad)) {
return tarval_cmp(ta, tb) == pn_Cmp_Lt ? get_mode_one(m) : get_mode_null(m);
- } else if (classify_tarval(ta) == TV_CLASSIFY_NULL) {
+ } else if (tarval_is_null(ta)) {
return get_mode_null(m);
}
return tarval_bad;
if ((ta != tarval_bad) && (tb != tarval_bad)) {
return tarval_and (ta, tb);
} else {
- tarval *v;
-
- if ( (classify_tarval ((v = ta)) == TV_CLASSIFY_NULL)
- || (classify_tarval ((v = tb)) == TV_CLASSIFY_NULL)) {
- return v;
- }
+ if (tarval_is_null(ta)) return ta;
+ if (tarval_is_null(tb)) return tb;
}
return tarval_bad;
} /* computed_value_And */
if ((ta != tarval_bad) && (tb != tarval_bad)) {
return tarval_or (ta, tb);
} else {
- tarval *v;
- if ( (classify_tarval ((v = ta)) == TV_CLASSIFY_ALL_ONE)
- || (classify_tarval ((v = tb)) == TV_CLASSIFY_ALL_ONE)) {
- return v;
- }
+ if (tarval_is_all_one(ta)) return ta;
+ if (tarval_is_all_one(tb)) return tb;
}
return tarval_bad;
} /* computed_value_Or */
* which happens in this rare construction: NULL + 3.
* Then, a Conv would be needed which we cannot include here.
*/
- if (classify_tarval (tv) == TV_CLASSIFY_NULL) {
- if (get_irn_mode(on) == get_irn_mode(n)) {
- n = on;
+ if (tarval_is_null(tv) && get_irn_mode(on) == get_irn_mode(n)) {
+ n = on;
- DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_NEUTRAL_0);
- }
+ DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_NEUTRAL_0);
}
return n;
ir_node *a = get_binop_left(n);
ir_node *b = get_binop_right(n);
- if (classify_tarval(value_of(b)) == TV_CLASSIFY_NULL) {
+ if (is_Const(b) && is_Const_null(b)) {
n = a;
DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_NEUTRAL_0);
b = get_Sub_right(n);
/* Beware: modes might be different */
- if (classify_tarval(value_of(b)) == TV_CLASSIFY_NULL) {
+ if (is_Const(b) && is_Const_null(b)) {
ir_node *a = get_Sub_left(n);
if (mode == get_irn_mode(a)) {
n = a;
ir_node *b = get_Mul_right(n);
/* Mul is commutative and has again an other neutral element. */
- if (classify_tarval(value_of(a)) == TV_CLASSIFY_ONE) {
+ if (is_Const(a) && is_Const_one(a)) {
n = b;
DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_NEUTRAL_1);
- } else if (classify_tarval(value_of(b)) == TV_CLASSIFY_ONE) {
+ } else if (is_Const(b) && is_Const_one(b)) {
n = a;
DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_NEUTRAL_1);
}
ir_node *b = get_Div_right(n);
/* Div is not commutative. */
- if (classify_tarval(value_of(b)) == TV_CLASSIFY_ONE) { /* div(x, 1) == x */
+ if (is_Const(b) && is_Const_one(b)) { /* div(x, 1) == x */
/* Turn Div into a tuple (mem, bad, a) */
ir_node *mem = get_Div_mem(n);
ir_node *blk = get_irn_n(n, -1);
ir_node *b = get_Quot_right(n);
/* Div is not commutative. */
- if (classify_tarval(value_of(b)) == TV_CLASSIFY_ONE) { /* Quot(x, 1) == x */
+ if (is_Const(b) && is_Const_one(b)) { /* Quot(x, 1) == x */
/* Turn Quot into a tuple (mem, jmp, bad, a) */
ir_node *mem = get_Quot_mem(n);
ir_node *blk = get_irn_n(n, -1);
ir_node *b = get_DivMod_right(n);
/* Div is not commutative. */
- if (classify_tarval(value_of(b)) == TV_CLASSIFY_ONE) { /* div(x, 1) == x */
+ if (is_Const(b) && is_Const_one(b)) { /* div(x, 1) == x */
/* Turn DivMod into a tuple (mem, jmp, bad, a, 0) */
ir_node *a = get_DivMod_left(n);
ir_node *mem = get_Div_mem(n);
if (a == b) {
n = a; /* Or has it's own neutral element */
DBG_OPT_ALGSIM0(oldn, n, FS_OPT_OR);
- } else if (classify_tarval(value_of(a)) == TV_CLASSIFY_NULL) {
+ } else if (is_Const(a) && is_Const_null(a)) {
n = b;
DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_OR);
- } else if (classify_tarval(value_of(b)) == TV_CLASSIFY_NULL) {
+ } else if (is_Const(b) && is_Const_null(b)) {
n = a;
DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_OR);
}
DBG_OPT_ALGSIM0(oldn, n, FS_OPT_AND);
return n;
}
- if (classify_tarval(value_of(a)) == TV_CLASSIFY_ALL_ONE) {
+ if (is_Const(a) && is_Const_all_one(a)) {
n = b;
DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_AND);
return n;
}
- if (classify_tarval(value_of(b)) == TV_CLASSIFY_ALL_ONE) {
+ if (is_Const(b) && is_Const_all_one(b)) {
n = a;
DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_AND);
return n;
* However, if +0 and -0 is handled differently, we cannot use the first one.
*/
if (get_irn_op(cmp) == op_Cmp && get_Cmp_left(cmp) == a) {
- if (classify_Const(get_Cmp_right(cmp)) == CNST_NULL) {
+ ir_node *cmp_r = get_Cmp_right(cmp);
+ if (is_Const(cmp_r) && is_Const_null(cmp_r)) {
/* Mux(a CMP 0, X, a) */
if (get_irn_op(b) == op_Minus && get_Minus_op(b) == a) {
/* Mux(a CMP 0, -a, a) */
n = a;
DBG_OPT_ALGSIM0(oldn, n, FS_OPT_MUX_TRANSFORM);
}
- } else if (classify_Const(b) == CNST_NULL) {
+ } else if (is_Const(b) && is_Const_null(b)) {
/* Mux(a CMP 0, 0, a) */
if (proj_nr == pn_Cmp_Lg || proj_nr == pn_Cmp_Ne) {
/* Mux(a != 0, 0, a) ==> a */
ir_node *left = get_Cmp_left(n);
ir_node *right = get_Cmp_right(n);
- if (get_irn_op(left) == op_Minus && get_irn_op(right) == op_Minus &&
+ if (is_Minus(left) && is_Minus(right) &&
!mode_overflow_on_unary_Minus(get_irn_mode(left))) {
left = get_Minus_op(left);
right = get_Minus_op(right);
if (is_Not(a)) {
ir_node *op = get_Not_op(a);
- if (classify_Const(b) == CNST_ONE) {
+ if (is_Const(b) && is_Const_one(b)) {
/* ~x + 1 = -x */
ir_node *blk = get_irn_n(n, -1);
n = new_rd_Minus(get_irn_dbg_info(n), current_ir_graph, blk, op, mode);
if (mode_is_float(mode) && (get_irg_fp_model(current_ir_graph) & fp_strict_algebraic))
return n;
- /* Sub(a, Const) -> Add(a, -Const) */
if (is_Const(b) && get_irn_mode(b) != mode_P) {
- ir_node* cnst = const_negate(b);
+ /* a - C -> a + (-C) */
+ ir_node *cnst = const_negate(b);
if (cnst != NULL) {
ir_node *block = get_nodes_block(n);
dbg_info *dbgi = get_irn_dbg_info(n);
ir_graph *irg = get_irn_irg(n);
- ir_node *add = new_rd_Add(dbgi, irg, block, a, cnst, mode);
- return add;
+ n = new_rd_Add(dbgi, irg, block, a, cnst, mode);
+ DBG_OPT_ALGSIM0(oldn, n, FS_OPT_SUB_TO_ADD);
+ return n;
}
}
- if (is_Minus(a)) { /* -a - b -> -(a + b) */
+ if (is_Minus(a)) { /* (-a) - b -> -(a + b) */
ir_graph *irg = current_ir_graph;
dbg_info *dbg = get_irn_dbg_info(n);
ir_node *block = get_nodes_block(n);
ir_node *left = get_Minus_op(a);
ir_mode *mode = get_irn_mode(n);
ir_node *add = new_rd_Add(dbg, irg, block, left, b, mode);
- ir_node *neg = new_rd_Minus(dbg, irg, block, add, mode);
- return neg;
- } else if (is_Minus(b)) { /* a - -b -> a + b */
+
+ n = new_rd_Minus(dbg, irg, block, add, mode);
+ DBG_OPT_ALGSIM0(oldn, n, FS_OPT_SUB_TO_ADD);
+ return n;
+ } else if (is_Minus(b)) { /* a - (-b) -> a + b */
ir_graph *irg = current_ir_graph;
dbg_info *dbg = get_irn_dbg_info(n);
ir_node *block = get_nodes_block(n);
ir_node *right = get_Minus_op(b);
ir_mode *mode = get_irn_mode(n);
- ir_node *add = new_rd_Add(dbg, irg, block, a, right, mode);
- return add;
+
+ n = new_rd_Add(dbg, irg, block, a, right, mode);
+ DBG_OPT_ALGSIM0(oldn, n, FS_OPT_SUB_MINUS);
+ return n;
} else if (is_Sub(b)) { /* a - (b - c) -> a + (c - b) */
ir_graph *irg = current_ir_graph;
dbg_info *s_dbg = get_irn_dbg_info(b);
dbg_info *a_dbg = get_irn_dbg_info(n);
ir_node *a_block = get_nodes_block(n);
ir_mode *a_mode = get_irn_mode(n);
- ir_node *add = new_rd_Add(a_dbg, irg, a_block, a, sub, a_mode);
- return add;
- } else if (is_Mul(b)) { /* a - (b * const2) -> a + (b * -const2) */
- ir_node* m_right = get_Mul_right(b);
+
+ n = new_rd_Add(a_dbg, irg, a_block, a, sub, a_mode);
+ DBG_OPT_ALGSIM0(oldn, n, FS_OPT_SUB_TO_ADD);
+ return n;
+ } else if (is_Mul(b)) { /* a - (b * C) -> a + (b * -C) */
+ ir_node *m_right = get_Mul_right(b);
if (is_Const(m_right)) {
- ir_node* cnst2 = const_negate(m_right);
+ ir_node *cnst2 = const_negate(m_right);
if (cnst2 != NULL) {
ir_graph *irg = current_ir_graph;
dbg_info *m_dbg = get_irn_dbg_info(b);
dbg_info *a_dbg = get_irn_dbg_info(n);
ir_node *a_block = get_nodes_block(n);
ir_mode *a_mode = get_irn_mode(n);
- ir_node *add = new_rd_Add(a_dbg, irg, a_block, a, mul, a_mode);
- return add;
+
+ n = new_rd_Add(a_dbg, irg, a_block, a, mul, a_mode);
+ DBG_OPT_ALGSIM0(oldn, n, FS_OPT_SUB_TO_ADD);
+ return n;
}
}
}
/* Beware of Sub(P, P) which cannot be optimized into a simple Minus ... */
- if (mode_is_num(mode) && mode == get_irn_mode(a) && (classify_Const(a) == CNST_NULL)) {
+ 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),
current_ir_graph,
}
}
if (is_Minus(a)) {
- if (is_Const(b)) { /* -a * const -> a * -const */
- ir_node* cnst = const_negate(b);
+ if (is_Const(b)) { /* (-a) * const -> a * -const */
+ ir_node *cnst = const_negate(b);
if (cnst != NULL) {
- set_Mul_left( n, get_Minus_op(a));
- set_Mul_right(n, cnst);
+ dbg_info *dbgi = get_irn_dbg_info(n);
+ ir_node *block = get_nodes_block(n);
+ n = new_rd_Mul(dbgi, current_ir_graph, block, get_Minus_op(a), cnst, mode);
+ DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_MUL_MINUS_1);
return n;
}
- } else if (is_Minus(b)) { /* -a * -b -> a * b */
- set_Mul_left( n, get_Minus_op(a));
- set_Mul_right(n, get_Minus_op(b));
+ } else if (is_Minus(b)) { /* (-a) * (-b) -> a * b */
+ dbg_info *dbgi = get_irn_dbg_info(n);
+ ir_node *block = get_nodes_block(n);
+ n = new_rd_Mul(dbgi, current_ir_graph, block, get_Minus_op(a), get_Minus_op(b), mode);
+ DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_MUL_MINUS_MINUS);
return n;
- } else if (is_Sub(b)) { /* -a * (b - c) -> a * (c - b) */
+ } else if (is_Sub(b)) { /* (-a) * (b - c) -> a * (c - b) */
ir_node *sub_l = get_Sub_left(b);
ir_node *sub_r = get_Sub_right(b);
- dbg_info *dbgi = get_irn_dbg_info(b);
+ dbg_info *dbgi = get_irn_dbg_info(n);
ir_graph *irg = current_ir_graph;
- ir_mode *mode = get_irn_mode(b);
- ir_node *block = get_nodes_block(b);
+ ir_node *block = get_nodes_block(n);
ir_node *new_b = new_rd_Sub(dbgi, irg, block, sub_r, sub_l, mode);
- set_Mul_left( n, get_Minus_op(a));
- set_Mul_right(n, new_b);
+ n = new_rd_Mul(dbgi, irg, block, get_Minus_op(a), new_b, mode);
+ DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_MUL_MINUS);
return n;
}
} else if (is_Minus(b)) {
- if (is_Sub(a)) { /* (a - b) * -c -> (b - a) * c */
+ if (is_Sub(a)) { /* (a - b) * (-c) -> (b - a) * c */
ir_node *sub_l = get_Sub_left(a);
ir_node *sub_r = get_Sub_right(a);
- dbg_info *dbgi = get_irn_dbg_info(a);
+ dbg_info *dbgi = get_irn_dbg_info(n);
ir_graph *irg = current_ir_graph;
- ir_mode *mode = get_irn_mode(a);
- ir_node *block = get_nodes_block(a);
+ ir_node *block = get_nodes_block(n);
ir_node *new_a = new_rd_Sub(dbgi, irg, block, sub_r, sub_l, mode);
- set_Mul_left (n, new_a);
- set_Mul_right(n, get_Minus_op(b));
+ n = new_rd_Mul(dbgi, irg, block, new_a, get_Minus_op(b), mode);
+ DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_MUL_MINUS);
return n;
}
}
ir_node *c, *oldn = n;
ir_node *a = get_And_left(n);
ir_node *b = get_And_right(n);
+ ir_mode *mode;
HANDLE_BINOP_PHI(tarval_and, a,b,c);
+ mode = get_irn_mode(n);
+
/* we can evaluate 2 Projs of the same Cmp */
- if (get_irn_mode(n) == mode_b && is_Proj(a) && is_Proj(b)) {
+ if (mode == mode_b && is_Proj(a) && is_Proj(b)) {
ir_node *pred_a = get_Proj_pred(a);
ir_node *pred_b = get_Proj_pred(b);
- if(pred_a == pred_b) {
+ if (pred_a == pred_b) {
dbg_info *dbgi = get_irn_dbg_info(n);
ir_node *block = get_nodes_block(pred_a);
pn_Cmp pn_a = get_Proj_proj(a);
/* yes, we can simply calculate with pncs */
pn_Cmp new_pnc = pn_a & pn_b;
- return new_rd_Proj(dbgi, current_ir_graph, block, pred_a, mode_b,
- new_pnc);
+ return new_rd_Proj(dbgi, current_ir_graph, block, pred_a, mode_b, new_pnc);
}
}
if (is_Or(a)) {
/* (a|b) & ~(a&b) = a^b */
ir_node *block = get_nodes_block(n);
- n = new_rd_Eor(get_irn_dbg_info(n), current_ir_graph, block, ba, bb, get_irn_mode(n));
+ n = new_rd_Eor(get_irn_dbg_info(n), current_ir_graph, block, ba, bb, mode);
DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_TO_EOR);
return n;
}
/* (a|b) & ~(a&b) = a^b */
ir_node *block = get_nodes_block(n);
- n = new_rd_Eor(get_irn_dbg_info(n), current_ir_graph, block, aa, ab, get_irn_mode(n));
+ n = new_rd_Eor(get_irn_dbg_info(n), current_ir_graph, block, aa, ab, mode);
DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_TO_EOR);
return n;
}
}
}
+ }
+ if (is_Eor(a)) {
+ ir_node *al = get_Eor_left(a);
+ ir_node *ar = get_Eor_right(a);
+
+ if (al == b) {
+ /* (b ^ a) & b -> ~a & b */
+ dbg_info *dbg = get_irn_dbg_info(n);
+ ir_node *block = get_nodes_block(n);
+
+ ar = new_rd_Minus(dbg, current_ir_graph, block, ar, mode);
+ n = new_rd_And(dbg, current_ir_graph, block, ar, b, mode);
+ DBG_OPT_ALGSIM0(oldn, n, FS_OPT_EOR_TO_NOT);
+ return n;
+ }
+ if (ar == b) {
+ /* (a ^ b) & b -> ~a & b */
+ dbg_info *dbg = get_irn_dbg_info(n);
+ ir_node *block = get_nodes_block(n);
+
+ al = new_rd_Minus(dbg, current_ir_graph, block, al, mode);
+ n = new_rd_And(dbg, current_ir_graph, block, al, b, mode);
+ DBG_OPT_ALGSIM0(oldn, n, FS_OPT_EOR_TO_NOT);
+ return n;
+ }
+ }
+ if (is_Eor(b)) {
+ ir_node *bl = get_Eor_left(b);
+ ir_node *br = get_Eor_right(b);
+
+ if (bl == a) {
+ /* a & (a ^ b) -> a & ~b */
+ dbg_info *dbg = get_irn_dbg_info(n);
+ ir_node *block = get_nodes_block(n);
+
+ br = new_rd_Minus(dbg, current_ir_graph, block, br, mode);
+ n = new_rd_And(dbg, current_ir_graph, block, br, a, mode);
+ DBG_OPT_ALGSIM0(oldn, n, FS_OPT_EOR_TO_NOT);
+ return n;
+ }
+ if (br == a) {
+ /* a & (b ^ a) -> a & ~b */
+ dbg_info *dbg = get_irn_dbg_info(n);
+ ir_node *block = get_nodes_block(n);
+
+ bl = new_rd_Minus(dbg, current_ir_graph, block, bl, mode);
+ n = new_rd_And(dbg, current_ir_graph, block, bl, a, mode);
+ DBG_OPT_ALGSIM0(oldn, n, FS_OPT_EOR_TO_NOT);
+ return n;
+ }
+ }
+ if (is_Not(a) && is_Not(b)) {
+ /* ~a & ~b = ~(a|b) */
+ ir_node *block = get_nodes_block(n);
+ ir_mode *mode = get_irn_mode(n);
+ a = get_Not_op(a);
+ b = get_Not_op(b);
+ n = new_rd_Or(get_irn_dbg_info(n), current_ir_graph, block, a, b, mode);
+ n = new_rd_Not(get_irn_dbg_info(n), current_ir_graph, block, n, mode);
+ DBG_OPT_ALGSIM0(oldn, n, FS_OPT_DEMORGAN);
+ return n;
}
n = transform_bitwise_distributive(n, transform_node_And);
} else if ((mode == mode_b)
&& (get_irn_op(a) == op_Proj)
&& (get_irn_mode(a) == mode_b)
- && (classify_tarval (value_of(b)) == TV_CLASSIFY_ONE)
+ && is_Const(b) && is_Const_one(b)
&& (get_irn_op(get_Proj_pred(a)) == op_Cmp)) {
/* The Eor negates a Cmp. The Cmp has the negated result anyways! */
n = new_r_Proj(current_ir_graph, get_irn_n(n, -1), get_Proj_pred(a),
mode_b, get_negated_pnc(get_Proj_proj(a), mode));
DBG_OPT_ALGSIM0(oldn, n, FS_OPT_EOR_TO_NOT_BOOL);
- } else if ((mode == mode_b)
- && (classify_tarval (value_of(b)) == TV_CLASSIFY_ONE)) {
+ } else if (mode == mode_b && is_Const(b) && is_Const_one(b)) {
/* The Eor is a Not. Replace it by a Not. */
/* ????!!!Extend to bitfield 1111111. */
n = new_r_Not(current_ir_graph, get_irn_n(n, -1), a, mode_b);
DBG_OPT_ALGSIM0(oldn, n, FS_OPT_NOT_CMP);
return n;
}
- if (op_a == op_Sub && classify_Const(get_Sub_right(a)) == CNST_ONE) {
- /* ~(x-1) = -x */
- ir_node *op = get_Sub_left(a);
- ir_node *blk = get_irn_n(n, -1);
- n = new_rd_Minus(get_irn_dbg_info(n), current_ir_graph, blk, op, get_irn_mode(n));
- DBG_OPT_ALGSIM0(oldn, n, FS_OPT_NOT_MINUS_1);
+ if (op_a == op_Sub) {
+ ir_node *sub_r = get_Sub_right(a);
+ if (is_Const(sub_r) && is_Const_one(sub_r)) {
+ /* ~(x-1) = -x */
+ ir_node *op = get_Sub_left(a);
+ ir_node *blk = get_irn_n(n, -1);
+ n = new_rd_Minus(get_irn_dbg_info(n), current_ir_graph, blk, op, get_irn_mode(n));
+ DBG_OPT_ALGSIM0(oldn, n, FS_OPT_NOT_MINUS_1);
+ }
}
return n;
} /* transform_node_Not */
}
}
+ /* TODO extend to arbitrary constants */
+ if (is_Conv(left) && is_Const(right) && is_Const_null(right)) {
+ ir_mode* mode = get_irn_mode(left);
+ ir_node* op = get_Conv_op(left);
+ ir_mode* op_mode = get_irn_mode(op);
+
+ if (get_mode_size_bits(mode) > get_mode_size_bits(op_mode) &&
+ (mode_is_signed(mode) || !mode_is_signed(op_mode))) {
+ ir_node *null = new_Const(op_mode, get_mode_null(op_mode));
+ set_Cmp_left( n, op);
+ set_Cmp_right(n, null);
+ return proj;
+ }
+ }
+
/* remove Casts */
if (is_Cast(left))
left = get_Cast_op(left);
default:
break;
}
-
}
}
if (proj_nr == pn_Cmp_Eq || proj_nr == pn_Cmp_Lg) {
/* a-b == 0 ==> a == b, a-b != 0 ==> a != b */
- if (classify_tarval(tv) == TV_CLASSIFY_NULL && is_Sub(left)) {
+ if (tarval_is_null(tv) && is_Sub(left)) {
right =get_Sub_right(left);
left = get_Sub_left(left);
tv2 = get_Const_tarval(c2);
tv = tarval_or(tv1, tv2);
- if (classify_tarval(tv) == TV_CLASSIFY_ALL_ONE) {
- /* the AND does NOT clear a bit with isn't set be the OR */
+ if (tarval_is_all_one(tv)) {
+ /* the AND does NOT clear a bit with isn't set by the OR */
set_Or_left(or, or_l);
set_Or_right(or, c1);
tv4 = get_Const_tarval(c4);
tv = tarval_or(tv4, tv2);
- if (classify_tarval(tv) != TV_CLASSIFY_ALL_ONE) {
+ if (!tarval_is_all_one(tv)) {
/* have at least one 0 at the same bit position */
return or;
}
ir_node *a = get_Or_left(n);
ir_node *b = get_Or_right(n);
+ if (is_Not(a) && is_Not(b)) {
+ /* ~a | ~b = ~(a&b) */
+ ir_node *block = get_nodes_block(n);
+ ir_mode *mode = get_irn_mode(n);
+
+ a = get_Not_op(a);
+ b = get_Not_op(b);
+ n = new_rd_And(get_irn_dbg_info(n), current_ir_graph, block, a, b, mode);
+ n = new_rd_Not(get_irn_dbg_info(n), current_ir_graph, block, n, mode);
+ DBG_OPT_ALGSIM0(oldn, n, FS_OPT_DEMORGAN);
+ return n;
+ }
+
/* we can evaluate 2 Projs of the same Cmp */
- if(get_irn_mode(n) == mode_b && is_Proj(a) && is_Proj(b)) {
+ if (get_irn_mode(n) == mode_b && is_Proj(a) && is_Proj(b)) {
ir_node *pred_a = get_Proj_pred(a);
ir_node *pred_b = get_Proj_pred(b);
- if(pred_a == pred_b) {
+ if (pred_a == pred_b) {
dbg_info *dbgi = get_irn_dbg_info(n);
ir_node *block = get_nodes_block(pred_a);
pn_Cmp pn_a = get_Proj_proj(a);
* However, if +0 and -0 is handled differently, we cannot use the first
* one.
*/
- if (get_irn_op(cmp) == op_Cmp
- && classify_Const(get_Cmp_right(cmp)) == CNST_NULL) {
- ir_node *block = get_irn_n(n, -1);
-
- if(is_negated_value(f, t)) {
- ir_node *cmp_left = get_Cmp_left(cmp);
-
- /* Psi(a >= 0, a, -a) = Psi(a <= 0, -a, a) ==> Abs(a) */
- if ( (cmp_left == t && (pn == pn_Cmp_Ge || pn == pn_Cmp_Gt))
- || (cmp_left == f && (pn == pn_Cmp_Le || pn == pn_Cmp_Lt)))
- {
- n = new_rd_Abs(get_irn_dbg_info(n), current_ir_graph, block,
- cmp_left, mode);
- DBG_OPT_ALGSIM1(oldn, cmp, sel, n, FS_OPT_MUX_TO_ABS);
- return n;
- /* Psi(a <= 0, a, -a) = Psi(a >= 0, -a, a) ==> -Abs(a) */
- } else if ((cmp_left == t && (pn == pn_Cmp_Le || pn == pn_Cmp_Lt))
- || (cmp_left == f && (pn == pn_Cmp_Ge || pn == pn_Cmp_Gt)))
- {
- n = new_rd_Abs(get_irn_dbg_info(n), current_ir_graph, block,
- cmp_left, mode);
- n = new_rd_Minus(get_irn_dbg_info(n), current_ir_graph,
- block, n, mode);
- DBG_OPT_ALGSIM1(oldn, cmp, sel, n, FS_OPT_MUX_TO_ABS);
- return n;
+ if (is_Cmp(cmp)) {
+ ir_node *cmp_r = get_Cmp_right(cmp);
+ if (is_Const(cmp_r) && is_Const_null(cmp_r)) {
+ ir_node *block = get_irn_n(n, -1);
+
+ if(is_negated_value(f, t)) {
+ ir_node *cmp_left = get_Cmp_left(cmp);
+
+ /* Psi(a >= 0, a, -a) = Psi(a <= 0, -a, a) ==> Abs(a) */
+ if ( (cmp_left == t && (pn == pn_Cmp_Ge || pn == pn_Cmp_Gt))
+ || (cmp_left == f && (pn == pn_Cmp_Le || pn == pn_Cmp_Lt)))
+ {
+ n = new_rd_Abs(get_irn_dbg_info(n), current_ir_graph, block,
+ cmp_left, mode);
+ DBG_OPT_ALGSIM1(oldn, cmp, sel, n, FS_OPT_MUX_TO_ABS);
+ return n;
+ /* Psi(a <= 0, a, -a) = Psi(a >= 0, -a, a) ==> -Abs(a) */
+ } else if ((cmp_left == t && (pn == pn_Cmp_Le || pn == pn_Cmp_Lt))
+ || (cmp_left == f && (pn == pn_Cmp_Ge || pn == pn_Cmp_Gt)))
+ {
+ n = new_rd_Abs(get_irn_dbg_info(n), current_ir_graph, block,
+ cmp_left, mode);
+ n = new_rd_Minus(get_irn_dbg_info(n), current_ir_graph,
+ block, n, mode);
+ DBG_OPT_ALGSIM1(oldn, cmp, sel, n, FS_OPT_MUX_TO_ABS);
+ return n;
+ }
}
- }
- if (mode_is_int(mode) && mode_is_signed(mode) &&
- get_mode_arithmetic(mode) == irma_twos_complement) {
- ir_node *x = get_Cmp_left(cmp);
+ if (mode_is_int(mode) && mode_is_signed(mode) &&
+ get_mode_arithmetic(mode) == irma_twos_complement) {
+ ir_node *x = get_Cmp_left(cmp);
- /* the following optimization works only with signed integer two-complement mode */
+ /* the following optimization works only with signed integer two-complement mode */
- if (mode == get_irn_mode(x)) {
- /*
- * FIXME: this restriction is two rigid, as it would still
- * work if mode(x) = Hs and mode == Is, but at least it removes
- * all wrong cases.
- */
- if ((pn == pn_Cmp_Lt || pn == pn_Cmp_Le) &&
- classify_Const(t) == CNST_ALL_ONE &&
- classify_Const(f) == CNST_NULL) {
+ if (mode == get_irn_mode(x)) {
/*
- * Mux(x:T </<= 0, 0, -1) -> Shrs(x, sizeof_bits(T) - 1)
- * Conditions:
- * T must be signed.
+ * FIXME: this restriction is two rigid, as it would still
+ * work if mode(x) = Hs and mode == Is, but at least it removes
+ * all wrong cases.
*/
- n = new_rd_Shrs(get_irn_dbg_info(n),
- current_ir_graph, block, x,
+ if ((pn == pn_Cmp_Lt || pn == pn_Cmp_Le) &&
+ is_Const(t) && is_Const_all_one(t) &&
+ is_Const(f) && is_Const_null(f)) {
+ /*
+ * Mux(x:T </<= 0, 0, -1) -> Shrs(x, sizeof_bits(T) - 1)
+ * Conditions:
+ * T must be signed.
+ */
+ n = new_rd_Shrs(get_irn_dbg_info(n),
+ current_ir_graph, block, x,
+ new_r_Const_long(current_ir_graph, block, mode_Iu,
+ get_mode_size_bits(mode) - 1),
+ mode);
+ DBG_OPT_ALGSIM1(oldn, cmp, sel, n, FS_OPT_MUX_TO_SHR);
+ return n;
+ } else if ((pn == pn_Cmp_Gt || pn == pn_Cmp_Ge) &&
+ is_Const(t) && is_Const_one(t) &&
+ is_Const(f) && is_Const_null(f)) {
+ /*
+ * Mux(x:T >/>= 0, 0, 1) -> Shr(-x, sizeof_bits(T) - 1)
+ * Conditions:
+ * T must be signed.
+ */
+ n = new_rd_Shr(get_irn_dbg_info(n),
+ current_ir_graph, block,
+ new_r_Minus(current_ir_graph, block, x, mode),
new_r_Const_long(current_ir_graph, block, mode_Iu,
get_mode_size_bits(mode) - 1),
mode);
- DBG_OPT_ALGSIM1(oldn, cmp, sel, n, FS_OPT_MUX_TO_SHR);
- return n;
- } else if ((pn == pn_Cmp_Gt || pn == pn_Cmp_Ge) &&
- classify_Const(t) == CNST_ONE &&
- classify_Const(f) == CNST_NULL) {
- /*
- * Mux(x:T >/>= 0, 0, 1) -> Shr(-x, sizeof_bits(T) - 1)
- * Conditions:
- * T must be signed.
- */
- n = new_rd_Shr(get_irn_dbg_info(n),
- current_ir_graph, block,
- new_r_Minus(current_ir_graph, block, x, mode),
- new_r_Const_long(current_ir_graph, block, mode_Iu,
- get_mode_size_bits(mode) - 1),
- mode);
- DBG_OPT_ALGSIM1(oldn, cmp, sel, n, FS_OPT_MUX_TO_SHR);
- return n;
+ DBG_OPT_ALGSIM1(oldn, cmp, sel, n, FS_OPT_MUX_TO_SHR);
+ return n;
+ }
}
}
}
del_pset(value_table);
} /* del_identities */
+/**
+ * Normalize a node by putting constants (and operands with smaller
+ * node index) on the right
+ *
+ * @param n The node to normalize
+ */
+static void normalize_node(ir_node *n) {
+ if (get_opt_reassociation()) {
+ if (is_op_commutative(get_irn_op(n))) {
+ ir_node *l = get_binop_left(n);
+ ir_node *r = get_binop_right(n);
+ int l_idx = get_irn_idx(l);
+ int r_idx = get_irn_idx(r);
+
+ /* For commutative operators perform a OP b == b OP a but keep
+ constants on the RIGHT side. This helps greatly in some optimizations.
+ Moreover we use the idx number to make the form deterministic. */
+ if (is_irn_constlike(l))
+ l_idx = -l_idx;
+ if (is_irn_constlike(r))
+ r_idx = -r_idx;
+ if (l_idx < r_idx) {
+ set_binop_left(n, r);
+ set_binop_right(n, l);
+ }
+ }
+ }
+} /* normalize_node */
+
/**
* Return the canonical node computing the same value as n.
*
if (!value_table) return n;
- if (get_opt_reassociation()) {
- if (is_op_commutative(get_irn_op(n))) {
- ir_node *l = get_binop_left(n);
- ir_node *r = get_binop_right(n);
-
- /* for commutative operators perform a OP b == b OP a */
- if (get_irn_idx(l) > get_irn_idx(r)) {
- set_binop_left(n, r);
- set_binop_right(n, l);
- }
- }
- }
+ normalize_node(n);
o = pset_find(value_table, n, ir_node_hash(n));
if (!o) return n;
if (!value_table) return n;
- if (get_opt_reassociation()) {
- if (is_op_commutative(get_irn_op(n))) {
- ir_node *l = get_binop_left(n);
- ir_node *r = get_binop_right(n);
- int l_idx = get_irn_idx(l);
- int r_idx = get_irn_idx(r);
-
- /* For commutative operators perform a OP b == b OP a but keep
- constants on the RIGHT side. This helps greatly in some optimizations.
- Moreover we use the idx number to make the form deterministic. */
- if (is_irn_constlike(l))
- l_idx = -l_idx;
- if (is_irn_constlike(r))
- r_idx = -r_idx;
- if (l_idx < r_idx) {
- set_binop_left(n, r);
- set_binop_right(n, l);
- }
- }
- }
-
+ normalize_node(n);
/* lookup or insert in hash table with given hash key. */
o = pset_insert(value_table, n, ir_node_hash(n));
* Garbage in, garbage out. If a node has a dead input, i.e., the
* Bad node is input to the node, return the Bad node.
*/
-static INLINE ir_node *gigo(ir_node *node) {
+static ir_node *gigo(ir_node *node) {
int i, irn_arity;
ir_op *op = get_irn_op(node);
/* evaluation was successful -- replace the node. */
irg_kill_node(current_ir_graph, n);
- nw = new_Const(get_tarval_mode (tv), tv);
+ nw = new_Const(get_tarval_mode(tv), tv);
- if (old_tp && get_type_mode(old_tp) == get_tarval_mode (tv))
+ if (old_tp && get_type_mode(old_tp) == get_tarval_mode(tv))
set_Const_type(nw, old_tp);
DBG_OPT_CSTEVAL(oldn, nw);
tarval_enable_fp_ops(old_fp_mode);