public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-6849] tree-optimization/106912 - clear const attribute from fntype
@ 2023-03-24 12:53 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2023-03-24 12:53 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:ed626f18b189920aeed9974aded3f9cb6f25b543

commit r13-6849-ged626f18b189920aeed9974aded3f9cb6f25b543
Author: Richard Biener <rguenther@suse.de>
Date:   Thu Mar 16 13:51:19 2023 +0100

    tree-optimization/106912 - clear const attribute from fntype
    
    The following makes sure that after clearing pure/const from
    instrumented function declarations we are adjusting call statements
    fntype as well to handle indirect calls and because gimple_call_flags
    looks at both decl and fntype.
    
    Like the pure/const flag clearing on decls we refrain from touching
    calls to known functions that do not have a body in the current TU.
    
            PR tree-optimization/106912
            * tree-profile.cc (tree_profiling): Update stmts only when
            profiling or testing coverage.  Make sure to update calls
            fntype, stripping 'const' there.
    
            * gcc.dg/profile-generate-4.c: New testcase.

Diff:
---
 gcc/testsuite/gcc.dg/profile-generate-4.c | 19 +++++++++++++++
 gcc/tree-profile.cc                       | 40 +++++++++++++++++++++++--------
 2 files changed, 49 insertions(+), 10 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/profile-generate-4.c b/gcc/testsuite/gcc.dg/profile-generate-4.c
new file mode 100644
index 00000000000..c2b999fe4cb
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/profile-generate-4.c
@@ -0,0 +1,19 @@
+/* PR106912 */
+/* { dg-require-profiling "-fprofile-generate" } */
+/* { dg-options "-O2 -fprofile-generate -ftree-vectorize" } */
+
+__attribute__ ((__simd__))
+__attribute__ ((__nothrow__ , __leaf__ , __const__, __noinline__))
+double foo (double x);
+
+void bar(double *f, int n)
+{
+  int i;
+  for (i = 0; i < n; i++)
+    f[i] = foo(f[i]);
+}
+
+double foo(double x)
+{
+  return x * x / 3.0;
+}
diff --git a/gcc/tree-profile.cc b/gcc/tree-profile.cc
index ea9d7a23443..6f9a43e4bd5 100644
--- a/gcc/tree-profile.cc
+++ b/gcc/tree-profile.cc
@@ -835,16 +835,36 @@ tree_profiling (void)
 
       push_cfun (DECL_STRUCT_FUNCTION (node->decl));
 
-      FOR_EACH_BB_FN (bb, cfun)
-	{
-	  gimple_stmt_iterator gsi;
-	  for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
-	    {
-	      gimple *stmt = gsi_stmt (gsi);
-	      if (is_gimple_call (stmt))
-		update_stmt (stmt);
-	    }
-	}
+      if (profile_arc_flag || flag_test_coverage)
+	FOR_EACH_BB_FN (bb, cfun)
+	  {
+	    gimple_stmt_iterator gsi;
+	    for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
+	      {
+		gcall *call = dyn_cast <gcall *> (gsi_stmt (gsi));
+		if (!call)
+		  continue;
+
+		/* We do not clear pure/const on decls without body.  */
+		tree fndecl = gimple_call_fndecl (call);
+		if (fndecl && !gimple_has_body_p (fndecl))
+		  continue;
+
+		/* Drop the const attribute from the call type (the pure
+		   attribute is not available on types).  */
+		tree fntype = gimple_call_fntype (call);
+		if (fntype && TYPE_READONLY (fntype))
+		  {
+		    int quals = TYPE_QUALS (fntype) & ~TYPE_QUAL_CONST;
+		    fntype = build_qualified_type (fntype, quals);
+		    gimple_call_set_fntype (call, fntype);
+		  }
+
+		/* Update virtual operands of calls to no longer const/pure
+		   functions.  */
+		update_stmt (call);
+	      }
+	  }
 
       /* re-merge split blocks.  */
       cleanup_tree_cfg ();

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-03-24 12:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-24 12:53 [gcc r13-6849] tree-optimization/106912 - clear const attribute from fntype Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).