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

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

index 5c06499..5712689 100644 (file)
@@ -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 */
index 22814cc..c47d72a 100644 (file)
@@ -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 */
index ea0a505..70840d2 100644 (file)
@@ -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" },