Add optmitizations for the following cases:
authorMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Sun, 19 Mar 2006 11:56:56 +0000 (11:56 +0000)
committerMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Sun, 19 Mar 2006 11:56:56 +0000 (11:56 +0000)
   And(x, C) == C  ==>  And(x, C) != 0
   And(x, C) != C  ==>  And(X, C) == 0

This helps the ia32 backend to create test instructions and might be useful for other backends
as well

[r7474]

ir/ir/iropt.c

index a03d0f7..aac8fe0 100644 (file)
@@ -2530,7 +2530,32 @@ static ir_node *transform_node_Proj_Cmp(ir_node *proj)
             }
           }
         } /* mode_is_int */
-      }
+
+        /*
+         * optimization for AND:
+         * Optimize:
+         *   And(x, C) == C  ==>  And(x, C) != 0
+         *   And(x, C) != C  ==>  And(X, C) == 0
+         *
+         * if C is a single Bit constant.
+         */
+        if ((proj_nr == pn_Cmp_Eq || proj_nr == pn_Cmp_Lg) &&
+            (get_irn_op(left) == op_And)) {
+          if (is_single_bit_tarval(tv)) {
+            /* check for Constant's match. We have check hare the tarvals,
+               because our const might be changed */
+            ir_node *la = get_And_left(left);
+            ir_node *ra = get_And_right(left);
+            if ((is_Const(la) && get_Const_tarval(la) == tv) ||
+                (is_Const(ra) && get_Const_tarval(ra) == tv)) {
+              /* fine: do the transformation */
+              tv = get_mode_null(get_tarval_mode(tv));
+              proj_nr ^= pn_Cmp_Leg;
+              changed |= 2;
+            }
+          }
+        }
+      } /* tarval != bad */
     }
 
     if (changed) {