OSDN Git Service

2011-08-08 Mikael Pettersson <mikpe@it.uu.se>
[pf3gnuchains/gcc-fork.git] / gcc / ipa-inline-analysis.c
index f96e09e..df96c99 100644 (file)
@@ -227,19 +227,20 @@ add_condition (struct inline_summary *summary, int operand_num,
 }
 
 
-/* Add clause CLAUSE into the predicate.  */
+/* Add clause CLAUSE into the predicate P.  */
 
 static inline void
 add_clause (struct predicate *p, clause_t clause)
 {
   int i;
+  int i2;
   int insert_here = -1;
 
   /* True clause.  */
   if (!clause)
     return;
 
-  /* Flase clause makes the whole predicate false.  Kill the other variants.  */
+  /* False clause makes the whole predicate false.  Kill the other variants.  */
   if (clause == (1 << predicate_false_condition))
     {
       p->clause[0] = (1 << predicate_false_condition);
@@ -248,26 +249,46 @@ add_clause (struct predicate *p, clause_t clause)
     }
   if (false_predicate_p (p))
     return;
-  gcc_assert (!(clause & (1 << predicate_false_condition)));
-  for (i = 0; i < MAX_CLAUSES - 1; i++)
+
+  /* No one should be sily enough to add false into nontrivial clauses.  */
+  gcc_checking_assert (!(clause & (1 << predicate_false_condition)));
+
+  /* Look where to insert the clause.  At the same time prune out
+     clauses of P that are implied by the new clause and thus
+     redundant.  */
+  for (i = 0, i2 = 0; i <= MAX_CLAUSES; i++)
     {
-      if (p->clause[i] == clause)
-        return;
+      p->clause[i2] = p->clause[i];
+
       if (!p->clause[i])
        break;
-      if (p->clause[i] < clause && !insert_here)
-       insert_here = i;
+
+      /* If p->clause[i] implies clause, there is nothing to add.  */
+      if ((p->clause[i] & clause) == p->clause[i])
+       {
+         /* We had nothing to add, none of clauses should've become redundant.  */
+         gcc_checking_assert (i == i2);
+         return;
+       }
+
+      if (p->clause[i] < clause && insert_here < 0)
+       insert_here = i2;
+
+      /* If clause implies p->clause[i], then p->clause[i] becomes redundant.
+        Otherwise the p->clause[i] has to stay.  */
+      if ((p->clause[i] & clause) != clause)
+       i2++;
     }
-  /* We run out of variants.  Be conservative in positive direciton.  */
-  if (i == MAX_CLAUSES)
+  /* We run out of variants.  Be conservative in positive direction.  */
+  if (i2 == MAX_CLAUSES)
     return;
-  /* Keep clauses ordered by index, so equivalence testing is easy.  */
-  p->clause[i + 1] = 0;
+  /* Keep clauses in decreasing order. This makes equivalence testing easy.  */
+  p->clause[i2 + 1] = 0;
   if (insert_here >= 0)
-    for (;i > insert_here; i--)
-      p->clause[i] = p->clause[i - 1];
+    for (;i2 > insert_here; i2--)
+      p->clause[i2] = p->clause[i2 - 1];
   else
-    insert_here = i;
+    insert_here = i2;
   p->clause[insert_here] = clause;
 }
 
@@ -280,7 +301,20 @@ and_predicates (struct predicate *p, struct predicate *p2)
   struct predicate out = *p;
   int i;
 
-  for (i = 0; p2->clause[i]; i++)
+  /* Avoid busy work.  */
+  if (false_predicate_p (p2) || true_predicate_p (p))
+    return *p2;
+  if (false_predicate_p (p) || true_predicate_p (p2))
+    return *p;
+
+  /* See how far predicates match.  */
+  for (i = 0; p->clause[i] && p->clause[i] == p2->clause[i]; i++)
+    {
+      gcc_checking_assert (i < MAX_CLAUSES);
+    }
+    
+  /* Combine the predicates rest.  */
+  for (; p2->clause[i]; i++)
     {
       gcc_checking_assert (i < MAX_CLAUSES);
       add_clause (&out, p2->clause[i]);
@@ -289,6 +323,24 @@ and_predicates (struct predicate *p, struct predicate *p2)
 }
 
 
+/* Return true if predicates are obviously equal.  */
+
+static inline bool
+predicates_equal_p (struct predicate *p, struct predicate *p2)
+{
+  int i;
+  for (i = 0; p->clause[i]; i++)
+    {
+      gcc_checking_assert (i < MAX_CLAUSES);
+      gcc_checking_assert (p->clause [i] > p->clause[i + 1]);
+      gcc_checking_assert (!p2->clause[i] || p2->clause [i] > p2->clause[i + 1]);
+      if (p->clause[i] != p2->clause[i])
+        return false;
+    }
+  return !p2->clause[i];
+}
+
+
 /* Return P | P2.  */
 
 static struct predicate
@@ -297,11 +349,15 @@ or_predicates (struct predicate *p, struct predicate *p2)
   struct predicate out = true_predicate ();
   int i,j;
 
-  /* If one of conditions is false, return the other.  */
-  if (false_predicate_p (p2))
+  /* Avoid busy work.  */
+  if (false_predicate_p (p2) || true_predicate_p (p))
     return *p;
-  if (false_predicate_p (p))
+  if (false_predicate_p (p) || true_predicate_p (p2))
     return *p2;
+  if (predicates_equal_p (p, p2))
+    return *p;
+
+  /* OK, combine the predicates.  */
   for (i = 0; p->clause[i]; i++)
     for (j = 0; p2->clause[j]; j++)
       {
@@ -312,22 +368,6 @@ or_predicates (struct predicate *p, struct predicate *p2)
 }
 
 
-/* Return true if predicates are obviously equal.  */
-
-static inline bool
-predicates_equal_p (struct predicate *p, struct predicate *p2)
-{
-  int i;
-  for (i = 0; p->clause[i]; i++)
-    {
-      gcc_checking_assert (i < MAX_CLAUSES);
-      if (p->clause[i] != p2->clause[i])
-        return false;
-    }
-  return !p2->clause[i];
-}
-
-
 /* Having partial truth assignment in POSSIBLE_TRUTHS, return false if predicate P
    to be false.  */
 
