- if(operands[0] && operands[1]
- && can_move_to(operands[0], bl, max_depth)
- && can_move_to(operands[1], bl, max_depth)) {
-
- move_to(operands[0], bl);
- move_to(operands[1], bl);
-
- /* Make the mux. */
- *mux = new_r_Mux(current_ir_graph, bl, projb,
- operands[0], operands[1], get_irn_mode(operands[0]));
-
- *muxes_made += 1;
-
- DBG((dbg, LEVEL_2, "\t%n(%n, %n, %n)[%d, %d]\n",
- *mux, projb, operands[0], operands[1], set[0], set[1]));
-
- for(i = 0; i < 2; ++i)
- if(set[i] >= 0)
- bitset_set(positions, set[i]);
+ if(operands[0] && operands[1]) {
+ if (operands[0] == operands[1]) {
+ /* there is no gain in using mux in this case, as
+ it will be optimized away. We will NOT move the
+ content of the blocks either
+ */
+ for (i = 0; i < 2; ++i)
+ if(set[i] >= 0)
+ bitset_set(positions, set[i]);
+
+ *mux = operands[0];
+ return *mux;
+ }
+
+ can_move[0] = can_move_to(operands[0], bl, max_depth);
+ can_move[1] = can_move_to(operands[1], bl, max_depth);
+
+ if (can_move[0] == SUCCESS && can_move[1] == SUCCESS) {
+ move_to(operands[0], bl);
+ move_to(operands[1], bl);
+
+ /* Make the mux. */
+ *mux = new_r_Mux(current_ir_graph, bl, projb,
+ operands[0], operands[1], get_irn_mode(operands[0]));
+
+ *muxes_made += 1;
+
+ DBG((dbg, LEVEL_2, "\t%n(%n, %n, %n)[%d, %d]\n",
+ *mux, projb, operands[0], operands[1], set[0], set[1]));
+
+ for(i = 0; i < 2; ++i)
+ if(set[i] >= 0) {
+ bitset_set(positions, set[i]);
+
+ /* we have done one */
+ hook_if_conversion(current_ir_graph, phi, set[i], *mux, IF_RESULT_SUCCESS);
+ }
+ }
+ else {
+ if(can_move[0] != SUCCESS)
+ hook_if_conversion(current_ir_graph, phi, set[0], NULL, can_move[0]);
+ if(can_move[1] != SUCCESS)
+ hook_if_conversion(current_ir_graph, phi, set[1], NULL, can_move[1]);
+ }