[Patch] OpenMP: Add the 'scaled' modifier to the 'simdlen' clause [PR127723]

Tobias Burnus tburnus@baylibre.com
Mon Oct 5 17:11:45 GMT 2026


Tamar + Robbin: This was added to OpenMP 6.1 (release: Nov 2026) / TR14 (Nov 2025)
for aarch64 / RISC-V as they have many vector modes.
Please take care of the middle-end part + target hooks, including mangling,
once it landed

Also missing:
* Fortran
* When used with 'declare variant', I found a bug (C++-only): PR127734.
* It seems as if something should be done for the __simd__ attribute as
   well (cf. far below).

PR127723 is the tracking issue for this. Tamar pointed me to PR114635
('OpenMP reductions fail dependency analysis')  at the end of the
vectorizer BoF.

To the feature itself:
   #pragma omp declare simd
and
   #pragma omp [for] simd
     <some loop>

now have a type-dependent scaling argument (>= 1) for simdlen, namely:

    simdlen( [scaled(<type>[, divisor]) :] length )

where the scaling is MAX( 1, round-down( VL(type) / divisor ))

VL is permitted to be a runtime value and is target and type-dependent;
type is an arithmetic type - and the length + divisor are constant
integer >= 1.

[In 'omp declare variant', it can also be used with
  'match(construct={simd(simdlen(scaled(...):len))})]

* * *

Any comments, remarks, or concerns before I commit it?

* * *

BTW: In GLIBC's /usr/include/bits/math-vector.h there is:

#if defined __x86_64__ && defined __FAST_MATH__
# if defined _OPENMP && _OPENMP >= 201307
/* OpenMP case.  */
#  define __DECL_SIMD_x86_64 _Pragma ("omp declare simd notinbranch")
# elif __GNUC_PREREQ (6,0)
/* W/o OpenMP use GCC 6.* __attribute__ ((__simd__)).  */
#  define __DECL_SIMD_x86_64 __attribute__ ((__simd__ ("notinbranch")))
# endif

I think it would be useful to have something for aarch64 and RISC-V
as well, I also recall some old idea by Tamar to expend the __simd__
attribute for SVE, which might now work with 'scaled'?

Having some __simd__ variant (with GCC >= 17 check) would be nice
as most codes does not use OpenMP - and even with -fopenmp-simd,
_OPENMP is not set.
When adding a 'scaled' version to GLIBC, it would require a
GCC >= 17 check - not only for __simd__ but also for OpenMP as
it will take many years until compilers claim sufficiently full
OpenMP 6.1 support (>= 202611) to report it as such via _OPENMP.

When modifying the __simd__, recall that GLIBC also has a Fortran
header: /usr/include/finclude/math-vector-fortran.h

This is currently used as:
   !GCC$ builtin (cos) attributes simd (notinbranch) if('x86_64')
and should be then also updated.

Cheers,

Tobias

PS: For type being equal, I currently check whether the type tree
is identical (pointer comparison); that should work for any normal code,
but with typeof or some 'typedef' one might end up having trees which
differ, e.g. in the qualifier. I am not sure that's a real issue or not.

Thoughts about this?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: simdlen-scaled.diff
Type: text/x-patch
Size: 35984 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20261005/a736e38d/attachment-0001.bin>


More information about the Gcc-patches mailing list