Skip to content

Commit

Permalink
[Flang][OpenMP] Use simdloop operation only for omp simd pragma
Browse files Browse the repository at this point in the history
OpenMP standard differentiates between omp simd (2.9.3.1) and
omp do/for simd (2.9.3.2 for OpenMP 5.0 standard) pragmas.
The first one describes the loop which needs to be vectorized.
The second pragma describes the loop which needs to be workshared
between existing threads. Each thread can use SIMD instructions
to execute its chunk of the loop.

That's why we need to model
!$omp simd
  do-loop
as omp.simdloop operation and add compiler hints for vectorization.

The worksharing loop:
!$omp do simd
  do-loop
should be represented as worksharing loop.

Currently Flang denotes both type of OpenMP pragmas by omp.simdloop
operation. In consequence we cannot differentiate between:
!$omp parallel simd
   do-loop
and
!$omp parallel do simd
   do-loop
The second loop should be workshared between multiple threads.
The first one describes the loop which needs to be redundantly
executed by multiple threads. Current Flang implementation
does not perform worksharing for `!$omp do simd` pragma and
generates valid code only for first case.
  • Loading branch information
DominikAdamski committed Jan 25, 2024
1 parent 6f25158 commit 3bc8b58
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion flang/lib/Lower/OpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3789,7 +3789,16 @@ static void genOMP(Fortran::lower::AbstractConverter &converter,
}

// 2.9.3.1 SIMD construct
if (llvm::omp::allSimdSet.test(ompDirective)) {
// Process simd loop:
// !$ omp simd
// do-loop
// Worksharing loops like:
// !$ omp do simd
// do-loop
// should be processed as other worksharing loops
// and they should be represented by omp.wsloop operation
if ((llvm::omp::OMPD_simd == ompDirective) ||
(llvm::omp::OMPD_target_simd == ompDirective)) {
createSimdLoop(converter, eval, ompDirective, loopOpClauseList,
currentLocation);
} else {
Expand Down

0 comments on commit 3bc8b58

Please sign in to comment.