Commit a6843eac authored by Michael Beck's avatar Michael Beck
Browse files

Add ~(x-1) = -x algebraic simplification

[r15009]
parent 71bd6158
......@@ -80,6 +80,7 @@ enum firmstat_optimizations_t {
FS_OPT_MUX_TO_SHR, /**< Mux(a > b, a, b) = a >> b */
FS_OPT_IDEM_UNARY, /**< Idempotent unary operation */
FS_OPT_MINUS_NOT, /**< -(~x) = x + 1 */
FS_OPT_NOT_MINUS_1, /**< ~(x-1) = -x */
FS_OPT_CONST_PHI, /**< Constant evaluation on Phi */
FS_BE_IA32_LEA, /**< Lea was created */
FS_BE_IA32_LOAD_LEA, /**< Load merged with a Lea */
......
......@@ -2530,18 +2530,27 @@ static ir_node *transform_node_Eor(ir_node *n) {
static ir_node *transform_node_Not(ir_node *n) {
ir_node *c, *oldn = n;
ir_node *a = get_Not_op(n);
ir_op *op_a = get_irn_op(a);
HANDLE_UNOP_PHI(tarval_not,a,c);
/* check for a boolean Not */
if ( (get_irn_mode(n) == mode_b)
&& (get_irn_op(a) == op_Proj)
&& (op_a == op_Proj)
&& (get_irn_mode(a) == mode_b)
&& (get_irn_op(get_Proj_pred(a)) == op_Cmp)) {
/* We negate 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_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);
}
return n;
} /* transform_node_Not */
......
......@@ -98,6 +98,7 @@ static const struct {
{ FS_OPT_MUX_TO_SHR, "algebraic simplification: Mux(a > b, a, b) = a >> b" },
{ FS_OPT_IDEM_UNARY, "algebraic simplification: Idempotent unary operation" },
{ FS_OPT_MINUS_NOT, "algebraic simplification: -(~x) = x + 1" },
{ FS_OPT_NOT_MINUS_1, "algebraic simplification: ~(x-1) = -x" },
{ FS_OPT_CONST_PHI, "constant evaluation on Phi node" },
{ FS_BE_IA32_LEA, "ia32 Backend transformation: Lea was created" },
{ FS_BE_IA32_LOAD_LEA, "ia32 Backend transformation: Load merged with a Lea" },
......
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