diff mbox

[gomp4] fix simd clones with no return value

Message ID 5274F748.8060205@redhat.com
State New
Headers show

Commit Message

Aldy Hernandez Nov. 2, 2013, 12:59 p.m. UTC
> The second testcase currently ICEs I guess during simd cloning, just wanted
> to make it clear that while simd clones without any arguments probably don't
> make any sense (other than const, but those really should be hoisted out of
> the loop much earlier), simd clones with no return value make sense.

The problem here is that we are currently bailing out when there is no 
return value, thus keeping the return in the basic block which will be 
redirected elsewhere.

Fixed with the attached patch and committed to branch.

Note: I am purposely inhibiting warnings (-w) in the test to avoid 
failing with the aforementioned:

a.c:2:6: warning: AVX vector argument without AVX enabled changes the 
ABI [enabled by default]

We already have a test that fails because of this.  No sense having 
another one.  After we fix the ABI problem we can remove the -w.

Aldy
gcc/ChangeLog.gomp

	* omp-low.c (ipa_simd_modify_function_body): Handle empty returns.
diff mbox

Patch

diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index 7852723..d30fb17 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -11098,17 +11098,23 @@  ipa_simd_modify_function_body (struct cgraph_node *node,
 	    {
 	    case GIMPLE_RETURN:
 	      {
-		/* Replace `return foo' by `retval_array[iter] = foo'.  */
 		tree old_retval = gimple_return_retval (stmt);
-		if (!old_retval)
-		  break;
-		stmt = gimple_build_assign (build4 (ARRAY_REF,
-						    TREE_TYPE (old_retval),
-						    retval_array, iter,
-						    NULL, NULL),
-					    old_retval);
-		gsi_replace (&gsi, stmt, true);
-		modified = true;
+		if (old_retval)
+		  {
+		    /* Replace `return foo' by `retval_array[iter] = foo'.  */
+		    stmt = gimple_build_assign (build4 (ARRAY_REF,
+							TREE_TYPE (old_retval),
+							retval_array, iter,
+							NULL, NULL),
+						old_retval);
+		    gsi_replace (&gsi, stmt, true);
+		    modified = true;
+		  }
+		else
+		  {
+		    gsi_remove (&gsi, true);
+		    continue;
+		  }
 		break;
 	      }
 
diff --git a/gcc/testsuite/gcc.dg/gomp/simd-clones-5.c b/gcc/testsuite/gcc.dg/gomp/simd-clones-5.c
new file mode 100644
index 0000000..801c24f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/gomp/simd-clones-5.c
@@ -0,0 +1,12 @@ 
+/* { dg-do compile { target i?86-*-* x86_64-*-* } } */
+/* { dg-options "-fopenmp -w" } */
+
+/* ?? The -w above is to inhibit the following warning for now:
+   a.c:2:6: warning: AVX vector argument without AVX enabled changes
+   the ABI [enabled by default].  */
+
+#pragma omp declare simd notinbranch simdlen(4)
+void foo (int *a)
+{
+  *a = 555;
+}