Here we inline a transaction_pure function into a non transaction_pure
function, but end up instrumenting all the memory operations in the
tm_pure function regardless.
As discussed in the PR, we should've disallowed inlining of TM_pure
functions into non TM_pure functions. We are currently only disabling a
subset of this, tm_safe callers. The patch below disallows all inlining
of TM_pure functions into non TM_pure functions.
No regressions.
OK? (I'm not sure whether the "looks good" was because I'm handsome, or
because it was an actual approval).
PR middle-end/52142
* ipa-inline.c (can_inline_edge_p): Do not inline tm_pure
functions into non-tm_pure functions.
Index: testsuite/gcc.dg/tm/pr52142.c
===================================================================
--- testsuite/gcc.dg/tm/pr52142.c (revision 0)
+++ testsuite/gcc.dg/tm/pr52142.c (revision 0)
@@ -0,0 +1,22 @@
+/* { dg-do compile } */
+/* { dg-options "-fgnu-tm -O1" } */
+static int global = 0;
+
+__attribute__((transaction_pure))
+static inline void purefunc()
+{
+ global++;
+}
+
+__attribute__((transaction_safe))
+void f();
+
+void push()
+{
+ __transaction_atomic {
+ f();
+ purefunc();
+ }
+}
+
+/* { dg-final { scan-assembler-not "_ITM_RfWU4" } } */
Index: ipa-inline.c
===================================================================
--- ipa-inline.c (revision 184181)
+++ ipa-inline.c (working copy)
@@ -284,10 +284,10 @@ can_inline_edge_p (struct cgraph_edge *e
e->inline_failed = CIF_EH_PERSONALITY;
inlinable = false;
}
- /* TM pure functions should not get inlined if the outer function is
- a TM safe function. */
+ /* TM pure functions should not be inlined into non-TM_pure
+ functions. */
else if (is_tm_pure (callee->decl)
- && is_tm_safe (e->caller->decl))
+ && !is_tm_pure (e->caller->decl))
{
e->inline_failed = CIF_UNSPECIFIED;
inlinable = false;