removed pn_Bound_M_except, Bound now have only one memory output
[libfirm] / ir / ir / iropt.c
index 443d248..e464728 100644 (file)
@@ -59,9 +59,22 @@ static tarval *computed_value_Const(ir_node *n)
  */
 static tarval *computed_value_SymConst(ir_node *n)
 {
-  if ((get_SymConst_kind(n) == symconst_size) &&
-      (get_type_state(get_SymConst_type(n))) == layout_fixed)
-    return new_tarval_from_long(get_type_size_bytes(get_SymConst_type(n)), get_irn_mode(n));
+  ir_type *type;
+
+  switch (get_SymConst_kind(n)) {
+  case symconst_type_size:
+    type = get_SymConst_type(n);
+    if (get_type_state(type) == layout_fixed)
+      return new_tarval_from_long(get_type_size_bytes(type), get_irn_mode(n));
+    break;
+  case symconst_type_align:
+    type = get_SymConst_type(n);
+    if (get_type_state(type) == layout_fixed)
+      return new_tarval_from_long(get_type_alignment_bytes(type), get_irn_mode(n));
+    break;
+  default:
+    break;
+  }
   return tarval_bad;
 }
 
@@ -1560,10 +1573,9 @@ static ir_node *equivalent_node_Bound(ir_node *n)
     /* Turn Bound into a tuple (mem, bad, idx) */
     ir_node *mem = get_Bound_mem(n);
     turn_into_tuple(n, pn_Bound_max);
-    set_Tuple_pred(n, pn_Bound_M_regular, mem);
-    set_Tuple_pred(n, pn_Bound_X_except,  new_Bad());       /* no exception */
-    set_Tuple_pred(n, pn_Bound_res,       idx);
-    set_Tuple_pred(n, pn_Bound_M_except,  mem);
+    set_Tuple_pred(n, pn_Bound_M,        mem);
+    set_Tuple_pred(n, pn_Bound_X_except, new_Bad());       /* no exception */
+    set_Tuple_pred(n, pn_Bound_res,      idx);
   }
   return n;
 }
@@ -1670,6 +1682,18 @@ optimize_preds(ir_node *n) {
   } /* end switch */
 }
 
+/**
+ * Returns non-zero if all Phi predecessors are constants
+ */
+static int is_const_Phi(ir_node *phi) {
+  int i;
+
+  for (i = get_irn_arity(phi) - 1; i >= 0; --i)
+    if (! is_Const(get_irn_n(phi, i)))
+      return 0;
+  return 1;
+}
+
 /**
  * Transform AddP(P, ConvIs(Iu)), AddP(P, ConvIu(Is)) and
  * SubP(P, ConvIs(Iu)), SubP(P, ConvIu(Is)).
@@ -2627,6 +2651,42 @@ static ir_node *transform_node_Proj(ir_node *proj)
   }
 }
 
+/**
+ * Move Confirms down through Phi nodes.
+ */
+static ir_node *transform_node_Phi(ir_node *phi) {
+  int i, n;
+  ir_mode *mode = get_irn_mode(phi);
+
+  if (mode_is_reference(mode)) {
+    n = get_irn_arity(phi);
+
+    /* Beware of Phi0 */
+    if (n > 0) {
+      ir_node *pred = get_irn_n(phi, 0);
+      ir_node *bound;
+      pn_Cmp  pnc;
+
+      if (! is_Confirm(pred))
+        return phi;
+
+      bound = get_Confirm_bound(pred);
+      pnc   = get_Confirm_cmp(pred);
+
+      for (i = 1; i < n; ++i) {
+        pred = get_irn_n(phi, i);
+
+        if (! is_Confirm(pred) ||
+            get_Confirm_bound(pred) != bound ||
+            get_Confirm_cmp(pred) != pnc)
+          return phi;
+      }
+      return new_r_Confirm(current_ir_graph, get_irn_n(phi, -1), phi, bound, pnc);
+    }
+  }
+  return phi;
+}
+
 /**
  * returns the operands of a commutative bin-op, if one operand is
  * a const, it is returned as the second one.
@@ -3123,6 +3183,7 @@ static ir_op_ops *firm_set_default_transform_node(opcode code, ir_op_ops *ops)
   CASE(Not);
   CASE(Cast);
   CASE(Proj);
+  CASE(Phi);
   CASE(Sel);
   CASE(Or);
   CASE(Shr);