implement/refactor x&~x, x|~x, x^~x and x+~x localopts
authorMatthias Braun <matze@braunis.de>
Fri, 27 May 2011 08:09:41 +0000 (10:09 +0200)
committerMatthias Braun <matze@braunis.de>
Fri, 27 May 2011 13:30:56 +0000 (15:30 +0200)
ir/ir/iropt.c

index 5e27de9..0a97728 100644 (file)
@@ -131,6 +131,12 @@ static ir_tarval *computed_value_Add(const ir_node *n)
        if ((ta != tarval_bad) && (tb != tarval_bad))
                return tarval_add(ta, tb);
 
+       /* x+~x => -1 */
+       if ((is_Not(a) && get_Not_op(a) == b)
+           || (is_Not(b) && get_Not_op(b) == a)) {
+               return get_mode_all_one(get_irn_mode(n));
+       }
+
        return tarval_bad;
 }  /* computed_value_Add */
 
@@ -264,10 +270,17 @@ static ir_tarval *computed_value_And(const ir_node *n)
 
        if ((ta != tarval_bad) && (tb != tarval_bad)) {
                return tarval_and (ta, tb);
-       } else {
-               if (tarval_is_null(ta)) return ta;
-               if (tarval_is_null(tb)) return tb;
        }
+
+       if (tarval_is_null(ta)) return ta;
+       if (tarval_is_null(tb)) return tb;
+
+       /* x&~x => 0 */
+       if ((is_Not(a) && get_Not_op(a) == b)
+           || (is_Not(b) && get_Not_op(b) == a)) {
+               return get_mode_null(get_irn_mode(n));
+       }
+
        return tarval_bad;
 }  /* computed_value_And */
 
@@ -284,9 +297,15 @@ static ir_tarval *computed_value_Or(const ir_node *n)
 
        if ((ta != tarval_bad) && (tb != tarval_bad)) {
                return tarval_or (ta, tb);
-       } else {
-               if (tarval_is_all_one(ta)) return ta;
-               if (tarval_is_all_one(tb)) return tb;
+       }
+
+       if (tarval_is_all_one(ta)) return ta;
+       if (tarval_is_all_one(tb)) return tb;
+
+       /* x|~x => -1 */
+       if ((is_Not(a) && get_Not_op(a) == b)
+           || (is_Not(b) && get_Not_op(b) == a)) {
+               return get_mode_all_one(get_irn_mode(n));
        }
        return tarval_bad;
 }  /* computed_value_Or */
@@ -303,6 +322,11 @@ static ir_tarval *computed_value_Eor(const ir_node *n)
 
        if (a == b)
                return get_mode_null(get_irn_mode(n));
+       /* x^~x => -1 */
+       if ((is_Not(a) && get_Not_op(a) == b)
+           || (is_Not(b) && get_Not_op(b) == a)) {
+               return get_mode_all_one(get_irn_mode(n));
+       }
 
        ta = value_of(a);
        tb = value_of(b);
@@ -2016,22 +2040,6 @@ static ir_node *transform_node_Add(ir_node *n)
                                        DBG_OPT_ALGSIM0(oldn, n, FS_OPT_NOT_PLUS_1);
                                        return n;
                                }
-                               if (op == b) {
-                                       /* ~x + x = -1 */
-                                       n = new_r_Const(irg, get_mode_minus_one(mode));
-                                       DBG_OPT_ALGSIM0(oldn, n, FS_OPT_ADD_X_NOT_X);
-                                       return n;
-                               }
-                       }
-                       if (is_Not(b)) {
-                               ir_node *op = get_Not_op(b);
-
-                               if (op == a) {
-                                       /* x + ~x = -1 */
-                                       n = new_r_Const(irg, get_mode_minus_one(mode));
-                                       DBG_OPT_ALGSIM0(oldn, n, FS_OPT_ADD_X_NOT_X);
-                                       return n;
-                               }
                        }
                }
        }