public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [gomp] Fix !$omp atomic (PR fortran/34020)
@ 2007-11-09 11:49 Jakub Jelinek
  2007-11-09 14:59 ` Diego Novillo
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2007-11-09 11:49 UTC (permalink / raw)
  To: Richard Henderson, Diego Novillo; +Cc: gcc-patches

Hi!

On the following testcase lhsaddr is
(real4 *) lhs
where lhs has real4 & type.  But unshare_body unshares the NOP_EXPR,
so in goa_lhs_expr_p the NOP_EXPR addresses aren't equal anymore, which
means that the read from *lhs is done before the loop and so is the floating
point addition, which means the operation is no longer atomic.

Fixed by going through any nops.  Tested on x86_64-linux.

Ok for trunk/4.2/4.1?

2007-11-09  Jakub Jelinek  <jakub@redhat.com>

	PR fortran/34020
	* gimplify.c (goa_lhs_expr_p): Inside INDIRECT_REF handle unshared
	nops.

	* testsuite/libgomp.fortran/pr34020.f90: New test.

--- gcc/gimplify.c.jj	2007-11-08 22:50:35.000000000 +0100
+++ gcc/gimplify.c	2007-11-09 08:48:25.000000000 +0100
@@ -5291,8 +5291,22 @@ goa_lhs_expr_p (tree expr, tree addr)
              == TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (expr, 0)))))
     expr = TREE_OPERAND (expr, 0);
 
-  if (TREE_CODE (expr) == INDIRECT_REF && TREE_OPERAND (expr, 0) == addr)
-    return true;
+  if (TREE_CODE (expr) == INDIRECT_REF)
+    {
+      expr = TREE_OPERAND (expr, 0);
+      while (expr != addr
+	     && (TREE_CODE (expr) == NOP_EXPR
+		 || TREE_CODE (expr) == CONVERT_EXPR
+		 || TREE_CODE (expr) == NON_LVALUE_EXPR)
+	     && TREE_CODE (expr) == TREE_CODE (addr)
+	     && TYPE_MAIN_VARIANT (TREE_TYPE (expr))
+		== TYPE_MAIN_VARIANT (TREE_TYPE (addr)))
+	{
+	  expr = TREE_OPERAND (expr, 0);
+	  addr = TREE_OPERAND (addr, 0);
+	}
+      return expr == addr;
+    }
   if (TREE_CODE (addr) == ADDR_EXPR && expr == TREE_OPERAND (addr, 0))
     return true;
   return false;
--- libgomp/testsuite/libgomp.fortran/pr34020.f90.jj	2007-11-09 08:56:44.000000000 +0100
+++ libgomp/testsuite/libgomp.fortran/pr34020.f90	2007-11-09 08:56:29.000000000 +0100
@@ -0,0 +1,19 @@
+! PR fortran/34020
+! { dg-do run }
+
+      subroutine atomic_add(lhs, rhs)
+      real lhs, rhs
+!$omp atomic
+      lhs = rhs + lhs
+      end
+
+      real lhs, rhs
+      integer i
+      lhs = 0
+      rhs = 1
+!$omp parallel do num_threads(8) shared(lhs, rhs)
+      do i = 1, 300000
+        call atomic_add(lhs, rhs)
+      enddo
+      if (lhs .ne. 300000) call abort
+      end

	Jakub

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [gomp] Fix !$omp atomic (PR fortran/34020)
  2007-11-09 11:49 [gomp] Fix !$omp atomic (PR fortran/34020) Jakub Jelinek
@ 2007-11-09 14:59 ` Diego Novillo
  0 siblings, 0 replies; 2+ messages in thread
From: Diego Novillo @ 2007-11-09 14:59 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Richard Henderson, gcc-patches

On 11/9/07, Jakub Jelinek <jakub@redhat.com> wrote:

> 2007-11-09  Jakub Jelinek  <jakub@redhat.com>
>
>         PR fortran/34020
>         * gimplify.c (goa_lhs_expr_p): Inside INDIRECT_REF handle unshared
>         nops.
>
>         * testsuite/libgomp.fortran/pr34020.f90: New test.

OK.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-11-09 14:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-09 11:49 [gomp] Fix !$omp atomic (PR fortran/34020) Jakub Jelinek
2007-11-09 14:59 ` Diego Novillo

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