+2014-10-04 Jan Hubicka <hubicka@ucw.cz>
+
+ * ipa-polymorphic-call.c (possible_placement_new): Fix condition
+ on size.
+ (ipa_polymorphic_call_context::restrict_to_inner_type): Do not walk
+ into vptr pointer.
+ (ipa_polymorphic_call_context::dump): Fix formating.
+ (walk_ssa_copies): Add logic avoiding loops; update uses.
+ * ipa-prop.c (ipa_analyze_call_uses): Compute vptr_changed.
+
2014-10-02 Mark Wielaard <mjw@redhat.com>
PR debug/63239
|| !tree_fits_shwi_p (TYPE_SIZE (type))
|| (cur_offset
+ (expected_type ? tree_to_uhwi (TYPE_SIZE (expected_type))
- : 1)
+ : GET_MODE_BITSIZE (Pmode))
<= tree_to_uhwi (TYPE_SIZE (type)))));
}
pos = int_bit_position (fld);
if (pos > (unsigned HOST_WIDE_INT)cur_offset)
continue;
+
+ /* Do not consider vptr itself. Not even for placement new. */
+ if (!pos && DECL_ARTIFICIAL (fld)
+ && POINTER_TYPE_P (TREE_TYPE (fld))
+ && TYPE_BINFO (type)
+ && polymorphic_type_binfo_p (TYPE_BINFO (type)))
+ continue;
+
if (!DECL_SIZE (fld) || !tree_fits_uhwi_p (DECL_SIZE (fld)))
goto no_useful_type_info;
size = tree_to_uhwi (DECL_SIZE (fld));
{
fprintf (f, " ");
if (invalid)
- fprintf (f, "Call is known to be undefined\n");
+ fprintf (f, "Call is known to be undefined");
else
{
if (useless_p ())
}
/* See if OP is SSA name initialized as a copy or by single assignment.
- If so, walk the SSA graph up. */
+ If so, walk the SSA graph up. Because simple PHI conditional is considered
+ copy, GLOBAL_VISITED may be used to avoid infinite loop walking the SSA
+ graph. */
static tree
-walk_ssa_copies (tree op)
+walk_ssa_copies (tree op, hash_set<tree> **global_visited = NULL)
{
+ hash_set <tree> *visited = NULL;
STRIP_NOPS (op);
while (TREE_CODE (op) == SSA_NAME
&& !SSA_NAME_IS_DEFAULT_DEF (op)
&& (gimple_assign_single_p (SSA_NAME_DEF_STMT (op))
|| gimple_code (SSA_NAME_DEF_STMT (op)) == GIMPLE_PHI))
{
+ if (global_visited)
+ {
+ if (!*global_visited)
+ *global_visited = new hash_set<tree>;
+ if ((*global_visited)->add (op))
+ goto done;
+ }
+ else
+ {
+ if (!visited)
+ visited = new hash_set<tree>;
+ if (visited->add (op))
+ goto done;
+ }
/* Special case
if (ptr == 0)
ptr = 0;
{
gimple phi = SSA_NAME_DEF_STMT (op);
- if (gimple_phi_num_args (phi) != 2)
- return op;
- if (integer_zerop (gimple_phi_arg_def (phi, 0)))
+ if (gimple_phi_num_args (phi) > 2)
+ goto done;
+ if (gimple_phi_num_args (phi) == 1)
+ op = gimple_phi_arg_def (phi, 0);
+ else if (integer_zerop (gimple_phi_arg_def (phi, 0)))
op = gimple_phi_arg_def (phi, 1);
else if (integer_zerop (gimple_phi_arg_def (phi, 1)))
op = gimple_phi_arg_def (phi, 0);
else
- return op;
+ goto done;
}
else
{
if (gimple_assign_load_p (SSA_NAME_DEF_STMT (op)))
- return op;
+ goto done;
op = gimple_assign_rhs1 (SSA_NAME_DEF_STMT (op));
}
STRIP_NOPS (op);
}
+done:
+ if (visited)
+ delete (visited);
return op;
}
{
tree otr_type = NULL;
tree base_pointer;
+ hash_set <tree> *visited = NULL;
if (TREE_CODE (ref) == OBJ_TYPE_REF)
{
invalid = false;
/* Walk SSA for outer object. */
- do
+ while (true)
{
- base_pointer = walk_ssa_copies (base_pointer);
+ base_pointer = walk_ssa_copies (base_pointer, &visited);
if (TREE_CODE (base_pointer) == ADDR_EXPR)
{
HOST_WIDE_INT size, max_size;
is known. */
else if (DECL_P (base))
{
+ if (visited)
+ delete (visited);
/* Only type inconsistent programs can have otr_type that is
not part of outer type. */
if (otr_type
else
break;
}
- while (true);
+
+ if (visited)
+ delete (visited);
/* Try to determine type of the outer object. */
if (TREE_CODE (base_pointer) == SSA_NAME
gcc_checking_assert (cs->indirect_info->otr_token
== tree_to_shwi (OBJ_TYPE_REF_TOKEN (target)));
- context.get_dynamic_type (instance,
- OBJ_TYPE_REF_OBJECT (target),
- obj_type_ref_class (target), call);
+ cs->indirect_info->vptr_changed
+ = !context.get_dynamic_type (instance,
+ OBJ_TYPE_REF_OBJECT (target),
+ obj_type_ref_class (target), call);
cs->indirect_info->context = context;
}
{
if (!possible_polymorphic_call_target_p (ie, cgraph_node::get_create (target)))
{
- if (!speculative)
+ if (speculative)
return NULL;
target = ipa_impossible_devirt_target (ie, target);
}
+2014-10-04 Jan Hubicka <hubicka@ucw.cz>
+
+ * g++.dg/ipa/devirt-42.C: Update template.
+ * g++.dg/ipa/devirt-44.C: Update template.
+ * g++.dg/ipa/devirt-45.C: Update template.
+ * g++.dg/ipa/devirt-46.C: Update template.
+ * g++.dg/ipa/devirt-47.C: Update template.
+ * g++.dg/ipa/devirt-48.C: New testcase.
+
2014-10-02 Mark Wielaard <mjw@redhat.com>
PR debug/63239
/* Inlining everything into main makes type clear from type of variable b.
However devirtualization is also possible for offline copy of A::barbar. Invoking
B's barbar makes it clear the type is at least B and B is an anonymous
- namespace type and therefore we know it has no derivations.
- FIXME: Currently we devirtualize speculatively only because we do not track
- dynamic type changes well. */
-/* { dg-final { scan-ipa-dump-times "First type is base of second" 1 "inline" } } */
-/* { dg-final { scan-ipa-dump-times "Outer types match, merging flags" 2 "inline" } } */
-/* { dg-final { scan-ipa-dump-times "Discovered a virtual call to a known target" 1 "inline" } } */
-/* { dg-final { scan-ipa-dump-times "Discovered a virtual call to a speculative target" 1 "inline" } } */
+ namespace type and therefore we know it has no derivations. */
+/* { dg-final { scan-ipa-dump-times "First type is base of second" 3 "inline" } } */
+/* { dg-final { scan-ipa-dump-times "Discovered a virtual call to a known target" 2 "inline" } } */
/* Verify that speculation is optimized by late optimizers. */
/* { dg-final { scan-ipa-dump-times "return 2" 2 "optimized" } } */
Check that we handle that. */
/* { dg-final { scan-ipa-dump-times "First type is base of second" 1 "inline" } } */
-/* { dg-final { scan-ipa-dump "(maybe in construction)" "inline" } } */
/* { dg-final { scan-ipa-dump-times "Discovered a virtual call to a known target\[^\\n\]*A::foo" 1 "inline" } } */
/* { dg-final { scan-ipa-dump-times "Discovered a virtual call to a known target\[^\\n\]*B::foo" 1 "inline" } } */
/* { dg-final { cleanup-ipa-dump "inline" } } */
}
/* One invocation is A::foo () other is B::foo () even though the type is destroyed and rebuilt in test() */
-/* { dg-final { scan-ipa-dump "(maybe in construction)" "inline" } } */
/* { dg-final { scan-ipa-dump-times "Discovered a virtual call to a known target\[^\\n\]*A::foo" 1 "inline" } } */
/* { dg-final { scan-ipa-dump-times "Discovered a virtual call to a known target\[^\\n\]*B::foo" 1 "inline" } } */
/* { dg-final { cleanup-ipa-dump "inline" } } */
return 0;
}
-/* { dg-final { scan-ipa-dump-times "Discovered a virtual call to a speculative target\[^\\n\]*B::foo" 1 "inline" } } */
+/* { dg-final { scan-ipa-dump-times "Discovered a virtual call to a known target\[^\\n\]*B::foo" 1 "inline" } } */
/* { dg-final { scan-ipa-dump-not "OBJ_TYPE_REF" "optimized" } } */
/* { dg-final { scan-ipa-dump-not "abort" "optimized" } } */
/* { dg-final { cleanup-ipa-dump "inline" } } */
return 0;
}
-/* { dg-final { scan-ipa-dump-times "Discovered a virtual call to a speculative target\[^\\n\]*C::_ZTh" 1 "inline" } } */
+/* { dg-final { scan-ipa-dump-times "Discovered a virtual call to a known target\[^\\n\]*C::_ZTh" 1 "inline" } } */
/* { dg-final { scan-ipa-dump-not "OBJ_TYPE_REF" "optimized" } } */
/* FIXME: We ought to inline thunk. */
/* { dg-final { scan-ipa-dump "C::_ZThn" "optimized" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O3 -fno-ipa-cp -fdump-ipa-inline-details -fno-early-inlining" } */
+struct A {
+ virtual int foo(){return 1;}
+};
+struct B:A {
+ virtual int foo(){return 2;}
+ int callfoo(){foo();}
+};
+struct C:A {
+ virtual int foo(){return 3;}
+};
+struct D:B {
+ virtual int foo(){return 4;}
+ int callfoo(){foo();}
+};
+static void
+test (struct A *a)
+{
+ if (a->foo() != 2)
+ __builtin_abort ();
+}
+int
+m()
+{
+ struct A *a = new C;
+ static_cast<B*>(a)->callfoo();
+ return 0;
+}
+
+/* { dg-final { scan-ipa-dump-times "Discovered a virtual call to a known target\[^\\n\]*__builtin_unreachable" 1 "inline" } } */
+/* { dg-final { cleanup-ipa-dump "inline" } } */