inline: do not einline when no_profile_instrument_function is different
authorMartin Liska <mliska@suse.cz>
Tue, 22 Jun 2021 08:09:01 +0000 (10:09 +0200)
committerMartin Liska <mliska@suse.cz>
Tue, 7 Sep 2021 09:47:57 +0000 (11:47 +0200)
PR gcov-profile/80223

gcc/ChangeLog:

* ipa-inline.c (can_inline_edge_p): Similarly to sanitizer
options, do not inline when no_profile_instrument_function
attributes are different in early inliner. It's fine to inline
it after PGO instrumentation.

gcc/testsuite/ChangeLog:

* gcc.dg/no_profile_instrument_function-attr-2.c: New test.

gcc/ipa-inline.c
gcc/testsuite/gcc.dg/no_profile_instrument_function-attr-2.c [new file with mode: 0644]

index 413446b..012b326 100644 (file)
@@ -396,6 +396,23 @@ can_inline_edge_p (struct cgraph_edge *e, bool report,
       e->inline_failed = CIF_SANITIZE_ATTRIBUTE_MISMATCH;
       inlinable = false;
     }
+  else if (profile_arc_flag
+          && (lookup_attribute ("no_profile_instrument_function",
+                                DECL_ATTRIBUTES (caller->decl)) == NULL_TREE)
+          != (lookup_attribute ("no_profile_instrument_function",
+                                DECL_ATTRIBUTES (callee->decl)) == NULL_TREE))
+    {
+      cgraph_node *origin = caller;
+      while (origin->clone_of)
+       origin = origin->clone_of;
+
+      if (!DECL_STRUCT_FUNCTION (origin->decl)->always_inline_functions_inlined)
+       {
+         e->inline_failed = CIF_UNSPECIFIED;
+         inlinable = false;
+       }
+    }
+
   if (!inlinable && report)
     report_inline_failed_reason (e);
   return inlinable;
diff --git a/gcc/testsuite/gcc.dg/no_profile_instrument_function-attr-2.c b/gcc/testsuite/gcc.dg/no_profile_instrument_function-attr-2.c
new file mode 100644 (file)
index 0000000..472eca8
--- /dev/null
@@ -0,0 +1,15 @@
+/* { dg-require-effective-target global_constructor } */
+/* { dg-options "-O2 -fprofile-generate -fprofile-update=single -fdump-tree-optimized" } */
+
+__attribute__ ((no_profile_instrument_function))
+int foo()
+{
+  return 0;
+}
+
+int bar()
+{
+  return foo();
+}
+
+/* { dg-final { scan-tree-dump-not" = foo \\(\\)" "optimized"} } */