From 3fc8ae70fd055eee4e9aa51b7a1cde4c58574464 Mon Sep 17 00:00:00 2001 From: Michael Beck Date: Tue, 10 Jul 2007 16:28:28 +0000 Subject: [PATCH] Add ~x + 1 = -x algebraic simplification [r15014] --- include/libfirm/firmstat.h | 3 ++- ir/ir/iropt.c | 8 ++++++++ ir/stat/stat_dmp.c | 3 ++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/include/libfirm/firmstat.h b/include/libfirm/firmstat.h index 57126895c..056e3ffe4 100644 --- a/include/libfirm/firmstat.h +++ b/include/libfirm/firmstat.h @@ -80,7 +80,8 @@ 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_NOT_MINUS_1, /**< ~(x - 1) = -x */ + FS_OPT_NOT_PLUS_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 c47d72a97..7198ae739 100644 --- a/ir/ir/iropt.c +++ b/ir/ir/iropt.c @@ -1993,6 +1993,14 @@ static ir_node *transform_node_Add(ir_node *n) { DBG_OPT_ALGSIM0(oldn, n, FS_OPT_ADD_MUL_A_X_A); } } + /* Here we rely on constants be on the RIGHT side */ + else if (is_Not(a) && classify_Const(b) == CNST_ONE) { + /* ~x + 1 = -x */ + ir_node *op = get_Not_op(a); + ir_node *blk = get_irn_n(n, -1); + n = new_rd_Minus(get_irn_dbg_info(n), current_ir_graph, blk, op, mode); + DBG_OPT_ALGSIM0(oldn, n, FS_OPT_NOT_PLUS_1); + } } return n; } /* transform_node_Add */ diff --git a/ir/stat/stat_dmp.c b/ir/stat/stat_dmp.c index 70840d2f7..de072dd84 100644 --- a/ir/stat/stat_dmp.c +++ b/ir/stat/stat_dmp.c @@ -98,7 +98,8 @@ 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_NOT_MINUS_1, "algebraic simplification: ~(x - 1) = -x" }, + { FS_OPT_NOT_PLUS_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