- int i;
- ir_node *res;
- ir_node *ops[2];
- ir_mode *mode = get_irn_mode(mux);
- tarval *null;
- tarval *minus_one;
-
- /*
- * If we have no mux, or its mode is not integer, we
- * can return.
- */
- if(get_irn_op(mux) != op_Mux || !mode_is_int(mode))
- return mux;
-
- res = mux;
- null = get_tarval_null(mode);
- minus_one = tarval_sub(null, get_tarval_one(mode));
-
- ops[0] = get_Mux_false(mux);
- ops[1] = get_Mux_true(mux);
-
- for(i = 0; i < 2; ++i) {
- ir_node *a, *b, *d;
- tarval *tva, *tvb, *tvd;
- ir_node *child_mux;
-
- /*
- * A mux operand at the first position can be factored
- * out, if the operands fulfill several conditions:
- *
- * mux(c1, mux(c2, a, b), d)
- *
- * This can be made into:
- * 1) mux(c1, 0, d) | mux(c2, a, b)
- * if a | d == d and b | d == d
- *
- * 2) mux(c1, -1, d) & mux(c2, a, b)
- * if a & d == d and a & b == b
- */
- if(get_irn_op(ops[i]) == op_Mux) {
-
- child_mux = ops[i];
- a = get_Mux_false(child_mux);
- b = get_Mux_true(child_mux);
- d = ops[1 - i];
-
- /* Try the or stuff */
- tva = get_value_or(a, minus_one);
- tvb = get_value_or(b, minus_one);
- tvd = get_value_or(d, null);
-
- if(tarval_cmp(tarval_or(tva, tvd), tvd) == pn_Cmp_Eq
- && tarval_cmp(tarval_or(tvb, tvd), tvd) == pn_Cmp_Eq) {
-
- ops[i] = new_Const(mode, null);
- res = new_r_Or(current_ir_graph, get_nodes_block(mux),
- mux, child_mux, mode);
- break;
- }
-
- /* If the or didn't go, try the and stuff */
- tva = get_value_or(a, null);
- tvb = get_value_or(b, null);
- tvd = get_value_or(d, minus_one);
-
- if(tarval_cmp(tarval_and(tva, tvd), tvd) == pn_Cmp_Eq
- && tarval_cmp(tarval_and(tvb, tvd), tvd) == pn_Cmp_Eq) {
-
- ops[i] = new_Const(mode, minus_one);
- res = new_r_And(current_ir_graph, get_nodes_block(mux),
- mux, child_mux, mode);
- break;
- }
- }
- }
-
- /* recursively optimize nested muxes. */
- set_irn_n(mux, 1, optimize_mux_chain(ops[0]));
- set_irn_n(mux, 2, optimize_mux_chain(ops[1]));
-
- return res;
+ int i;
+ ir_node *res;
+ ir_node *ops[2];
+ ir_mode *mode = get_irn_mode(mux);
+ tarval *null;
+ tarval *minus_one;
+
+ /*
+ * If we have no mux, or its mode is not integer, we
+ * can return.
+ */
+ if(get_irn_op(mux) != op_Mux || !mode_is_int(mode))
+ return mux;
+
+ res = mux;
+ null = get_mode_null(mode);
+ minus_one = tarval_sub(null, get_tarval_one(mode));
+
+ ops[0] = get_Mux_false(mux);
+ ops[1] = get_Mux_true(mux);
+
+ for(i = 0; i < 2; ++i) {
+ ir_node *a, *b, *d;
+ tarval *tva, *tvb, *tvd;
+ ir_node *child_mux;
+
+ /*
+ * A mux operand at the first position can be factored
+ * out, if the operands fulfill several conditions:
+ *
+ * mux(c1, mux(c2, a, b), d)
+ *
+ * This can be made into:
+ * 1) mux(c1, 0, d) | mux(c2, a, b)
+ * if a | d == d and b | d == d
+ *
+ * 2) mux(c1, -1, d) & mux(c2, a, b)
+ * if a & d == d and a & b == b
+ */
+ if(get_irn_op(ops[i]) == op_Mux) {
+
+ child_mux = ops[i];
+ a = get_Mux_false(child_mux);
+ b = get_Mux_true(child_mux);
+ d = ops[1 - i];
+
+ /* Try the or stuff */
+ tva = get_value_or(a, minus_one);
+ tvb = get_value_or(b, minus_one);
+ tvd = get_value_or(d, null);
+
+ if(tarval_cmp(tarval_or(tva, tvd), tvd) == pn_Cmp_Eq
+ && tarval_cmp(tarval_or(tvb, tvd), tvd) == pn_Cmp_Eq) {
+
+ ops[i] = new_Const(mode, null);
+ res = new_r_Or(current_ir_graph, get_nodes_block(mux),
+ mux, child_mux, mode);
+ break;
+ }
+
+ /* If the or didn't go, try the and stuff */
+ tva = get_value_or(a, null);
+ tvb = get_value_or(b, null);
+ tvd = get_value_or(d, minus_one);
+
+ if(tarval_cmp(tarval_and(tva, tvd), tvd) == pn_Cmp_Eq
+ && tarval_cmp(tarval_and(tvb, tvd), tvd) == pn_Cmp_Eq) {
+
+ ops[i] = new_Const(mode, minus_one);
+ res = new_r_And(current_ir_graph, get_nodes_block(mux),
+ mux, child_mux, mode);
+ break;
+ }
+ }
+ }
+
+ /* recursively optimize nested muxes. */
+ set_irn_n(mux, 1, optimize_mux_chain(ops[0]));
+ set_irn_n(mux, 2, optimize_mux_chain(ops[1]));
+
+ return res;