Here is version two of my patch to fix simd attribute handling on aarch64. Unlike the first patch where I swapped the order of the calls to targetm.simd_clone.adjust and simd_clone_adjust_return_type, in this one I remove the (conditional) call to build_distinct_type_copy from simd_clone_adjust_return_type and do it unconditionally before calling either routine. The only downside to this that I can see is that on non-aarch64 platforms where the return type of a vector function is VOID (and not changed), we will create a distinct type where we did not before.
I also added some tests to ensure that, on aarch64, the vector functions created by cloning a simd function have the .variant_pcs directive and that the original non-vector version of the function does not have the directive. Without this patch the non-vector version is putting out the directive, that is what this patch fixes. Retested on x86 and aarch64 with no regressions. OK to checkin? Steve Ellcey sell...@marvell.com 2019-07-19 Steve Ellcey <sell...@marvell.com> * omp-simd-clone.c (simd_clone_adjust_return_type): Remove call to build_distinct_type_copy. (simd_clone_adjust): Call build_distinct_type_copy. (expand_simd_clones): Ditto. 2019-07-19 Steve Ellcey <sell...@marvell.com> * gcc.target/aarch64/simd_pcs_attribute.c: New test. * gcc.target/aarch64/simd_pcs_attribute-2.c: Ditto. * gcc.target/aarch64/simd_pcs_attribute-3.c: Ditto.
diff --git a/gcc/omp-simd-clone.c b/gcc/omp-simd-clone.c index caa8da3cba5..427d6f6f514 100644 --- a/gcc/omp-simd-clone.c +++ b/gcc/omp-simd-clone.c @@ -498,7 +498,6 @@ simd_clone_adjust_return_type (struct cgraph_node *node) /* Adjust the function return type. */ if (orig_rettype == void_type_node) return NULL_TREE; - TREE_TYPE (fndecl) = build_distinct_type_copy (TREE_TYPE (fndecl)); t = TREE_TYPE (TREE_TYPE (fndecl)); if (INTEGRAL_TYPE_P (t) || POINTER_TYPE_P (t)) veclen = node->simdclone->vecsize_int; @@ -1164,6 +1163,7 @@ simd_clone_adjust (struct cgraph_node *node) { push_cfun (DECL_STRUCT_FUNCTION (node->decl)); + TREE_TYPE (node->decl) = build_distinct_type_copy (TREE_TYPE (node->decl)); targetm.simd_clone.adjust (node); tree retval = simd_clone_adjust_return_type (node); @@ -1737,6 +1737,8 @@ expand_simd_clones (struct cgraph_node *node) simd_clone_adjust (n); else { + TREE_TYPE (n->decl) + = build_distinct_type_copy (TREE_TYPE (n->decl)); targetm.simd_clone.adjust (n); simd_clone_adjust_return_type (n); simd_clone_adjust_argument_types (n);
diff --git a/gcc/testsuite/gcc.target/aarch64/simd_pcs_attribute-2.c b/gcc/testsuite/gcc.target/aarch64/simd_pcs_attribute-2.c index e69de29bb2d..913960c607b 100644 --- a/gcc/testsuite/gcc.target/aarch64/simd_pcs_attribute-2.c +++ b/gcc/testsuite/gcc.target/aarch64/simd_pcs_attribute-2.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-Ofast" } */ +/* { dg-require-effective-target aarch64_variant_pcs } */ + +__attribute__ ((__simd__ ("notinbranch"))) +__attribute__ ((__nothrow__ , __leaf__ , __const__)) +extern double foo (double x); + +void bar(double * f, int n) +{ + int i; + for (i = 0; i < n; i++) + f[i] = foo(f[i]); +} + +/* { dg-final { scan-assembler-not {\.variant_pcs\tfoo} } } */ +/* { dg-final { scan-assembler-times {\.variant_pcs\t_ZGVnN2v_foo} 1 } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/simd_pcs_attribute-3.c b/gcc/testsuite/gcc.target/aarch64/simd_pcs_attribute-3.c index e69de29bb2d..e3debb0ab18 100644 --- a/gcc/testsuite/gcc.target/aarch64/simd_pcs_attribute-3.c +++ b/gcc/testsuite/gcc.target/aarch64/simd_pcs_attribute-3.c @@ -0,0 +1,25 @@ +/* { dg-do compile } */ +/* { dg-options "-Ofast" } */ +/* { dg-require-effective-target aarch64_variant_pcs } */ + +__attribute__ ((__simd__)) +__attribute__ ((__nothrow__ , __leaf__ , __const__)) +double foo (double x); + +void bar(double *f, int n) +{ + int i; + for (i = 0; i < n; i++) + f[i] = foo(f[i]); +} + +double foo(double x) +{ + return x * x / 3.0; +} + +/* { dg-final { scan-assembler-not {\.variant_pcs\tfoo} } } */ +/* { dg-final { scan-assembler-times {\.variant_pcs\t_ZGVnM1v_foo} 1 } } */ +/* { dg-final { scan-assembler-times {\.variant_pcs\t_ZGVnM2v_foo} 1 } } */ +/* { dg-final { scan-assembler-times {\.variant_pcs\t_ZGVnN1v_foo} 1 } } */ +/* { dg-final { scan-assembler-times {\.variant_pcs\t_ZGVnN2v_foo} 1 } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/simd_pcs_attribute.c b/gcc/testsuite/gcc.target/aarch64/simd_pcs_attribute.c index e69de29bb2d..17a0a701cf4 100644 --- a/gcc/testsuite/gcc.target/aarch64/simd_pcs_attribute.c +++ b/gcc/testsuite/gcc.target/aarch64/simd_pcs_attribute.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-Ofast" } */ +/* { dg-require-effective-target aarch64_variant_pcs } */ + +__attribute__ ((__simd__ ("notinbranch"))) +__attribute__ ((__nothrow__ , __leaf__ , __const__)) +extern double log (double __x); + +void foo(double *f, int n) +{ + int i; + for (i = 0; i < n; i++) + f[i] = log(f[i]); +} + +/* { dg-final { scan-assembler-not {\.variant_pcs\tlog} } } */ +/* { dg-final { scan-assembler-times {\.variant_pcs\t_ZGVnN2v_log} 1 } } */