+ build_int_cst (ptr_type_node, 0));
+
+ return detect_type_change_1 (arg, arg, comp_type, call, jfunc, 0);
+}
+
+/* Callback of walk_aliased_vdefs. Flags that it has been invoked to the
+ boolean variable pointed to by DATA. */
+
+static bool
+mark_modified (ao_ref *ao ATTRIBUTE_UNUSED, tree vdef ATTRIBUTE_UNUSED,
+ void *data)
+{
+ bool *b = (bool *) data;
+ *b = true;
+ return true;
+}
+
+/* Return true if a load from a formal parameter PARM_LOAD is known to retreive
+ a value known not to be modified in this function before reaching the
+ statement STMT. PARM_AINFO is a pointer to a structure containing temporary
+ information about the parameter. */
+
+static bool
+parm_preserved_before_stmt_p (struct param_analysis_info *parm_ainfo,
+ gimple stmt, tree parm_load)
+{
+ bool modified = false;
+ bitmap *visited_stmts;
+ ao_ref refd;
+
+ if (parm_ainfo && parm_ainfo->parm_modified)
+ return false;
+
+ gcc_checking_assert (gimple_vuse (stmt) != NULL_TREE);
+ ao_ref_init (&refd, parm_load);
+ /* We can cache visited statements only when parm_ainfo is available and when
+ we are looking at a naked load of the whole parameter. */
+ if (!parm_ainfo || TREE_CODE (parm_load) != PARM_DECL)
+ visited_stmts = NULL;
+ else
+ visited_stmts = &parm_ainfo->parm_visited_statements;
+ walk_aliased_vdefs (&refd, gimple_vuse (stmt), mark_modified, &modified,
+ visited_stmts);
+ if (parm_ainfo && modified)
+ parm_ainfo->parm_modified = true;
+ return !modified;
+}
+
+/* If STMT is an assignment that loads a value from an parameter declaration,
+ return the index of the parameter in ipa_node_params which has not been
+ modified. Otherwise return -1. */
+
+static int
+load_from_unmodified_param (vec<ipa_param_descriptor_t> descriptors,
+ struct param_analysis_info *parms_ainfo,
+ gimple stmt)
+{
+ int index;
+ tree op1;
+
+ if (!gimple_assign_single_p (stmt))
+ return -1;
+
+ op1 = gimple_assign_rhs1 (stmt);
+ if (TREE_CODE (op1) != PARM_DECL)
+ return -1;
+
+ index = ipa_get_param_decl_index_1 (descriptors, op1);
+ if (index < 0
+ || !parm_preserved_before_stmt_p (parms_ainfo ? &parms_ainfo[index]
+ : NULL, stmt, op1))
+ return -1;
+
+ return index;
+}
+
+/* Return true if memory reference REF loads data that are known to be
+ unmodified in this function before reaching statement STMT. PARM_AINFO, if
+ non-NULL, is a pointer to a structure containing temporary information about
+ PARM. */
+
+static bool
+parm_ref_data_preserved_p (struct param_analysis_info *parm_ainfo,
+ gimple stmt, tree ref)
+{
+ bool modified = false;
+ ao_ref refd;
+
+ gcc_checking_assert (gimple_vuse (stmt));
+ if (parm_ainfo && parm_ainfo->ref_modified)
+ return false;
+
+ ao_ref_init (&refd, ref);
+ walk_aliased_vdefs (&refd, gimple_vuse (stmt), mark_modified, &modified,
+ NULL);
+ if (parm_ainfo && modified)
+ parm_ainfo->ref_modified = true;
+ return !modified;
+}
+
+/* Return true if the data pointed to by PARM is known to be unmodified in this
+ function before reaching call statement CALL into which it is passed.
+ PARM_AINFO is a pointer to a structure containing temporary information
+ about PARM. */
+
+static bool
+parm_ref_data_pass_through_p (struct param_analysis_info *parm_ainfo,
+ gimple call, tree parm)
+{
+ bool modified = false;
+ ao_ref refd;
+
+ /* It's unnecessary to calculate anything about memory contnets for a const
+ function because it is not goin to use it. But do not cache the result
+ either. Also, no such calculations for non-pointers. */
+ if (!gimple_vuse (call)
+ || !POINTER_TYPE_P (TREE_TYPE (parm)))
+ return false;
+
+ if (parm_ainfo->pt_modified)
+ return false;
+
+ ao_ref_init_from_ptr_and_size (&refd, parm, NULL_TREE);
+ walk_aliased_vdefs (&refd, gimple_vuse (call), mark_modified, &modified,
+ parm_ainfo ? &parm_ainfo->pt_visited_statements : NULL);
+ if (modified)
+ parm_ainfo->pt_modified = true;
+ return !modified;
+}
+
+/* Return true if we can prove that OP is a memory reference loading unmodified
+ data from an aggregate passed as a parameter and if the aggregate is passed
+ by reference, that the alias type of the load corresponds to the type of the
+ formal parameter (so that we can rely on this type for TBAA in callers).
+ INFO and PARMS_AINFO describe parameters of the current function (but the
+ latter can be NULL), STMT is the load statement. If function returns true,
+ *INDEX_P, *OFFSET_P and *BY_REF is filled with the parameter index, offset
+ within the aggregate and whether it is a load from a value passed by
+ reference respectively. */
+
+static bool
+ipa_load_from_parm_agg_1 (vec<ipa_param_descriptor_t> descriptors,
+ struct param_analysis_info *parms_ainfo, gimple stmt,
+ tree op, int *index_p, HOST_WIDE_INT *offset_p,
+ bool *by_ref_p)
+{
+ int index;
+ HOST_WIDE_INT size, max_size;
+ tree base = get_ref_base_and_extent (op, offset_p, &size, &max_size);
+
+ if (max_size == -1 || max_size != size || *offset_p < 0)
+ return false;
+
+ if (DECL_P (base))
+ {
+ int index = ipa_get_param_decl_index_1 (descriptors, base);
+ if (index >= 0
+ && parm_preserved_before_stmt_p (parms_ainfo ? &parms_ainfo[index]
+ : NULL, stmt, op))
+ {
+ *index_p = index;
+ *by_ref_p = false;
+ return true;
+ }
+ return false;
+ }
+
+ if (TREE_CODE (base) != MEM_REF
+ || TREE_CODE (TREE_OPERAND (base, 0)) != SSA_NAME
+ || !integer_zerop (TREE_OPERAND (base, 1)))
+ return false;
+
+ if (SSA_NAME_IS_DEFAULT_DEF (TREE_OPERAND (base, 0)))
+ {
+ tree parm = SSA_NAME_VAR (TREE_OPERAND (base, 0));
+ index = ipa_get_param_decl_index_1 (descriptors, parm);
+ }
+ else
+ {
+ /* This branch catches situations where a pointer parameter is not a
+ gimple register, for example:
+
+ void hip7(S*) (struct S * p)
+ {
+ void (*<T2e4>) (struct S *) D.1867;
+ struct S * p.1;
+
+ <bb 2>:
+ p.1_1 = p;
+ D.1867_2 = p.1_1->f;
+ D.1867_2 ();
+ gdp = &p;
+ */
+
+ gimple def = SSA_NAME_DEF_STMT (TREE_OPERAND (base, 0));
+ index = load_from_unmodified_param (descriptors, parms_ainfo, def);
+ }