This patch tests various shared clauses with SVE types. It also adds a test scaffold to run OpenMP tests in under the gcc.target testsuite.
gcc/testsuite/ChangeLog: * gcc.target/aarch64/sve/omp/aarch64-sve-omp.exp: New scaffold. * gcc/testsuite/gcc.target/aarch64/sve/omp/shared.c: New test. --- .../aarch64/sve/omp/aarch64-sve-omp.exp | 80 ++++++++ .../gcc.target/aarch64/sve/omp/shared.c | 186 ++++++++++++++++++ 2 files changed, 266 insertions(+) create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/omp/aarch64-sve-omp.exp create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/omp/shared.c diff --git a/gcc/testsuite/gcc.target/aarch64/sve/omp/aarch64-sve-omp.exp b/gcc/testsuite/gcc.target/aarch64/sve/omp/aarch64-sve-omp.exp new file mode 100644 index 00000000000..1997c80c334 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/omp/aarch64-sve-omp.exp @@ -0,0 +1,80 @@ +# Copyright (C) 2006-2024 Free Software Foundation, Inc. +# +# This file is part of GCC. +# +# GCC is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GCC is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GCC; see the file COPYING3. If not see +# <http://www.gnu.org/licenses/>. + +# GCC testsuite that uses the `dg.exp' driver. + +# Exit immediately if this isn't an AArch64 target. +if {![istarget aarch64*-*-*] } then { + return +} + +# Load support procs. +load_lib gcc-dg.exp + +# Initialize `dg'. +dg-init + +if ![check_effective_target_fopenmp] { + return +} + +proc omp_link_flags { } { + global ld_library_path + global TOOL_OPTIONS + + set flags "" + + if ![is_remote host] { + if [info exists TOOL_OPTIONS] { + set gccpath "[get_multilibs ${TOOL_OPTIONS}]" + } else { + set gccpath "[get_multilibs]" + } + } + + if { $gccpath != "" } { + if [file exists "${gccpath}/libgomp/libgomp.spec"] { + append flags "-B${gccpath}/libgomp/ -L${gccpath}/libgomp/.libs -I${gccpath}/libgomp/" + append ld_library_path ":${gccpath}/libgomp/.libs" + } + } else { + global tool_root_dir + + set libgomp [lookfor_file ${tool_root_dir} libgomp] + if { $libgomp != "" } { + append flags "-L${libgomp} -B${libgomp}" + append ld_library_path ":${libgomp}" + } + } + + set_ld_library_path_env_vars + + return "$flags" +} + +if { [check_effective_target_aarch64_sve] } { + set sve_flags "" +} else { + set sve_flags "-march=armv8.2-a+sve" +} + +# Main loop. +dg-runtest [lsort [find $srcdir/$subdir *.c]] "[omp_link_flags] $sve_flags -fopenmp" "" + +# All done. +dg-finish diff --git a/gcc/testsuite/gcc.target/aarch64/sve/omp/shared.c b/gcc/testsuite/gcc.target/aarch64/sve/omp/shared.c new file mode 100644 index 00000000000..3f380d95da4 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/omp/shared.c @@ -0,0 +1,186 @@ +/* { dg-do run { target aarch64_sve256_hw } } */ +/* { dg-options "-msve-vector-bits=256 -std=gnu99 -fopenmp -O2 -fdump-tree-ompexp" } */ + +#include <arm_sve.h> +#include <stdint.h> +#include <stdlib.h> +#include <stdbool.h> + +svint32_t +__attribute__ ((noinline)) +explicit_shared (svint32_t a, svint32_t b, svbool_t p) +{ + +#pragma omp parallel shared (a, b, p) num_threads (1) + { + /* 'a', 'b' and 'p' are explicitly shared. */ + a = svadd_s32_z (p, a, b); + } + +#pragma omp parallel shared (a, b, p) num_threads (1) + { + a = svadd_s32_z (p, a, b); + } + + return a; +} + +svint32_t +__attribute__ ((noinline)) +implicit_shared_default (svint32_t a, svint32_t b, svbool_t p) +{ + +#pragma omp parallel default (shared) num_threads (1) + { + /* 'a', 'b' and 'p' are implicitly shared. */ + a = svadd_s32_z (p, a, b); + } + +#pragma omp parallel default (shared) num_threads (1) + { + a = svadd_s32_z (p, a, b); + } + + return a; +} + +svint32_t +__attribute__ ((noinline)) +implicit_shared_no_default (svint32_t a, svint32_t b, svbool_t p) +{ + +#pragma omp parallel num_threads (1) + { + /* 'a', 'b' and 'p' are implicitly shared without default clause. */ + a = svadd_s32_z (p, a, b); + } + +#pragma omp parallel num_threads (1) + { + a = svadd_s32_z (p, a, b); + } + + return a; +} + +svint32_t +__attribute__ ((noinline)) +mix_shared (svint32_t b, svbool_t p) +{ + + svint32_t a; + int32_t *m = (int32_t *)malloc (8 * sizeof (int32_t)); + int i; + +#pragma omp parallel for + for (i = 0; i < 8; i++) + m[i] = i; + +#pragma omp parallel + { + /* 'm' is predetermined shared here. 'a' is implicitly shared here. */ + a = svld1_s32 (svptrue_b32 (), m); + } + +#pragma omp parallel num_threads (1) + { + /* 'a', 'b' and 'p' are implicitly shared here. */ + a = svadd_s32_z (p, a, b); + } + +#pragma omp parallel shared (a, b, p) num_threads (1) + { + /* 'a', 'b' and 'p' are explicitly shared here. */ + a = svadd_s32_z (p, a, b); + } + + return a; +} + +void +__attribute__ ((noinline)) +predetermined_shared_static (bool x) +{ + + int32_t *m = (int32_t *)malloc (8 * sizeof (int32_t)); + int i; + +#pragma omp parallel for + /* 'm' is predetermined shared here. */ + for (i = 0; i < 8; i++) + { + m[i] = i; + } + +#pragma omp parallel + { + /* 'a' is predetermined shared here. */ + static int64_t n; + svint32_t a; + #pragma omp parallel + { + /* 'n' is predetermined shared here. */ + if (x) + { + a = svld1_s32 (svptrue_b32 (), m); + n = svaddv_s32 (svptrue_b32 (), a); + } + if (!x && n != 28) + __builtin_abort (); + } + } +} + +svint32_t +__attribute__ ((noinline)) +foo (svint32_t a, svint32_t b, svbool_t p) +{ + a = svadd_s32_z (p, a, b); + a = svadd_s32_z (p, a, b); + return a; +} + +void compare_vec (svint32_t x, svint32_t y) +{ + svbool_t p = svnot_b_z (svptrue_b32 (), svcmpeq_s32 (svptrue_b32 (), x, y)); + + if (svptest_any (svptrue_b32 (), p)) + __builtin_abort (); +} + +int +main () +{ + svint32_t x = svindex_s32 (0 ,1); + svint32_t y = svindex_s32 (8, 1); + svint32_t a, b; + svbool_t p; + + /* Implicit shared. */ + a = foo (x, y, p); + b = implicit_shared_default (x, y, p); + compare_vec (a, b); + + /* Explicit shared. */ + a = foo (x ,y, p); + b = explicit_shared (x, y, p); + compare_vec (a, b); + + /* Implicit shared with no default clause. */ + a = foo (x ,y, p); + b = implicit_shared_no_default (x, y, p); + compare_vec (a, b); + + /* Mix shared. */ + a = foo (x ,y, p); + b = mix_shared (y, p); + compare_vec (a, b); + + /* Predetermined shared. */ + predetermined_shared_static (true); + predetermined_shared_static (false); + + return 0; +} + +/* { dg-final { scan-tree-dump-times "value-expr: \*.omp_data_i->a" 10 "ompexp" } } */ -- 2.25.1