diff mbox

PR62091 (ipa-devirt disagreeing with ipa-prop)

Message ID 20140814233913.GA18133@kam.mff.cuni.cz
State New
Headers show

Commit Message

Jan Hubicka Aug. 14, 2014, 11:39 p.m. UTC
Hi,
testcase in PR 62092 triggers assert I added to temporarily check that new
ipa-devirt code handles all cases as ipa-prop devirtualization.  In this case
ipa-prop gives wrong answer because of bug I introduced into
walk_aliased_vdefs.  The function_entry_reached is supposed to be cleared at
begginign of walk_aliased_vdefs instead of walk_aliased_vdefs_1.  It seems I
have misapplied a patch here.

THere is one extra issue I noticed while looking into dump - the ctor detection
code did not handled static storage vars correctly.

Bootstrapped/regtested x86_64-linux.  With this patch the testcase passes
but it is not devirtualized, becuase we think we can not reffer the function.

We ought to devirtualize because the funcion is empty and should be inlined -
I would like to keep the PR open for that.

Honza

	PR tree-optimization/62091
	* g++.dg/ipa/devirt-38.C: New testcase.
	* tree-ssa-alias.c (walk_aliased_vdefs_1): Do not clear
	function_entry_reached.
	(walk_aliased_vdefs): Clear it here.
	* ipa-devirt.c (check_stmt_for_type_change): Handle static storage.
diff mbox

Patch

Index: testsuite/g++.dg/ipa/devirt-38.C
===================================================================
--- testsuite/g++.dg/ipa/devirt-38.C	(revision 0)
+++ testsuite/g++.dg/ipa/devirt-38.C	(revision 0)
@@ -0,0 +1,30 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2"  } */
+class SnmpSyntax
+{
+public:
+  virtual SnmpSyntax *m_fn1 () const;
+  ~SnmpSyntax () {}
+  virtual SnmpSyntax &operator=(const SnmpSyntax &);
+};
+
+class A : public SnmpSyntax
+{
+public:
+  A (int);
+  SnmpSyntax *m_fn1 () const {}
+  SnmpSyntax &operator=(const SnmpSyntax &);
+};
+int a;
+void fn1 ()
+{
+  for (;; a++)
+    switch (0)
+    case 0:
+      {
+        A b (0);
+        SnmpSyntax &c = b;
+        c.m_fn1 ();
+      }
+}
+// Devirtualization to A::m_fn1 would be possible, but we can not do it at the moment
Index: tree-ssa-alias.c
===================================================================
--- tree-ssa-alias.c	(revision 213989)
+++ tree-ssa-alias.c	(working copy)
@@ -2658,8 +2658,6 @@  walk_aliased_vdefs_1 (ao_ref *ref, tree
 		      bitmap *visited, unsigned int cnt,
 		      bool *function_entry_reached)
 {
-  if (function_entry_reached)
-    *function_entry_reached = false;
   do
     {
       gimple def_stmt = SSA_NAME_DEF_STMT (vdef);
@@ -2709,6 +2707,9 @@  walk_aliased_vdefs (ao_ref *ref, tree vd
 
   timevar_push (TV_ALIAS_STMT_WALK);
 
+  if (function_entry_reached)
+    *function_entry_reached = false;
+
   ret = walk_aliased_vdefs_1 (ref, vdef, walker, data,
 			      visited ? visited : &local_visited, 0,
 			      function_entry_reached);
Index: ipa-devirt.c
===================================================================
--- ipa-devirt.c	(revision 213990)
+++ ipa-devirt.c	(working copy)
@@ -2777,6 +2777,8 @@  check_stmt_for_type_change (ao_ref *ao A
 			  * BITS_PER_UNIT;
 		op = TREE_OPERAND (op, 0);
 	      }
+	    else if (DECL_P (op))
+	      ;
 	    else
 	      {
                 tci->speculative = true;