diff options
author | Sandra Loosemore <sandra@codesourcery.com> | 2022-11-15 03:40:12 +0000 |
---|---|---|
committer | Sandra Loosemore <sandra@codesourcery.com> | 2022-11-25 18:13:22 +0000 |
commit | 309e2d95e3b930c6f15c8a5346b913158404c76d (patch) | |
tree | 0f205d914d696e4f3c73d5fc08fcd05b5f85b3c4 /libgomp | |
parent | 3de627ffe4b51b3d82acdb5fb04c189978697832 (diff) | |
download | gcc-309e2d95e3b930c6f15c8a5346b913158404c76d.tar.gz |
OpenMP: Generate SIMD clones for functions with "declare target"
This patch causes the IPA simdclone pass to generate clones for
functions with the "omp declare target" attribute as if they had
"omp declare simd", provided the function appears to be suitable for
SIMD execution. The filter is conservative, rejecting functions
that write memory or that call other functions not known to be safe.
A new option -fopenmp-target-simd-clone is added to control this
transformation; it's enabled for offload processing at -O2 and higher.
gcc/ChangeLog:
* common.opt (fopenmp-target-simd-clone): New option.
(target_simd_clone_device): New enum to go with it.
* doc/invoke.texi (-fopenmp-target-simd-clone): Document.
* flag-types.h (enum omp_target_simd_clone_device_kind): New.
* omp-simd-clone.cc (auto_simd_fail): New function.
(auto_simd_check_stmt): New function.
(plausible_type_for_simd_clone): New function.
(ok_for_auto_simd_clone): New function.
(simd_clone_create): Add force_local argument, make the symbol
have internal linkage if it is true.
(expand_simd_clones): Also check for cloneable functions with
"omp declare target". Pass explicit_p argument to
simd_clone.compute_vecsize_and_simdlen target hook.
* opts.cc (default_options_table): Add -fopenmp-target-simd-clone.
* target.def (TARGET_SIMD_CLONE_COMPUTE_VECSIZE_AND_SIMDLEN):
Add bool explicit_p argument.
* doc/tm.texi: Regenerated.
* config/aarch64/aarch64.cc
(aarch64_simd_clone_compute_vecsize_and_simdlen): Update.
* config/gcn/gcn.cc
(gcn_simd_clone_compute_vecsize_and_simdlen): Update.
* config/i386/i386.cc
(ix86_simd_clone_compute_vecsize_and_simdlen): Update.
gcc/testsuite/ChangeLog:
* g++.dg/gomp/target-simd-clone-1.C: New.
* g++.dg/gomp/target-simd-clone-2.C: New.
* gcc.dg/gomp/target-simd-clone-1.c: New.
* gcc.dg/gomp/target-simd-clone-2.c: New.
* gcc.dg/gomp/target-simd-clone-3.c: New.
* gcc.dg/gomp/target-simd-clone-4.c: New.
* gcc.dg/gomp/target-simd-clone-5.c: New.
* gcc.dg/gomp/target-simd-clone-6.c: New.
* gcc.dg/gomp/target-simd-clone-7.c: New.
* gcc.dg/gomp/target-simd-clone-8.c: New.
* lib/scanoffloadipa.exp: New.
libgomp/ChangeLog:
* testsuite/lib/libgomp.exp: Load scanoffloadipa.exp library.
* testsuite/libgomp.c/target-simd-clone-1.c: New.
* testsuite/libgomp.c/target-simd-clone-2.c: New.
* testsuite/libgomp.c/target-simd-clone-3.c: New.
Diffstat (limited to 'libgomp')
-rw-r--r-- | libgomp/testsuite/lib/libgomp.exp | 1 | ||||
-rw-r--r-- | libgomp/testsuite/libgomp.c/target-simd-clone-1.c | 43 | ||||
-rw-r--r-- | libgomp/testsuite/libgomp.c/target-simd-clone-2.c | 39 | ||||
-rw-r--r-- | libgomp/testsuite/libgomp.c/target-simd-clone-3.c | 40 |
4 files changed, 123 insertions, 0 deletions
diff --git a/libgomp/testsuite/lib/libgomp.exp b/libgomp/testsuite/lib/libgomp.exp index 1801fdc8224..e12236e9083 100644 --- a/libgomp/testsuite/lib/libgomp.exp +++ b/libgomp/testsuite/lib/libgomp.exp @@ -32,6 +32,7 @@ load_gcc_lib scansarif.exp load_gcc_lib scantree.exp load_gcc_lib scanltranstree.exp load_gcc_lib scanoffload.exp +load_gcc_lib scanoffloadipa.exp load_gcc_lib scanoffloadtree.exp load_gcc_lib scanoffloadrtl.exp load_gcc_lib scanipa.exp diff --git a/libgomp/testsuite/libgomp.c/target-simd-clone-1.c b/libgomp/testsuite/libgomp.c/target-simd-clone-1.c new file mode 100644 index 00000000000..a9defc4cdd6 --- /dev/null +++ b/libgomp/testsuite/libgomp.c/target-simd-clone-1.c @@ -0,0 +1,43 @@ +/* { dg-do link { target { offload_target_amdgcn } } } */ +/* { dg-additional-options "-O2 -foffload-options=-fdump-ipa-simdclone-details" } */ + +/* Test that simd clones for the offload processor are generated for + functions with "declare target" when enabled by default at -O2. */ + +#pragma omp declare target +__attribute__ ((__noinline__)) int addit (int a, int b) +{ + return a + b; +} + +__attribute__ ((__noinline__)) +void callit (int *a, int *b, int *c) +{ + int i; + #pragma omp for simd + for (i = 0; i < 16; i++) + c[i] = addit (a[i], b[i]); +} +#pragma omp end declare target + +int main (void) +{ + int aa[16], bb[16], cc[16]; + int i; + for (i = 0; i < 16; i++) + { + aa[i] = i; + bb[i] = -i; + } + callit (aa, bb, cc); + for (i = 0; i < 16; i++) + if (cc[i] != 0) + return 1; + return 0; +} + +/* Although addit has external linkage, we expect clones to be generated as + for a function with internal linkage. */ + +/* { dg-final { scan-offload-ipa-dump "Generated local clone _ZGV.*N.*_addit" "simdclone" } } */ +/* { dg-final { scan-offload-ipa-dump "Generated local clone _ZGV.*M.*_addit" "simdclone" } } */ diff --git a/libgomp/testsuite/libgomp.c/target-simd-clone-2.c b/libgomp/testsuite/libgomp.c/target-simd-clone-2.c new file mode 100644 index 00000000000..05a38ae2bc5 --- /dev/null +++ b/libgomp/testsuite/libgomp.c/target-simd-clone-2.c @@ -0,0 +1,39 @@ +/* { dg-do link { target { offload_target_amdgcn } } } */ +/* { dg-additional-options "-foffload-options=-fdump-ipa-simdclone-details -foffload-options=-fno-openmp-target-simd-clone" } */ + +/* Test that simd clones for the offload processor are not generated for + functions with "declare target" when explicitly disabled. */ + +#pragma omp declare target +__attribute__ ((__noinline__)) int addit (int a, int b) +{ + return a + b; +} + +__attribute__ ((__noinline__)) +void callit (int *a, int *b, int *c) +{ + int i; + #pragma omp for simd + for (i = 0; i < 16; i++) + c[i] = addit (a[i], b[i]); +} +#pragma omp end declare target + +int main (void) +{ + int aa[16], bb[16], cc[16]; + int i; + for (i = 0; i < 16; i++) + { + aa[i] = i; + bb[i] = -i; + } + callit (aa, bb, cc); + for (i = 0; i < 16; i++) + if (cc[i] != 0) + return 1; + return 0; +} + +/* { dg-final { scan-offload-ipa-dump-not "Generated .* clone" "simdclone" } } */ diff --git a/libgomp/testsuite/libgomp.c/target-simd-clone-3.c b/libgomp/testsuite/libgomp.c/target-simd-clone-3.c new file mode 100644 index 00000000000..bde091e24ba --- /dev/null +++ b/libgomp/testsuite/libgomp.c/target-simd-clone-3.c @@ -0,0 +1,40 @@ +/* { dg-do link { target { offload_target_amdgcn } } } */ +/* { dg-additional-options "-O2 -foffload-options=-fdump-ipa-simdclone-details" } */ + +/* Test that device simd clones are not generated for functions with the host + "declare target" clause only. */ + +__attribute__ ((__noinline__)) int addit (int a, int b) +{ + return a + b; +} +#pragma omp declare target to(addit) device_type(host) + +#pragma omp declare target +void callit (int *a, int *b, int *c) +{ + int i; + #pragma omp for simd + for (i = 0; i < 16; i++) + c[i] = addit (a[i], b[i]); +} +#pragma omp end declare target + +int main (void) +{ + int aa[16], bb[16], cc[16]; + int i; + for (i = 0; i < 16; i++) + { + aa[i] = i; + bb[i] = -i; + } + callit (aa, bb, cc); + for (i = 0; i < 16; i++) + if (cc[i] != 0) + return 1; + return 0; +} + +/* { dg-final { scan-offload-ipa-dump "device doesn't match" "simdclone" { target x86_64-*-* } } } */ +/* { dg-final { scan-offload-ipa-dump-not "Generated .* clone" "simdclone" { target x86_64-*-* } } } */ |