[flang-commits] [flang] [flang][acc] remap no_create array sections (PR #178660)
via flang-commits
flang-commits at lists.llvm.org
Thu Jan 29 05:59:27 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-fir-hlfir
Author: None (jeanPerier)
<details>
<summary>Changes</summary>
The workaround for no_create with array section is not needed anymore because it has been expected that it would be up to the runtime to make sure fir.box for the variable are always readable on the device even when the variable is not present.
---
Full diff: https://github.com/llvm/llvm-project/pull/178660.diff
2 Files Affected:
- (modified) flang/lib/Lower/OpenACC.cpp (+1-8)
- (added) flang/test/Lower/OpenACC/acc-no-create-array-section.f90 (+21)
``````````diff
diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp
index 183f9e717532a..133cc973897af 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -775,16 +775,9 @@ genDataOperandOperations(const Fortran::parser::AccObjectList &objectList,
if (auto *defOp = op.getVar().getDefiningOp())
addDeclareAttr(builder, defOp, dataClause);
- // TODO: no_create remapping could currently cause segfaults because of the
- // fir.box_addr that may be inserted in the remapping in the region.
- // This is an issue if the variable is not mapped (which is OK if its
- // accesses are not reached inside the construct).
- bool isNoCreateWithBounds =
- std::is_same_v<Op, mlir::acc::NoCreateOp> && !bounds.empty();
-
// Track the symbol and its corresponding mlir::Value if requested so that
// accesses inside regions can be remapped.
- if (dataMap && !isNoCreateWithBounds) {
+ if (dataMap) {
if (componentRef)
dataMap->emplaceComponent(op.getAccVar(), std::move(*componentRef),
baseAddr);
diff --git a/flang/test/Lower/OpenACC/acc-no-create-array-section.f90 b/flang/test/Lower/OpenACC/acc-no-create-array-section.f90
new file mode 100644
index 0000000000000..3097eccc8cbee
--- /dev/null
+++ b/flang/test/Lower/OpenACC/acc-no-create-array-section.f90
@@ -0,0 +1,21 @@
+! This test checks lowering of OpenACC no_create with an array section.
+
+! RUN: bbc -fopenacc -emit-hlfir %s -o - | FileCheck %s
+
+subroutine foo(n)
+ real :: a(n)
+ !$acc parallel no_create(a(11:20))
+ call bar(a)
+ !$acc end parallel
+end subroutine
+! CHECK-LABEL: func.func @_QPfoo(
+! CHECK: %[[SHAPE_0:.*]] = fir.shape
+! CHECK: %[[BOUNDS_0:.*]] = acc.bounds
+! CHECK: %[[NOCREATE_0:.*]] = acc.nocreate var(%{{.*}} : !fir.box<!fir.array<?xf32>>) bounds(%[[BOUNDS_0]]) -> !fir.box<!fir.array<?xf32>> {name = "a(11:20)"}
+! CHECK: acc.parallel dataOperands(%[[NOCREATE_0]] : !fir.box<!fir.array<?xf32>>) {
+! CHECK: %[[BOX_ADDR_0:.*]] = fir.box_addr %[[NOCREATE_0]] : (!fir.box<!fir.array<?xf32>>) -> !fir.ref<!fir.array<?xf32>>
+! CHECK: %[[DECLARE_2:.*]]:2 = hlfir.declare %[[BOX_ADDR_0]](%[[SHAPE_0]]) {uniq_name = "_QFfooEa"} : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>) -> (!fir.box<!fir.array<?xf32>>, !fir.ref<!fir.array<?xf32>>)
+! CHECK: fir.call @_QPbar(%[[DECLARE_2]]#1) fastmath<contract> : (!fir.ref<!fir.array<?xf32>>) -> ()
+! CHECK: acc.yield
+! CHECK: }
+! CHECK: acc.delete accVar(%[[NOCREATE_0]] : !fir.box<!fir.array<?xf32>>) bounds(%[[BOUNDS_0]]) {dataClause = #acc<data_clause acc_no_create>, name = "a(11:20)"}
``````````
</details>
https://github.com/llvm/llvm-project/pull/178660
More information about the flang-commits
mailing list