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

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

index 07ef579..5c06499 100644 (file)
@@ -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 */
index dd995ec..22814cc 100644 (file)
@@ -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 */
 
index ffe9803..ea0a505 100644 (file)
@@ -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" },