Sort.
[libfirm] / ir / be / ia32 / ia32_finish.c
index a62dd19..47b6f29 100644 (file)
@@ -208,18 +208,25 @@ static void ia32_transform_sub_to_neg_add(ir_node *irn, ia32_code_gen_t *cg) {
        DBG_OPT_SUB2NEGADD(irn, res);
 }
 
-static INLINE int need_constraint_copy(ir_node *irn) {
-       /* the 3 operand form of IMul needs no constraint copy */
-       if(is_ia32_IMul(irn)) {
-               ir_node *right = get_irn_n(irn, n_ia32_IMul_right);
-               if(is_ia32_Immediate(right))
+static INLINE int need_constraint_copy(ir_node *irn)
+{
+       /* TODO this should be determined from the node specification */
+       switch (get_ia32_irn_opcode(irn)) {
+               case iro_ia32_IMul: {
+                       /* the 3 operand form of IMul needs no constraint copy */
+                       ir_node *right = get_irn_n(irn, n_ia32_IMul_right);
+                       return !is_ia32_Immediate(right);
+               }
+
+               case iro_ia32_Lea:
+               case iro_ia32_Conv_I2I:
+               case iro_ia32_Conv_I2I8Bit:
+               case iro_ia32_CMov:
                        return 0;
-       }
 
-       return  ! is_ia32_Lea(irn)      &&
-               ! is_ia32_Conv_I2I(irn)     &&
-               ! is_ia32_Conv_I2I8Bit(irn) &&
-               ! is_ia32_CMov(irn);
+               default:
+                       return 1;
+       }
 }
 
 /**
@@ -479,8 +486,11 @@ static void fix_am_source(ir_node *irn, void *env)
                        arch_set_irn_register(cg->arch_env, load_res, out_reg);
 
                        /* set the new input operand */
-                       set_irn_n(irn, n_ia32_binary_right, load_res);
-                       if(get_irn_mode(irn) == mode_T) {
+                       if (is_ia32_Immediate(get_irn_n(irn, n_ia32_binary_right)))
+                               set_irn_n(irn, n_ia32_binary_left, load_res);
+                       else
+                               set_irn_n(irn, n_ia32_binary_right, load_res);
+                       if (get_irn_mode(irn) == mode_T) {
                                const ir_edge_t *edge, *next;
                                foreach_out_edge_safe(irn, edge, next) {
                                        ir_node *node = get_edge_src_irn(edge);