[llvm-branch-commits] [flang] [flang] Skip processing reductions for unstructured `do concurrent` loops (PR #150188)
Kareem Ergawy via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Jul 23 01:35:35 PDT 2025
https://github.com/ergawy created https://github.com/llvm/llvm-project/pull/150188
Fixes #149563
When emitting unstructured `do concurrent` loops, reduction processing should be skipped since we are not emitting `fir.do_concurrent` loop in the first place.
>From 72e6be536d6d71d63a4db35aec85920e4e3cb882 Mon Sep 17 00:00:00 2001
From: ergawy <kareem.ergawy at amd.com>
Date: Wed, 23 Jul 2025 03:31:10 -0500
Subject: [PATCH] [flang] Skip processing reductions for unstructured `do
concurrent` loops
Fixes #149563
When emitting unstructured `do concurrent` loops, reduction processing
should be skipped since we are not emitting `fir.do_concurrent` loop in
the first place.
---
flang/lib/Lower/Bridge.cpp | 3 +++
flang/test/Lower/do_loop_unstructured.f90 | 19 +++++++++++++++++++
2 files changed, 22 insertions(+)
diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index 13420f365919d..a6362b1e2f5ca 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -2115,6 +2115,9 @@ class FirConverter : public Fortran::lower::AbstractConverter {
}
}
+ if (!doConcurrentLoopOp)
+ return;
+
llvm::SmallVector<bool> reduceVarByRef;
llvm::SmallVector<mlir::Attribute> reductionDeclSymbols;
llvm::SmallVector<mlir::Attribute> nestReduceAttrs;
diff --git a/flang/test/Lower/do_loop_unstructured.f90 b/flang/test/Lower/do_loop_unstructured.f90
index d8890b2d0926e..176ea5ccee129 100644
--- a/flang/test/Lower/do_loop_unstructured.f90
+++ b/flang/test/Lower/do_loop_unstructured.f90
@@ -232,3 +232,22 @@ subroutine nested_structured_in_unstructured()
! CHECK: cf.br ^[[HEADER]]
! CHECK: ^[[EXIT]]:
! CHECK: return
+
+subroutine unstructured_do_concurrent
+ logical :: success
+ do concurrent (i=1:10) local(success)
+ error stop "fail"
+ enddo
+end
+! CHECK-LABEL: func.func @_QPunstructured_do_concurrent
+! CHECK: %[[ITER_VAR:.*]] = fir.alloca i32
+
+! CHECK: ^[[HEADER]]:
+! CHECK: %{{.*}} = fir.load %[[ITER_VAR]] : !fir.ref<i32>
+! CHECK: cf.cond_br %{{.*}}, ^[[BODY:.*]], ^[[EXIT:.*]]
+
+! CHECK: ^[[BODY]]:
+! CHECK-NEXT: %{{.*}} = fir.alloca !fir.logical<4> {bindc_name = "success", {{.*}}}
+
+! CHECK: ^[[EXIT]]:
+! CHECK-NEXT: return
More information about the llvm-branch-commits
mailing list