return NULL;
}
+/* If IPA-CP discovered a constant in parameter PARM at OFFSET of a given SIZE
+ - whether passed by reference or not is given by BY_REF - return that
+ constant. Otherwise return NULL_TREE. */
+
+tree
+ipcp_get_aggregate_const (struct function *func, tree parm, bool by_ref,
+ HOST_WIDE_INT bit_offset, HOST_WIDE_INT bit_size)
+{
+ cgraph_node *node = cgraph_node::get (func->decl);
+ ipcp_transformation *ts = ipcp_get_transformation_summary (node);
+
+ if (!ts || !ts->m_agg_values)
+ return NULL_TREE;
+
+ int index = ts->get_param_index (func->decl, parm);
+ if (index < 0)
+ return NULL_TREE;
+
+ ipa_argagg_value_list avl (ts);
+ unsigned unit_offset = bit_offset / BITS_PER_UNIT;
+ tree v = avl.get_value (index, unit_offset, by_ref);
+ if (!v
+ || maybe_ne (tree_to_poly_int64 (TYPE_SIZE (TREE_TYPE (v))), bit_size))
+ return NULL_TREE;
+
+ return v;
+}
+
/* Return true if we have recorded VALUE and MASK about PARM.
Set VALUE and MASk accordingly. */
free_ipa_bb_info (bi);
fbi.bb_infos.release ();
- ipcp_transformation *s = ipcp_transformation_sum->get (node);
- s->m_agg_values = NULL;
- s->bits = NULL;
- s->m_vr = NULL;
-
vec_free (descriptors);
if (cfg_changed)
delete_unreachable_blocks_update_callgraph (node, false);
void ipa_release_body_info (struct ipa_func_body_info *);
tree ipa_get_callee_param_type (struct cgraph_edge *e, int i);
bool ipcp_get_parm_bits (tree, tree *, widest_int *);
+tree ipcp_get_aggregate_const (struct function *func, tree parm, bool by_ref,
+ HOST_WIDE_INT bit_offset,
+ HOST_WIDE_INT bit_size);
bool unadjusted_ptr_and_unit_offset (tree op, tree *ret,
poly_int64 *offset_ret);
--- /dev/null
+/* { dg-do run } */
+/* { dg-options "-O2 -fno-early-inlining" } */
+
+struct a {int a;};
+static int
+foo (struct a a)
+{
+ if (!__builtin_constant_p (a.a))
+ __builtin_abort ();
+ return a.a;
+}
+
+static int __attribute__ ((noinline))
+bar (struct a a)
+{
+ return foo(a);
+}
+
+volatile int r;
+
+int main()
+{
+ struct a a={1};
+ r = bar (a);
+ return 0;
+}
--- /dev/null
+/* { dg-do run } */
+/* { dg-options "-O2 -fno-early-inlining -fno-ipa-sra" } */
+
+struct a {int a;};
+static int
+foo (struct a *a)
+{
+ if (!__builtin_constant_p (a->a))
+ __builtin_abort ();
+ return a->a;
+}
+
+static int __attribute__ ((noinline))
+bar (struct a *a)
+{
+ return foo(a);
+}
+
+volatile int r;
+
+int main()
+{
+ struct a a={1};
+ r = bar (&a);
+ return 0;
+}
#include "ipa-modref-tree.h"
#include "ipa-modref.h"
#include "tree-ssa-sccvn.h"
+#include "alloc-pool.h"
+#include "symbol-summary.h"
+#include "ipa-prop.h"
/* This algorithm is based on the SCC algorithm presented by Keith
Cooper and L. Taylor Simpson in "SCC-Based Value numbering"
with the current VUSE and performs the expression lookup. */
static void *
-vn_reference_lookup_2 (ao_ref *op ATTRIBUTE_UNUSED, tree vuse, void *data_)
+vn_reference_lookup_2 (ao_ref *op, tree vuse, void *data_)
{
vn_walk_cb_data *data = (vn_walk_cb_data *)data_;
vn_reference_t vr = data->vr;
return *slot;
}
+ if (SSA_NAME_IS_DEFAULT_DEF (vuse))
+ {
+ HOST_WIDE_INT op_offset, op_size;
+ tree v = NULL_TREE;
+ tree base = ao_ref_base (op);
+
+ if (base
+ && op->offset.is_constant (&op_offset)
+ && op->size.is_constant (&op_size)
+ && op->max_size_known_p ()
+ && known_eq (op->size, op->max_size))
+ {
+ if (TREE_CODE (base) == PARM_DECL)
+ v = ipcp_get_aggregate_const (cfun, base, false, op_offset,
+ op_size);
+ else if (TREE_CODE (base) == MEM_REF
+ && integer_zerop (TREE_OPERAND (base, 1))
+ && TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME
+ && SSA_NAME_IS_DEFAULT_DEF (TREE_OPERAND (base, 0))
+ && (TREE_CODE (SSA_NAME_VAR (TREE_OPERAND (base, 0)))
+ == PARM_DECL))
+ v = ipcp_get_aggregate_const (cfun,
+ SSA_NAME_VAR (TREE_OPERAND (base, 0)),
+ true, op_offset, op_size);
+ }
+ if (v)
+ return data->finish (vr->set, vr->base_set, v);
+ }
+
return NULL;
}