* @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.
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);
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);
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