public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C11-atomic] new test: limit precomputing values across acquire barriers
@ 2012-03-23 15:47 Aldy Hernandez
  0 siblings, 0 replies; only message in thread
From: Aldy Hernandez @ 2012-03-23 15:47 UTC (permalink / raw)
  To: Andrew MacLeod, Torvald Riegel, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 420 bytes --]

This is a similar test to the previous acquire test.  Here we are 
incorrectly caching 'x' and failing to reload it after the __ATOMIC_ACQUIRE.

+  i = x + y;
+
+  if (__atomic_load_n (&flag, __ATOMIC_ACQUIRE))
+    {
+      /* x here should not be reused from above.  */
+      k = x;
+    }

Note that there is technically a data race on the load of x+y.  See the 
explanation on my previous testcase.

OK for branch?

[-- Attachment #2: curr --]
[-- Type: text/plain, Size: 1434 bytes --]

Index: testsuite/gcc.dg/simulate-thread/atomic-hoist-2.c
===================================================================
--- testsuite/gcc.dg/simulate-thread/atomic-hoist-2.c	(revision 0)
+++ testsuite/gcc.dg/simulate-thread/atomic-hoist-2.c	(revision 0)
@@ -0,0 +1,60 @@
+/* { dg-do link } */
+/* { dg-require-effective-target sync_int_long } */
+/* { dg-final { simulate-thread } } */
+
+/* Test that a load is not precomputed before an acquire.  */
+
+#include <stdio.h>
+#include "simulate-thread.h"
+
+int flag=0;
+int x = 0, y = 10, i = 0, k = -1;
+
+__attribute__((noinline))
+void simulate_thread_main()
+{
+  /* Test that the first load of x is not cached and reused in the second
+     load of x.  */
+
+  /* Note: Technically this first load of x/y is a data race.  See
+     note on atomic-hoist-1.c.  */
+  i = x + y;
+
+  if (__atomic_load_n (&flag, __ATOMIC_ACQUIRE))
+    {
+      /* x here should not be reused from above.  */
+      k = x;
+    }
+}
+
+void simulate_thread_other_threads ()
+{
+  /* Once i has been calculated in thread 1, change the value of x.  */
+  if (i != 0)
+    {
+      x = -1;
+      flag = 1;
+    }
+}
+
+int simulate_thread_step_verify ()
+{
+  return 0;
+}
+
+int simulate_thread_final_verify ()
+{
+  if (k != -1)
+    {
+      printf("FAIL: k != -1\n");
+      return 1;
+    }
+  return 0;
+}
+
+main()
+{
+  simulate_thread_main ();
+  simulate_thread_done ();
+  return 0;
+}

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

only message in thread, other threads:[~2012-03-23 15:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-23 15:47 [C11-atomic] new test: limit precomputing values across acquire barriers Aldy Hernandez

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).