From e970f59e6b20dddc4369735affb79ca9be240c1c Mon Sep 17 00:00:00 2001 From: NimishMishra <42909663+NimishMishra@users.noreply.github.com> Date: Fri, 20 Jun 2025 17:23:00 +0530 Subject: [PATCH] [flang][OpenMP] Reintroduce TODO for FIR lowering of linear clause (#144883) Current design of the linear clause lowering and translation shifts all responsibility for handling the clause (like privatisation, linear stepping, finalisation, and emission of synchronisation barriers) to the IRBuilder. However in certain corner cases (like associated loops in or before OpenMP version 4.5), variables are are implicitly linear. This currently causes a problem with the existing linear clause implementation. Hence, re-introduce TODO on the linear clause until the linear clause lowering/translation are robust enough to handle such cases as well. Fixes https://github.com/llvm/llvm-project/issues/142935 --- flang/lib/Lower/OpenMP/OpenMP.cpp | 4 +- flang/test/Lower/OpenMP/wsloop-linear.f90 | 57 ----------------------- 2 files changed, 2 insertions(+), 59 deletions(-) delete mode 100644 flang/test/Lower/OpenMP/wsloop-linear.f90 diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp index ddf58fd87444..ebd1d038716e 100644 --- a/flang/lib/Lower/OpenMP/OpenMP.cpp +++ b/flang/lib/Lower/OpenMP/OpenMP.cpp @@ -1968,13 +1968,13 @@ static void genWsloopClauses( llvm::SmallVectorImpl &reductionSyms) { ClauseProcessor cp(converter, semaCtx, clauses); cp.processNowait(clauseOps); - cp.processLinear(clauseOps); cp.processOrder(clauseOps); cp.processOrdered(clauseOps); cp.processReduction(loc, clauseOps, reductionSyms); cp.processSchedule(stmtCtx, clauseOps); - cp.processTODO(loc, llvm::omp::Directive::OMPD_do); + cp.processTODO( + loc, llvm::omp::Directive::OMPD_do); } //===----------------------------------------------------------------------===// diff --git a/flang/test/Lower/OpenMP/wsloop-linear.f90 b/flang/test/Lower/OpenMP/wsloop-linear.f90 deleted file mode 100644 index b99677108be2..000000000000 --- a/flang/test/Lower/OpenMP/wsloop-linear.f90 +++ /dev/null @@ -1,57 +0,0 @@ -! This test checks lowering of OpenMP DO Directive (Worksharing) -! with linear clause - -! RUN: %flang_fc1 -fopenmp -emit-hlfir %s -o - 2>&1 | FileCheck %s - -!CHECK: %[[X_alloca:.*]] = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFsimple_linearEx"} -!CHECK: %[[X:.*]]:2 = hlfir.declare %[[X_alloca]] {uniq_name = "_QFsimple_linearEx"} : (!fir.ref) -> (!fir.ref, !fir.ref) -!CHECK: %[[const:.*]] = arith.constant 1 : i32 -subroutine simple_linear - implicit none - integer :: x, y, i - !CHECK: omp.wsloop linear(%[[X]]#0 = %[[const]] : !fir.ref) {{.*}} - !$omp do linear(x) - !CHECK: %[[LOAD:.*]] = fir.load %[[X]]#0 : !fir.ref - !CHECK: %[[const:.*]] = arith.constant 2 : i32 - !CHECK: %[[RESULT:.*]] = arith.addi %[[LOAD]], %[[const]] : i32 - do i = 1, 10 - y = x + 2 - end do - !$omp end do -end subroutine - - -!CHECK: %[[X_alloca:.*]] = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFlinear_stepEx"} -!CHECK: %[[X:.*]]:2 = hlfir.declare %[[X_alloca]] {uniq_name = "_QFlinear_stepEx"} : (!fir.ref) -> (!fir.ref, !fir.ref) -subroutine linear_step - implicit none - integer :: x, y, i - !CHECK: %[[const:.*]] = arith.constant 4 : i32 - !CHECK: omp.wsloop linear(%[[X]]#0 = %[[const]] : !fir.ref) {{.*}} - !$omp do linear(x:4) - !CHECK: %[[LOAD:.*]] = fir.load %[[X]]#0 : !fir.ref - !CHECK: %[[const:.*]] = arith.constant 2 : i32 - !CHECK: %[[RESULT:.*]] = arith.addi %[[LOAD]], %[[const]] : i32 - do i = 1, 10 - y = x + 2 - end do - !$omp end do -end subroutine - -!CHECK: %[[A_alloca:.*]] = fir.alloca i32 {bindc_name = "a", uniq_name = "_QFlinear_exprEa"} -!CHECK: %[[A:.*]]:2 = hlfir.declare %[[A_alloca]] {uniq_name = "_QFlinear_exprEa"} : (!fir.ref) -> (!fir.ref, !fir.ref) -!CHECK: %[[X_alloca:.*]] = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFlinear_exprEx"} -!CHECK: %[[X:.*]]:2 = hlfir.declare %[[X_alloca]] {uniq_name = "_QFlinear_exprEx"} : (!fir.ref) -> (!fir.ref, !fir.ref) -subroutine linear_expr - implicit none - integer :: x, y, i, a - !CHECK: %[[LOAD_A:.*]] = fir.load %[[A]]#0 : !fir.ref - !CHECK: %[[const:.*]] = arith.constant 4 : i32 - !CHECK: %[[LINEAR_EXPR:.*]] = arith.addi %[[LOAD_A]], %[[const]] : i32 - !CHECK: omp.wsloop linear(%[[X]]#0 = %[[LINEAR_EXPR]] : !fir.ref) {{.*}} - !$omp do linear(x:a+4) - do i = 1, 10 - y = x + 2 - end do - !$omp end do -end subroutine