From 3bc8b58d59c2ef195a290456ee4b3bbf32794dda Mon Sep 17 00:00:00 2001 From: Dominik Adamski Date: Tue, 23 Jan 2024 15:10:01 -0600 Subject: [PATCH] [Flang][OpenMP] Use simdloop operation only for omp simd pragma 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. --- flang/lib/Lower/OpenMP.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp index 2019b5631a46b..1684c4a8a01ac 100644 --- a/flang/lib/Lower/OpenMP.cpp +++ b/flang/lib/Lower/OpenMP.cpp @@ -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 {