From: Michael Beck Date: Tue, 10 Jul 2007 15:35:56 +0000 (+0000) Subject: Add -(~x) = x + 1 algebraic simplification X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=71bd615894a53355dcea6d8e2bcb7b9dc94628f5;p=libfirm Add -(~x) = x + 1 algebraic simplification [r15008] --- diff --git a/include/libfirm/firmstat.h b/include/libfirm/firmstat.h index 07ef579b3..5c064996d 100644 --- a/include/libfirm/firmstat.h +++ b/include/libfirm/firmstat.h @@ -78,6 +78,8 @@ enum firmstat_optimizations_t { FS_OPT_MUX_TO_MAX, /**< Mux(a > b, a, b) = Max(a,b) */ FS_OPT_MUX_TO_ABS, /**< Mux(a > b, a, b) = Abs(a,b) */ 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_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 dd995ec24..22814ccc7 100644 --- a/ir/ir/iropt.c +++ b/ir/ir/iropt.c @@ -990,7 +990,7 @@ static ir_node *equivalent_node_idempotent_unop(ir_node *n) { /* optimize symmetric unop */ if (get_irn_op(pred) == get_irn_op(n)) { n = get_unop_op(pred); - DBG_OPT_ALGSIM2(oldn, pred, n); + DBG_OPT_ALGSIM2(oldn, pred, n, FS_OPT_IDEM_UNARY); } return n; } /* equivalent_node_idempotent_unop */ @@ -2548,12 +2548,26 @@ static ir_node *transform_node_Not(ir_node *n) { /** * Transform a Minus. + * Optimize: + * -(~x) = x + 1 */ static ir_node *transform_node_Minus(ir_node *n) { ir_node *c, *oldn = n; ir_node *a = get_Minus_op(n); HANDLE_UNOP_PHI(tarval_neg,a,c); + + if (is_Not(a)) { + /* -(~x) = x + 1 */ + ir_node *op = get_Not_op(a); + ir_mode *mode = get_irn_mode(op); + tarval *tv = get_mode_one(mode); + ir_node *blk = get_irn_n(n, -1); + ir_node *c = new_r_Const(current_ir_graph, blk, mode, tv); + n = new_rd_Add(get_irn_dbg_info(n), current_ir_graph, blk, op, c, mode); + DBG_OPT_ALGSIM2(oldn, a, n, FS_OPT_MINUS_NOT); + } + return n; } /* transform_node_Minus */ diff --git a/ir/stat/stat_dmp.c b/ir/stat/stat_dmp.c index ffe98033b..ea0a5055d 100644 --- a/ir/stat/stat_dmp.c +++ b/ir/stat/stat_dmp.c @@ -96,6 +96,8 @@ static const struct { { FS_OPT_MUX_TO_MAX, "algebraic simplification: Mux(a > b, a, b) = Max(a,b)" }, { FS_OPT_MUX_TO_ABS, "algebraic simplification: Mux(a > b, a, b) = Abs(a,b)" }, { 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_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" },