From a6843eac460ff486a0e7831598a769a6b91be93f Mon Sep 17 00:00:00 2001 From: Michael Beck Date: Tue, 10 Jul 2007 15:53:19 +0000 Subject: [PATCH] Add ~(x-1) = -x algebraic simplification [r15009] --- include/libfirm/firmstat.h | 1 + ir/ir/iropt.c | 11 ++++++++++- ir/stat/stat_dmp.c | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/libfirm/firmstat.h b/include/libfirm/firmstat.h index 5c064996d..57126895c 100644 --- a/include/libfirm/firmstat.h +++ b/include/libfirm/firmstat.h @@ -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 */ diff --git a/ir/ir/iropt.c b/ir/ir/iropt.c index 22814ccc7..c47d72a97 100644 --- a/ir/ir/iropt.c +++ b/ir/ir/iropt.c @@ -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 */ diff --git a/ir/stat/stat_dmp.c b/ir/stat/stat_dmp.c index ea0a5055d..70840d2f7 100644 --- a/ir/stat/stat_dmp.c +++ b/ir/stat/stat_dmp.c @@ -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" }, -- 2.20.1