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;
