remove return values from graph transformations
[libfirm] / ir / ir / irarch.c
index ad1841c..1604ef1 100644 (file)
@@ -22,7 +22,6 @@
  * @brief   Machine dependent Firm optimizations.
  * @date    28.9.2004
  * @author  Sebastian Hack, Michael Beck
- * @version $Id$
  *
  * Implements "Strength Reduction of Multiplications by Integer Constants"
  * by Youfeng Wu.
@@ -572,19 +571,19 @@ ir_node *arch_dep_replace_mul_with_shifts(ir_node *irn)
        ir_tarval *tv;
        const ir_settings_arch_dep_t *params = be_get_backend_param()->dep_param;
 
-
        /* If the architecture dependent optimizations were not initialized
           or this optimization was not enabled. */
        if (params == NULL || (opts & arch_dep_mul_to_shift) == 0)
-               return irn;
+               return res;
 
-       if (!is_Mul(irn) || !mode_is_int(mode))
+       assert(is_Mul(irn));
+       if (!mode_is_int(mode))
                return res;
 
        /* we should never do the reverse transformations again
           (like x+x -> 2*x) */
        irg = get_irn_irg(irn);
-       set_irg_state(irg, IR_GRAPH_STATE_ARCH_DEP);
+       add_irg_constraints(irg, IR_GRAPH_CONSTRAINT_ARCH_DEP);
 
        left    = get_binop_left(irn);
        right   = get_binop_right(irn);
@@ -600,6 +599,11 @@ ir_node *arch_dep_replace_mul_with_shifts(ir_node *irn)
                operand = left;
        }
 
+       /* multiplications with 0 are a special case which we leave for
+        * equivalent_node_Mul because the code here can't handle them */
+       if (tv == get_mode_null(mode))
+               return res;
+
        if (tv != NULL) {
                res = do_decomposition(irn, operand, tv);
 
@@ -1051,7 +1055,13 @@ ir_node *arch_dep_replace_mod_by_const(ir_node *irn)
                        k = tv_ld2(tv, n);
                }
 
-               if (k >= 0) {
+               /* k == 0  i.e. modulo by 1 */
+               if (k == 0) {
+                       ir_graph *irg = get_irn_irg(irn);
+
+                       res = new_r_Const(irg, get_mode_null(mode));
+               }
+               else if (k > 0) {
                        ir_graph *irg = get_irn_irg(irn);
                        /* division by 2^k or -2^k:
                         * we use "modulus" here, so x % y == x % -y that's why is no difference between the case 2^k and -2^k