@@ -433,7 +473,7 @@ account_size_time (struct inline_summary *summary, int size, int time, struct pr
 
   /* We need to create initial empty unconitional clause, but otherwie
      we don't need to account empty times and sizes.  */
-  if (!size && !time && summary->conds)
+  if (!size && !time && summary->entry)
     return;
 
   /* Watch overflow that might result from insane profiles.  */
@@ -499,13 +539,58 @@ edge_set_predicate (struct cgraph_edge *e, struct predicate *predicate)
 }
 
 
+/* KNOWN_VALS is partial mapping of parameters of NODE to constant values.
+   Return clause of possible truths. When INLINE_P is true, assume that
+   we are inlining.  */
+
+static clause_t
+evaluate_conditions_for_known_args (struct cgraph_node *node,
+                                   bool inline_p,
+                                   VEC (tree, heap) *known_vals)
+{
+  clause_t clause = inline_p ? 0 : 1 << predicate_not_inlined_condition;
+  struct inline_summary *info = inline_summary (node);
+  int i;
+  struct condition *c;
+
+  for (i = 0; VEC_iterate (condition, info->conds, i, c); i++)
+    {
+      tree val;
+      tree res;
+
+      /* We allow call stmt to have fewer arguments than the callee
+        function (especially for K&R style programs).  So bound
+        check here.  */
+      if (c->operand_num < (int)VEC_length (tree, known_vals))
+        val = VEC_index (tree, known_vals, c->operand_num);
+      else
+       val = NULL;
+
+      if (!val)
+       {
+         clause |= 1 << (i + predicate_first_dynamic_condition);
+         continue;
+       }
+      if (c->code == IS_NOT_CONSTANT)
+       continue;
+      res = fold_binary_to_constant (c->code, boolean_type_node, val, c->val);
+      if (res
+         && integer_zerop (res))
+       continue;
+      clause |= 1 << (i + predicate_first_dynamic_condition);
+    }
+  return clause;
+}
+
+
 /* Work out what conditions might be true at invocation of E.  */
 
 static clause_t
 evaluate_conditions_for_edge (struct cgraph_edge *e, bool inline_p)
 {
   clause_t clause = inline_p ? 0 : 1 << predicate_not_inlined_condition;
-  struct inline_summary *info = inline_summary (e->callee);
+  struct cgraph_node *callee = cgraph_function_or_thunk_node (e->callee, NULL);
+  struct inline_summary *info = inline_summary (callee);
   int i;
 
   if (ipa_node_params_vector && info->conds
@@ -516,8 +601,6 @@ evaluate_conditions_for_edge (struct cgraph_edge *e, bool inline_p)
       struct ipa_node_params *parms_info;
       struct ipa_edge_args *args = IPA_EDGE_REF (e);
       int i, count = ipa_get_cs_argument_count (args);
-      struct ipcp_lattice lat;
-      struct condition *c;
       VEC (tree, heap) *known_vals = NULL;
 
       if (e->caller->global.inlined_to)
@@ -528,28 +611,13 @@ evaluate_conditions_for_edge (struct cgraph_edge *e, bool inline_p)
       VEC_safe_grow_cleared (tree, heap, known_vals, count);
       for (i = 0; i < count; i++)
        {
-         ipa_lattice_from_jfunc (parms_info, &lat, ipa_get_ith_jump_func (args, i));
-         if (lat.type == IPA_CONST_VALUE)
-           VEC_replace (tree, known_vals, i, lat.constant);
-       }
-      for (i = 0; VEC_iterate (condition, info->conds, i, c); i++)
-       {
-         tree val = VEC_index (tree, known_vals, c->operand_num);
-         tree res;
-
-         if (!val)
-           {
-             clause |= 1 << (i + predicate_first_dynamic_condition);
-             continue;
-           }
-         if (c->code == IS_NOT_CONSTANT)
-           continue;
-         res = fold_binary_to_constant (c->code, boolean_type_node, val, c->val);
-         if (res
-             && integer_zerop (res))
-           continue;
-         clause |= 1 << (i + predicate_first_dynamic_condition);
+         tree cst = ipa_cst_from_jfunc (parms_info,
+                                        ipa_get_ith_jump_func (args, i));
+         if (cst)
+           VEC_replace (tree, known_vals, i, cst);
        }
+      clause = evaluate_conditions_for_known_args (callee,
+                                                  inline_p, known_vals);
       VEC_free (tree, heap, known_vals);
     }
   else
@@ -621,8 +689,165 @@ inline_node_duplication_hook (struct cgraph_node *src, struct cgraph_node *dst,
   info = inline_summary (dst);
   memcpy (info, inline_summary (src),
          sizeof (struct inline_summary));
+  /* TODO: as an optimization, we may avoid copying conditions
+     that are known to be false or true.  */
   info->conds = VEC_copy (condition, gc, info->conds);
-  info->entry = VEC_copy (size_time_entry, gc, info->entry);
+
+  /* When there are any replacements in the function body, see if we can figure
+     out that something was optimized out.  */
+  if (ipa_node_params_vector && dst->clone.tree_map)
+    {
+      VEC(size_time_entry,gc) *entry = info->entry;
+      /* Use SRC parm info since it may not be copied yet.  */
+      struct ipa_node_params *parms_info = IPA_NODE_REF (src);
+      VEC (tree, heap) *known_vals = NULL;
+      int count = ipa_get_param_count (parms_info);
+      int i,j;
+      clause_t possible_truths;
+      struct predicate true_pred = true_predicate ();
+      size_time_entry *e;
+      int optimized_out_size = 0;
+      gcov_type optimized_out_time = 0;
+      bool inlined_to_p = false;
+      struct cgraph_edge *edge;
+
+      info->entry = 0;
+      VEC_safe_grow_cleared (tree, heap, known_vals, count);
+      for (i = 0; i < count; i++)
+        {
+         tree t = ipa_get_param (parms_info, i);
+         struct ipa_replace_map *r;
+
+         for (j = 0;
+              VEC_iterate (ipa_replace_map_p, dst->clone.tree_map, j, r);
+              j++)
+           {
+             if (r->old_tree == t
+                 && r->replace_p
+                 && !r->ref_p)
+               {
+                 VEC_replace (tree, known_vals, i, r->new_tree);
+                 break;
+               }
+           }
+       }
+      possible_truths = evaluate_conditions_for_known_args (dst,
+                                                           false, known_vals);
+      VEC_free (tree, heap, known_vals);
+
+      account_size_time (info, 0, 0, &true_pred);
+
+      /* Remap size_time vectors.
+        Simplify the predicate by prunning out alternatives that are known
+        to be false.
+        TODO: as on optimization, we can also eliminate conditions known to be true.  */
+      for (i = 0; VEC_iterate (size_time_entry, entry, i, e); i++)
+       {
+         struct predicate new_predicate = true_predicate ();
+         for (j = 0; e->predicate.clause[j]; j++)
+           if (!(possible_truths & e->predicate.clause[j]))
+             {
+               new_predicate = false_predicate ();
+               break;
+             }
+           else
+             add_clause (&new_predicate,
+                         possible_truths & e->predicate.clause[j]);
+         if (false_predicate_p (&new_predicate))
+           {
+             optimized_out_size += e->size;
+             optimized_out_time += e->time;
+           }
+         else
+           account_size_time (info, e->size, e->time, &new_predicate);
+       }
+
+      /* Remap edge predicates with the same simplificaiton as above.  */
+      for (edge = dst->callees; edge; edge = edge->next_callee)
+       {
+         struct predicate new_predicate = true_predicate ();
+         struct inline_edge_summary *es = inline_edge_summary (edge);
+
+         if (!edge->inline_failed)
+           inlined_to_p = true;
+         if (!es->predicate)
+           continue;
+         for (j = 0; es->predicate->clause[j]; j++)
+           if (!(possible_truths & es->predicate->clause[j]))
+             {
+               new_predicate = false_predicate ();
+               break;
+             }
+           else
+             add_clause (&new_predicate,
+                         possible_truths & es->predicate->clause[j]);
+         if (false_predicate_p (&new_predicate)
+             && !false_predicate_p (es->predicate))
+           {
+             optimized_out_size += es->call_stmt_size * INLINE_SIZE_SCALE;
+             optimized_out_time += (es->call_stmt_time
+                                    * (INLINE_TIME_SCALE / CGRAPH_FREQ_BASE)
+                                    * edge->frequency);
+             edge->frequency = 0;
+           }
+         *es->predicate = new_predicate;
+       }
+
+      /* Remap indirect edge predicates with the same simplificaiton as above.  */
+      for (edge = dst->indirect_calls; edge; edge = edge->next_callee)
+       {
+         struct predicate new_predicate = true_predicate ();
+         struct inline_edge_summary *es = inline_edge_summary (edge);
+
+         if (!edge->inline_failed)
+           inlined_to_p = true;
+         if (!es->predicate)
+           continue;
+         for (j = 0; es->predicate->clause[j]; j++)
+           if (!(possible_truths & es->predicate->clause[j]))
+             {
+               new_predicate = false_predicate ();
+               break;
+             }
+           else
+             add_clause (&new_predicate,
+                         possible_truths & es->predicate->clause[j]);
+         if (false_predicate_p (&new_predicate)
+             && !false_predicate_p (es->predicate))
+           {
+             optimized_out_size += es->call_stmt_size * INLINE_SIZE_SCALE;
+             optimized_out_time += (es->call_stmt_time
+                                    * (INLINE_TIME_SCALE / CGRAPH_FREQ_BASE)
+                                    * edge->frequency);
+             edge->frequency = 0;
+           }
+         *es->predicate = new_predicate;
+       }
+
+      /* If inliner or someone after inliner will ever start producing
+        non-trivial clones, we will get trouble with lack of information
+        about updating self sizes, because size vectors already contains
+        sizes of the calees.  */
+      gcc_assert (!inlined_to_p 
+                 || (!optimized_out_size && !optimized_out_time));
+
+      info->size -= optimized_out_size / INLINE_SIZE_SCALE;
+      info->self_size -= optimized_out_size / INLINE_SIZE_SCALE;
+      gcc_assert (info->size > 0);
+      gcc_assert (info->self_size > 0);
+
+      optimized_out_time /= INLINE_TIME_SCALE;
+      if (optimized_out_time > MAX_TIME)
+       optimized_out_time = MAX_TIME;
+      info->time -= optimized_out_time;
+      info->self_time -= optimized_out_time;
+      if (info->time < 0)
+       info->time = 0;
+      if (info->self_time < 0)
+       info->self_time = 0;
+    }
+  else
+    info->entry = VEC_copy (size_time_entry, gc, info->entry);
 }
 
 
@@ -695,16 +920,19 @@ dump_inline_edge_summary (FILE * f, int indent, struct cgraph_node *node,
   for (edge = node->callees; edge; edge = edge->next_callee)
     {
       struct inline_edge_summary *es = inline_edge_summary (edge);
-      fprintf (f, "%*s%s/%i %s\n%*s  loop depth:%2i freq:%4i size:%2i time: %2i",
-              indent, "", cgraph_node_name (edge->callee),
-              edge->callee->uid, 
+      struct cgraph_node *callee = cgraph_function_or_thunk_node (edge->callee, NULL);
+      fprintf (f, "%*s%s/%i %s\n%*s  loop depth:%2i freq:%4i size:%2i time: %2i callee size:%2i stack:%2i",
+              indent, "", cgraph_node_name (callee),
+              callee->uid, 
               !edge->inline_failed ? "inlined"
               : cgraph_inline_failed_string (edge->inline_failed),
               indent, "",
               es->loop_depth,  
                edge->frequency,
               es->call_stmt_size,
-              es->call_stmt_time);
+              es->call_stmt_time,
+              (int)inline_summary (callee)->size,
+              (int)inline_summary (callee)->estimated_stack_size);
       if (es->predicate)
        {
          fprintf (f, " predicate: ");
@@ -713,7 +941,14 @@ dump_inline_edge_summary (FILE * f, int indent, struct cgraph_node *node,
       else
          fprintf (f, "\n");
       if (!edge->inline_failed)
-       dump_inline_edge_summary (f, indent+2, edge->callee, info);
+       {
+          fprintf (f, "%*sStack frame offset %i, callee self size %i, callee size %i\n",
+                  indent+2, "",
+                  (int)inline_summary (callee)->stack_frame_offset,
+                  (int)inline_summary (callee)->estimated_self_stack_size,
+                  (int)inline_summary (callee)->estimated_stack_size);
+         dump_inline_edge_summary (f, indent+2, callee, info);
+       }
     }
   for (edge = node->indirect_calls; edge; edge = edge->next_callee)
     {
@@ -735,7 +970,7 @@ dump_inline_edge_summary (FILE * f, int indent, struct cgraph_node *node,
 }
 
 
-static void
+void
 dump_inline_summary (FILE * f, struct cgraph_node *node)
 {
   if (node->analyzed)
@@ -776,7 +1011,7 @@ dump_inline_summary (FILE * f, struct cgraph_node *node)
     }
 }
 
-void
+DEBUG_FUNCTION void
 debug_inline_summary (struct cgraph_node *node)
 {
   dump_inline_summary (stderr, node);
@@ -885,56 +1120,245 @@ eliminated_by_inlining_prob (gimple stmt)
 }
 
 
-/* Return predicate that must be true when is E executable.  */
+/* If BB ends by a conditional we can turn into predicates, attach corresponding
+   predicates to the CFG edges.   */
 
-static struct predicate
-edge_execution_predicate (struct ipa_node_params *info,
-                         struct inline_summary *summary,
-                         edge e)
+static void
+set_cond_stmt_execution_predicate (struct ipa_node_params *info,
+                                  struct inline_summary *summary,
+                                  basic_block bb)
 {
-  struct predicate p = true_predicate ();
   gimple last;
   tree op;
   int index;
-  enum tree_code code;
-
-  if (e->src == ENTRY_BLOCK_PTR)
-    return p;
+  enum tree_code code, inverted_code;
+  edge e;
+  edge_iterator ei;
+  gimple set_stmt;
+  tree op2;
 
-  last = last_stmt (e->src);
-  /* TODO: handle switch.  */
+  last = last_stmt (bb);
   if (!last
       || gimple_code (last) != GIMPLE_COND)
-    return p;
+    return;
   if (!is_gimple_ip_invariant (gimple_cond_rhs (last)))
-    return p;
+    return;
   op = gimple_cond_lhs (last);
   /* TODO: handle conditionals like
      var = op0 < 4;
-     if (var != 0)
-     and __bulitin_constant_p.  */
+     if (var != 0).  */
+  if (TREE_CODE (op) != SSA_NAME)
+    return;
+  if (SSA_NAME_IS_DEFAULT_DEF (op))
+    {
+      index = ipa_get_param_decl_index (info, SSA_NAME_VAR (op));
+      if (index == -1)
+       return;
+      code = gimple_cond_code (last);
+      inverted_code = invert_tree_comparison (code,
+                                             HONOR_NANS (TYPE_MODE (TREE_TYPE (op))));
+
+      FOR_EACH_EDGE (e, ei, bb->succs)
+       {
+         struct predicate p = add_condition (summary,
+                                             index,
+                                             e->flags & EDGE_TRUE_VALUE
+                                             ? code : inverted_code,
+                                             gimple_cond_rhs (last));
+         e->aux = pool_alloc (edge_predicate_pool);
+         *(struct predicate *)e->aux = p;
+       }
+    }
+
+  /* Special case
+     if (builtin_constant_p (op))
+       constant_code
+     else
+       nonconstant_code.
+     Here we can predicate nonconstant_code.  We can't
+     really handle constant_code since we have no predicate
+     for this and also the constant code is not known to be
+     optimized away when inliner doen't see operand is constant.
+     Other optimizers might think otherwise.  */
+  set_stmt = SSA_NAME_DEF_STMT (op);
+  if (!gimple_call_builtin_p (set_stmt, BUILT_IN_CONSTANT_P)
+      || gimple_call_num_args (set_stmt) != 1)
+    return;
+  op2 = gimple_call_arg (set_stmt, 0);
+  if (!SSA_NAME_IS_DEFAULT_DEF (op2))
+    return;
+  index = ipa_get_param_decl_index (info, SSA_NAME_VAR (op2));
+  if (index == -1)
+    return;
+  if (gimple_cond_code (last) != NE_EXPR
+      || !integer_zerop (gimple_cond_rhs (last)))
+    return;
+  FOR_EACH_EDGE (e, ei, bb->succs)
+    if (e->flags & EDGE_FALSE_VALUE)
+      {
+       struct predicate p = add_condition (summary,
+                                           index,
+                                           IS_NOT_CONSTANT,
+                                           NULL);
+       e->aux = pool_alloc (edge_predicate_pool);
+       *(struct predicate *)e->aux = p;
+      }
+}
+
+
+/* If BB ends by a switch we can turn into predicates, attach corresponding
+   predicates to the CFG edges.   */
+
+static void
+set_switch_stmt_execution_predicate (struct ipa_node_params *info,
+                                  struct inline_summary *summary,
+                                  basic_block bb)
+{
+  gimple last;
+  tree op;
+  int index;
+  edge e;
+  edge_iterator ei;
+  size_t n;
+  size_t case_idx;
+
+  last = last_stmt (bb);
+  if (!last
+      || gimple_code (last) != GIMPLE_SWITCH)
+    return;
+  op = gimple_switch_index (last);
   if (TREE_CODE (op) != SSA_NAME
       || !SSA_NAME_IS_DEFAULT_DEF (op))
-    return p;
+    return;
   index = ipa_get_param_decl_index (info, SSA_NAME_VAR (op));
   if (index == -1)
-    return p;
-  code = gimple_cond_code (last);
+    return;
 
-  if (EDGE_TRUE_VALUE)
-    code = invert_tree_comparison (code,
-                                  HONOR_NANS (TYPE_MODE (TREE_TYPE (op))));
+  FOR_EACH_EDGE (e, ei, bb->succs)
+    {
+      e->aux = pool_alloc (edge_predicate_pool);
+      *(struct predicate *)e->aux = false_predicate ();
+    }
+  n = gimple_switch_num_labels(last);
+  for (case_idx = 0; case_idx < n; ++case_idx)
+    {
+      tree cl = gimple_switch_label (last, case_idx);
+      tree min, max;
+      struct predicate p;
 
-  return add_condition (summary,
-                       index,
-                       gimple_cond_code (last),
-                       gimple_cond_rhs (last));
+      e = find_edge (bb, label_to_block (CASE_LABEL (cl)));
+      min = CASE_LOW (cl);
+      max = CASE_HIGH (cl);
+
+      /* For default we might want to construct predicate that none
+        of cases is met, but it is bit hard to do not having negations
+        of conditionals handy.  */
+      if (!min && !max)
+       p = true_predicate ();
+      else if (!max)
+       p = add_condition (summary, index,
+                          EQ_EXPR,
+                          min);
+      else
+       {
+         struct predicate p1, p2;
+         p1 = add_condition (summary, index,
+                             GE_EXPR,
+                             min);
+         p2 = add_condition (summary, index,
+                             LE_EXPR,
+                             max);
+         p = and_predicates (&p1, &p2);
+       }
+      *(struct predicate *)e->aux
+       = or_predicates (&p, (struct predicate *)e->aux);
+    }
 }
 
+
+/* For each BB in NODE attach to its AUX pointer predicate under
+   which it is executable.  */
+
+static void
+compute_bb_predicates (struct cgraph_node *node,
+                      struct ipa_node_params *parms_info,
+                      struct inline_summary *summary)
+{
+  struct function *my_function = DECL_STRUCT_FUNCTION (node->decl);
+  bool done = false;
+  basic_block bb;
+
+  FOR_EACH_BB_FN (bb, my_function)
+    {
+      set_cond_stmt_execution_predicate (parms_info, summary, bb);
+      set_switch_stmt_execution_predicate (parms_info, summary, bb);
+    }
+
+  /* Entry block is always executable.  */
+  ENTRY_BLOCK_PTR_FOR_FUNCTION (my_function)->aux = pool_alloc (edge_predicate_pool);
+  *(struct predicate *)ENTRY_BLOCK_PTR_FOR_FUNCTION (my_function)->aux
+    = true_predicate ();
+
+  /* A simple dataflow propagation of predicates forward in the CFG.
+     TODO: work in reverse postorder.  */
+  while (!done)
+    {
+      done = true;
+      FOR_EACH_BB_FN (bb, my_function)
+       {
+          struct predicate p = false_predicate ();
+          edge e;
+          edge_iterator ei;
+         FOR_EACH_EDGE (e, ei, bb->preds)
+           {
+             if (e->src->aux)
+               {
+                 struct predicate this_bb_predicate = *(struct predicate *)e->src->aux;
+                 if (e->aux)
+                   this_bb_predicate = and_predicates (&this_bb_predicate,
+                                                       (struct predicate *)e->aux);
+                 p = or_predicates (&p, &this_bb_predicate);
+                 if (true_predicate_p (&p))
+                   break;
+               }
+           }
+         if (false_predicate_p (&p))
+           gcc_assert (!bb->aux);
+         else
+           {
+             if (!bb->aux)
+               {
+                 done = false;
+                 bb->aux = pool_alloc (edge_predicate_pool);
+                 *((struct predicate *)bb->aux) = p;
+               }
+             else if (!predicates_equal_p (&p, (struct predicate *)bb->aux))
+               {
+                 done = false;
+                 *((struct predicate *)bb->aux) = p;
+               }
+           }
+       }
+    }
+}
+
+
+/* We keep info about constantness of SSA names.  */
+
+typedef struct predicate predicate_t;
+DEF_VEC_O (predicate_t);
+DEF_VEC_ALLOC_O (predicate_t, heap);
+
+
+/* Return predicate specifying when the STMT might have result that is not a compile
+   time constant.  */
+
 static struct predicate
 will_be_nonconstant_predicate (struct ipa_node_params *info,
                               struct inline_summary *summary,
-                              gimple stmt)
+                              gimple stmt,
+                              VEC (predicate_t, heap) *nonconstant_names)
+                             
 {
   struct predicate p = true_predicate ();
   ssa_op_iter iter;
@@ -943,13 +1367,15 @@ will_be_nonconstant_predicate (struct ipa_node_params *info,
 
   /* What statments might be optimized away
      when their arguments are constant
-     TODO: also trivial builtins, especially builtin_constant_p.  */
+     TODO: also trivial builtins.
+     builtin_constant_p is already handled later.  */
   if (gimple_code (stmt) != GIMPLE_ASSIGN
       && gimple_code (stmt) != GIMPLE_COND
       && gimple_code (stmt) != GIMPLE_SWITCH)
     return p;
 
-  /* Stores and loads will stay anyway.  */
+  /* Stores and loads will stay anyway.
+     TODO: Constant memory accesses could be handled here, too.  */
   if (gimple_vuse (stmt))
     return p;
 
@@ -957,21 +1383,36 @@ will_be_nonconstant_predicate (struct ipa_node_params *info,
      adding conditionals.  */
   FOR_EACH_SSA_TREE_OPERAND (use, stmt, iter, SSA_OP_USE)
     {
-      /* TODO: handle nested expressions and constant
-        array accesses.  */
-      if (TREE_CODE (use) != SSA_NAME
-         || !SSA_NAME_IS_DEFAULT_DEF (use)
-         || ipa_get_param_decl_index (info, SSA_NAME_VAR (use)) < 0)
+      if (TREE_CODE (use) != SSA_NAME)
        return p;
+      /* For arguments we can build a condition.  */
+      if (SSA_NAME_IS_DEFAULT_DEF (use)
+         && ipa_get_param_decl_index (info, SSA_NAME_VAR (use)) >= 0)
+       continue;
+      /* If we know when operand is constant,
+        we still can say something useful.  */
+      if (!true_predicate_p (VEC_index (predicate_t, nonconstant_names,
+                                       SSA_NAME_VERSION (use))))
+       continue;
+      return p;
     }
   op_non_const = false_predicate ();
   FOR_EACH_SSA_TREE_OPERAND (use, stmt, iter, SSA_OP_USE)
     {
-      p = add_condition (summary,
-                        ipa_get_param_decl_index (info, SSA_NAME_VAR (use)),
-                        IS_NOT_CONSTANT, NULL);
+      if (SSA_NAME_IS_DEFAULT_DEF (use)
+         && ipa_get_param_decl_index (info, SSA_NAME_VAR (use)) >= 0)
+       p = add_condition (summary,
+                          ipa_get_param_decl_index (info, SSA_NAME_VAR (use)),
+                          IS_NOT_CONSTANT, NULL);
+      else
+       p = *VEC_index (predicate_t, nonconstant_names,
+                       SSA_NAME_VERSION (use));
       op_non_const = or_predicates (&p, &op_non_const);
     }
+  if (gimple_code (stmt) == GIMPLE_ASSIGN
+      && TREE_CODE (gimple_assign_lhs (stmt)) == SSA_NAME)
+    VEC_replace (predicate_t, nonconstant_names,
+                SSA_NAME_VERSION (gimple_assign_lhs (stmt)), &op_non_const);
   return op_non_const;
 }
 
@@ -994,9 +1435,15 @@ estimate_function_body_sizes (struct cgraph_node *node, bool early)
   int freq;
   struct inline_summary *info = inline_summary (node);
   struct predicate bb_predicate;
-  struct ipa_node_params *parms_info;
+  struct ipa_node_params *parms_info = NULL;
+  VEC (predicate_t, heap) *nonconstant_names = NULL;
 
-  parms_info = ipa_node_params_vector && !early ? IPA_NODE_REF (node) : NULL;
+  if (ipa_node_params_vector && !early && optimize)
+    {
+      parms_info = IPA_NODE_REF (node);
+      VEC_safe_grow_cleared (predicate_t, heap, nonconstant_names,
+                            VEC_length (tree, SSANAMES (my_function)));
+    }
 
   info->conds = 0;
   info->entry = 0;
@@ -1014,25 +1461,20 @@ estimate_function_body_sizes (struct cgraph_node *node, bool early)
   bb_predicate = not_inlined_predicate ();
   account_size_time (info, 2 * INLINE_SIZE_SCALE, 0, &bb_predicate);
 
-
   gcc_assert (my_function && my_function->cfg);
+  if (parms_info)
+    compute_bb_predicates (node, parms_info, info);
   FOR_EACH_BB_FN (bb, my_function)
     {
-      edge e;
-      edge_iterator ei;
-
       freq = compute_call_stmt_bb_frequency (node->decl, bb);
 
       /* TODO: Obviously predicates can be propagated down across CFG.  */
       if (parms_info)
        {
-          bb_predicate = false_predicate ();
-         FOR_EACH_EDGE (e, ei, bb->preds)
-           {
-             struct predicate ep;
-             ep = edge_execution_predicate (parms_info, info, e);
-             bb_predicate = or_predicates (&ep, &bb_predicate);
-           }
+         if (bb->aux)
+           bb_predicate = *(struct predicate *)bb->aux;
+         else
+           bb_predicate = false_predicate ();
        }
       else
        bb_predicate = true_predicate ();
@@ -1049,6 +1491,7 @@ estimate_function_body_sizes (struct cgraph_node *node, bool early)
          int this_size = estimate_num_insns (stmt, &eni_size_weights);
          int this_time = estimate_num_insns (stmt, &eni_time_weights);
          int prob;
+         struct predicate will_be_nonconstant;
 
          if (dump_file && (dump_flags & TDF_DETAILS))
            {
@@ -1063,6 +1506,19 @@ estimate_function_body_sizes (struct cgraph_node *node, bool early)
              struct cgraph_edge *edge = cgraph_edge (node, stmt);
              struct inline_edge_summary *es = inline_edge_summary (edge);
 
+             /* Special case: results of BUILT_IN_CONSTANT_P will be always
+                resolved as constant.  We however don't want to optimize
+                out the cgraph edges.  */
+             if (nonconstant_names
+                 && gimple_call_builtin_p (stmt, BUILT_IN_CONSTANT_P)
+                 && gimple_call_lhs (stmt)
+                 && TREE_CODE (gimple_call_lhs (stmt)) == SSA_NAME)
+               {
+                 struct predicate false_p = false_predicate ();
+                 VEC_replace (predicate_t, nonconstant_names,
+                              SSA_NAME_VERSION (gimple_call_lhs (stmt)), &false_p);
+               }
+
              es->call_stmt_size = this_size;
              es->call_stmt_time = this_time;
              es->loop_depth = bb->loop_depth;
@@ -1071,7 +1527,10 @@ estimate_function_body_sizes (struct cgraph_node *node, bool early)
              /* Do not inline calls where we cannot triviall work around
                 mismatches in argument or return types.  */
              if (edge->callee
-                 && !gimple_check_call_matching_types (stmt, edge->callee->decl))
+                 && cgraph_function_or_thunk_node (edge->callee, NULL)
+                 && !gimple_check_call_matching_types (stmt,
+                                                       cgraph_function_or_thunk_node (edge->callee,
+                                                                                      NULL)->decl))
                {
                  edge->call_stmt_cannot_inline_p = true;
                  gimple_call_set_cannot_inline (stmt, true);
@@ -1080,9 +1539,15 @@ estimate_function_body_sizes (struct cgraph_node *node, bool early)
                gcc_assert (!gimple_call_cannot_inline_p (stmt));
            }
 
+         /* TODO: When conditional jump or swithc is known to be constant, but
+            we did not translate it into the predicates, we really can account
+            just maximum of the possible paths.  */
+         if (parms_info)
+           will_be_nonconstant
+              = will_be_nonconstant_predicate (parms_info, info,
+                                               stmt, nonconstant_names);
          if (this_time || this_size)
            {
-             struct predicate will_be_nonconstant;
              struct predicate p;
 
              this_time *= freq;
@@ -1096,11 +1561,7 @@ estimate_function_body_sizes (struct cgraph_node *node, bool early)
                fprintf (dump_file, "\t\twill eliminated by inlining\n");
 
              if (parms_info)
-               {
-                 will_be_nonconstant
-                    = will_be_nonconstant_predicate (parms_info, info, stmt);
-                 p = and_predicates (&bb_predicate, &will_be_nonconstant);
-               }
+               p = and_predicates (&bb_predicate, &will_be_nonconstant);
              else
                p = true_predicate ();
 
@@ -1126,11 +1587,27 @@ estimate_function_body_sizes (struct cgraph_node *node, bool early)
            }
        }
     }
+  FOR_ALL_BB_FN (bb, my_function)
+    {
+      edge e;
+      edge_iterator ei;
+
+      if (bb->aux)
+       pool_free (edge_predicate_pool, bb->aux);
+      bb->aux = NULL;
+      FOR_EACH_EDGE (e, ei, bb->succs)
+       {
+         if (e->aux)
+           pool_free (edge_predicate_pool, e->aux);
+         e->aux = NULL;
+       }
+    }
   time = (time + CGRAPH_FREQ_BASE / 2) / CGRAPH_FREQ_BASE;
   if (time > MAX_TIME)
     time = MAX_TIME;
   inline_summary (node)->self_time = time;
   inline_summary (node)->self_size = size;
+  VEC_free (predicate_t, heap, nonconstant_names);
   if (dump_file)
     {
       fprintf (dump_file, "\n");
@@ -1155,6 +1632,23 @@ compute_inline_parameters (struct cgraph_node *node, bool early)
 
   info = inline_summary (node);
 
+  /* FIXME: Thunks are inlinable, but tree-inline don't know how to do that.
+     Once this happen, we will need to more curefully predict call
+     statement size.  */
+  if (node->thunk.thunk_p)
+    {
+      struct inline_edge_summary *es = inline_edge_summary (node->callees);
+      struct predicate t = true_predicate ();
+
+      info->inlinable = info->versionable = 0;
+      node->callees->call_stmt_cannot_inline_p = true;
+      node->local.can_change_signature = false;
+      es->call_stmt_time = 1;
+      es->call_stmt_size = 1;
+      account_size_time (info, 0, 0, &t);
+      return;
+    }
+
   /* Estimate the stack size for the function if we're optimizing.  */
   self_stack_size = optimize ? estimated_stack_frame_size (node) : 0;
   info->estimated_self_stack_size = self_stack_size;
@@ -1260,17 +1754,15 @@ estimate_calls_size_and_time (struct cgraph_node *node, int *size, int *time,
 }
 
 
-/* Estimate size and time needed to execute callee of EDGE assuming
-   that parameters known to be constant at caller of EDGE are
-   propagated.  If INLINE_P is true, it is assumed that call will
-   be inlined.  */
+/* Estimate size and time needed to execute NODE assuming
+   POSSIBLE_TRUTHS clause. */
 
 static void
-estimate_callee_size_and_time (struct cgraph_edge *edge, bool inline_p,
-                              int *ret_size, int *ret_time)
+estimate_node_size_and_time (struct cgraph_node *node,
+                            clause_t possible_truths,
+                            int *ret_size, int *ret_time)
 {
-  struct inline_summary *info = inline_summary (edge->callee);
-  clause_t clause = evaluate_conditions_for_edge (edge, inline_p);
+  struct inline_summary *info = inline_summary (node);
   size_time_entry *e;
   int size = 0, time = 0;
   int i;
@@ -1279,15 +1771,15 @@ estimate_callee_size_and_time (struct cgraph_edge *edge, bool inline_p,
       && (dump_flags & TDF_DETAILS))
     {
       bool found = false;
-      fprintf (dump_file, "   Estimating callee body: %s/%i\n"
+      fprintf (dump_file, "   Estimating body: %s/%i\n"
                          "   Known to be false: ",
-              cgraph_node_name (edge->callee),
-              edge->callee->uid);
+              cgraph_node_name (node),
+              node->uid);
 
       for (i = predicate_not_inlined_condition;
           i < (predicate_first_dynamic_condition
                + (int)VEC_length (condition, info->conds)); i++)
-       if (!(clause & (1 << i)))
+       if (!(possible_truths & (1 << i)))
          {
            if (found)
              fprintf (dump_file, ", ");
@@ -1297,13 +1789,13 @@ estimate_callee_size_and_time (struct cgraph_edge *edge, bool inline_p,
     }
 
   for (i = 0; VEC_iterate (size_time_entry, info->entry, i, e); i++)
-    if (evaluate_predicate (&e->predicate, clause))
+    if (evaluate_predicate (&e->predicate, possible_truths))
       time += e->time, size += e->size;
 
   if (time > MAX_TIME * INLINE_TIME_SCALE)
     time = MAX_TIME * INLINE_TIME_SCALE;
 
-  estimate_calls_size_and_time (edge->callee, &size, &time, clause);
+  estimate_calls_size_and_time (node, &size, &time, possible_truths);
   time = (time + INLINE_TIME_SCALE / 2) / INLINE_TIME_SCALE;
   size = (size + INLINE_SIZE_SCALE / 2) / INLINE_SIZE_SCALE;
 
@@ -1319,6 +1811,22 @@ estimate_callee_size_and_time (struct cgraph_edge *edge, bool inline_p,
 }
 
 
+/* Estimate size and time needed to execute callee of EDGE assuming that
+   parameters known to be constant at caller of EDGE are propagated.
+   KNOWN_VALs is a vector of assumed known constant values for parameters.  */
+
+void
+estimate_ipcp_clone_size_and_time (struct cgraph_node *node,
+                                  VEC (tree, heap) *known_vals,
+                                  int *ret_size, int *ret_time)
+{
+  clause_t clause;
+
+  clause = evaluate_conditions_for_known_args (node, false, known_vals);
+  estimate_node_size_and_time (node, clause, ret_size, ret_time);
+}
+
+
 /* Translate all conditions from callee representation into caller representation and
    symbolically evaluate predicate P into new predicate.
 
@@ -1365,6 +1873,7 @@ remap_predicate (struct inline_summary *info, struct inline_summary *callee_info
                 /* See if we can remap condition operand to caller's operand.
                    Otherwise give up.  */
                 if (!operand_map
+                    || (int)VEC_length (int, operand_map) <= c->operand_num
                     || VEC_index (int, operand_map, c->operand_num) == -1)
                   cond_predicate = true_predicate ();
                 else
@@ -1454,6 +1963,8 @@ remap_edge_predicates (struct cgraph_node *node,
       if (!e->inline_failed)
        remap_edge_predicates (e->callee, info, callee_info, operand_map,
                               possible_truths, toplev_predicate);
+      else
+       edge_set_predicate (e, toplev_predicate);
     }
   for (e = node->indirect_calls; e; e = e->next_callee)
     {
@@ -1474,6 +1985,8 @@ remap_edge_predicates (struct cgraph_node *node,
              e->frequency = 0;
            }
        }
+      else
+       edge_set_predicate (e, toplev_predicate);
     }
 }
 
@@ -1567,7 +2080,9 @@ do_estimate_edge_time (struct cgraph_edge *edge)
   struct inline_edge_summary *es = inline_edge_summary (edge);
 
   gcc_checking_assert (edge->inline_failed);
-  estimate_callee_size_and_time (edge, true, &size, &time);
+  estimate_node_size_and_time (cgraph_function_or_thunk_node (edge->callee, NULL),
+                              evaluate_conditions_for_edge (edge, true),
+                              &size, &time);
 
   ret = (((gcov_type)time - es->call_stmt_time) * edge->frequency
         + CGRAPH_FREQ_BASE / 2) / CGRAPH_FREQ_BASE;
@@ -1601,6 +2116,7 @@ int
 do_estimate_edge_growth (struct cgraph_edge *edge)
 {
   int size;
+  struct cgraph_node *callee;
 
   /* When we do caching, use do_estimate_edge_time to populate the entry.  */
 
@@ -1613,10 +2129,13 @@ do_estimate_edge_growth (struct cgraph_edge *edge)
       gcc_checking_assert (size);
       return size - (size > 0);
     }
+  callee = cgraph_function_or_thunk_node (edge->callee, NULL);
 
   /* Early inliner runs without caching, go ahead and do the dirty work.  */
   gcc_checking_assert (edge->inline_failed);
-  estimate_callee_size_and_time (edge, true, &size, NULL);
+  estimate_node_size_and_time (callee,
+                              evaluate_conditions_for_edge (edge, true),
+                              &size, NULL);
   gcc_checking_assert (inline_edge_summary (edge)->call_stmt_size);
   return size - inline_edge_summary (edge)->call_stmt_size;
 }
@@ -1628,12 +2147,17 @@ int
 estimate_time_after_inlining (struct cgraph_node *node,
                              struct cgraph_edge *edge)
 {
-  gcov_type time = inline_summary (node)->time + estimate_edge_time (edge);
-  if (time < 0)
-    time = 0;
-  if (time > MAX_TIME)
-    time = MAX_TIME;
-  return time;
+  struct inline_edge_summary *es = inline_edge_summary (edge);
+  if (!es->predicate || !false_predicate_p (es->predicate))
+    {
+      gcov_type time = inline_summary (node)->time + estimate_edge_time (edge);
+      if (time < 0)
+       time = 0;
+      if (time > MAX_TIME)
+       time = MAX_TIME;
+      return time;
+    }
+  return inline_summary (node)->time;
 }
 
 
@@ -1644,21 +2168,31 @@ int
 estimate_size_after_inlining (struct cgraph_node *node,
                              struct cgraph_edge *edge)
 {
-  int size = inline_summary (node)->size + estimate_edge_growth (edge);
-  gcc_assert (size >= 0);
-  return size;
+  struct inline_edge_summary *es = inline_edge_summary (edge);
+  if (!es->predicate || !false_predicate_p (es->predicate))
+    {
+      int size = inline_summary (node)->size + estimate_edge_growth (edge);
+      gcc_assert (size >= 0);
+      return size;
+    }
+  return inline_summary (node)->size;
 }
 
 
-/* Estimate the growth caused by inlining NODE into all callees.  */
+struct growth_data
+{
+  bool self_recursive;
+  int growth;
+};
 
-int
-do_estimate_growth (struct cgraph_node *node)
+
+/* Worker for do_estimate_growth.  Collect growth for all callers.  */
+
+static bool
+do_estimate_growth_1 (struct cgraph_node *node, void *data)
 {
-  int growth = 0;
   struct cgraph_edge *e;
-  bool self_recursive = false;
-  struct inline_summary *info = inline_summary (node);
+  struct growth_data *d = (struct growth_data *) data;
 
   for (e = node->callers; e; e = e->next_caller)
     {
@@ -1667,37 +2201,49 @@ do_estimate_growth (struct cgraph_node *node)
       if (e->caller == node
          || (e->caller->global.inlined_to
              && e->caller->global.inlined_to == node))
-        self_recursive = true;
-      growth += estimate_edge_growth (e);
+        d->self_recursive = true;
+      d->growth += estimate_edge_growth (e);
     }
-     
+  return false;
+}
+
+
+/* Estimate the growth caused by inlining NODE into all callees.  */
+
+int
+do_estimate_growth (struct cgraph_node *node)
+{
+  struct growth_data d = {0, false};
+  struct inline_summary *info = inline_summary (node);
+
+  cgraph_for_node_and_aliases (node, do_estimate_growth_1, &d, true);
 
   /* For self recursive functions the growth estimation really should be
      infinity.  We don't want to return very large values because the growth
      plays various roles in badness computation fractions.  Be sure to not
      return zero or negative growths. */
-  if (self_recursive)
-    growth = growth < info->size ? info->size : growth;
+  if (d.self_recursive)
+    d.growth = d.growth < info->size ? info->size : d.growth;
   else
     {
-      if (cgraph_will_be_removed_from_program_if_no_direct_calls (node)
-         && !DECL_EXTERNAL (node->decl))
-       growth -= info->size;
+      if (!DECL_EXTERNAL (node->decl)
+         && cgraph_will_be_removed_from_program_if_no_direct_calls (node))
+       d.growth -= info->size;
       /* COMDAT functions are very often not shared across multiple units since they
         come from various template instantiations.  Take this into account.  */
       else  if (DECL_COMDAT (node->decl)
                && cgraph_can_remove_if_no_direct_calls_p (node))
-       growth -= (info->size
-                  * (100 - PARAM_VALUE (PARAM_COMDAT_SHARING_PROBABILITY)) + 50) / 100;
+       d.growth -= (info->size
+                    * (100 - PARAM_VALUE (PARAM_COMDAT_SHARING_PROBABILITY)) + 50) / 100;
     }
 
   if (node_growth_cache)
     {
       if ((int)VEC_length (int, node_growth_cache) <= node->uid)
        VEC_safe_grow_cleared (int, heap, node_growth_cache, cgraph_max_uid);
-      VEC_replace (int, node_growth_cache, node->uid, growth + (growth >= 0));
+      VEC_replace (int, node_growth_cache, node->uid, d.growth + (d.growth >= 0));
     }
-  return growth;
+  return d.growth;
 }
 
 
@@ -1729,7 +2275,7 @@ inline_analyze_function (struct cgraph_node *node)
             cgraph_node_name (node), node->uid);
   /* FIXME: We should remove the optimize check after we ensure we never run
      IPA passes when not optimizing.  */
-  if (flag_indirect_inlining && optimize)
+  if (flag_indirect_inlining && optimize && !node->thunk.thunk_p)
     inline_indirect_intraprocedural_analysis (node);
   compute_inline_parameters (node, false);
 
@@ -1760,8 +2306,8 @@ inline_generate_summary (void)
   if (flag_indirect_inlining)
     ipa_register_cgraph_hooks ();
 
-  for (node = cgraph_nodes; node; node = node->next)
-    if (node->analyzed)
+  FOR_EACH_DEFINED_FUNCTION (node)
+    if (!node->alias)
       inline_analyze_function (node);
 }
 
@@ -1777,10 +2323,15 @@ read_predicate (struct lto_input_block *ib)
 
   do 
     {
+      gcc_assert (k <= MAX_CLAUSES);
       clause = out.clause[k++] = lto_input_uleb128 (ib);
-      gcc_assert (k < MAX_CLAUSES);
     }
   while (clause);
+
+  /* Zero-initialize the remaining clauses in OUT.  */
+  while (k <= MAX_CLAUSES)
+    out.clause[k++] = 0;
+
   return out;
 }