Add ~x + 1 = -x algebraic simplification
authorMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Tue, 10 Jul 2007 16:28:28 +0000 (16:28 +0000)
committerMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Tue, 10 Jul 2007 16:28:28 +0000 (16:28 +0000)
[r15014]

include/libfirm/firmstat.h
ir/ir/iropt.c
ir/stat/stat_dmp.c

index 5712689..056e3ff 100644 (file)
@@ -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 */
index c47d72a..7198ae7 100644 (file)
@@ -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 */
index 70840d2..de072dd 100644 (file)
@@ -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" },