]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ipa/103989 - avoid IPA inlining of small functions with -Og
authorRichard Biener <rguenther@suse.de>
Tue, 18 Jan 2022 12:48:34 +0000 (13:48 +0100)
committerRichard Biener <rguenther@suse.de>
Tue, 18 Jan 2022 14:43:04 +0000 (15:43 +0100)
The following change avoids doing IPA inlining of small functions
into functions compiled with -Og - those functions will see almost no
followup scalar cleanups so that the benefit anticipated by the
inliner will not be realized and instead the late diagnostic code
will be confused by dead code that is left around.

2022-01-18  Richard Biener  <rguenther@suse.de>

PR ipa/103989
* ipa-inline.cc (inline_small_functions): Do not enqueue call
edges originating in functions compiled with -Og.

* g++.dg/opt/pr103989.C: New testcase.

gcc/ipa-inline.cc
gcc/testsuite/g++.dg/opt/pr103989.C [new file with mode: 0644]

index 38522771118cafaa2b4dcb7645d263892448e6ee..f8bb072c4220c9852cca57bf55c1551f310392d1 100644 (file)
@@ -2029,7 +2029,12 @@ inline_small_functions (void)
       struct cgraph_edge *next = NULL;
       bool has_speculative = false;
 
-      if (!opt_for_fn (node->decl, optimize))
+      if (!opt_for_fn (node->decl, optimize)
+         /* With -Og we do not want to perform IPA inlining of small
+            functions since there are no scalar cleanups after it
+            that would realize the anticipated win.  All abstraction
+            is removed during early inlining.  */
+         || opt_for_fn (node->decl, optimize_debug))
        continue;
 
       if (dump_file)
diff --git a/gcc/testsuite/g++.dg/opt/pr103989.C b/gcc/testsuite/g++.dg/opt/pr103989.C
new file mode 100644 (file)
index 0000000..4604811
--- /dev/null
@@ -0,0 +1,30 @@
+// { dg-require-effective-target c++17 }
+// { dg-options "-Og -Wall" }
+
+#include <optional>
+#include <memory>
+
+struct A {
+  A (int a) : a {a} 
+  {}
+
+  const std::shared_ptr <int> x;
+  int a;
+};
+
+class B
+{
+public:
+  B (const std::optional <A>& a)
+    : a {a}
+  {
+  }
+public:
+  const std::optional <A> a;
+};
+
+int
+main ()
+{
+  B b {std::nullopt};
+}