[flang-commits] [flang] [mlir] [flang][OpenMP] Lower target in_reduction for host fallback (PR #199967)

Sergio Afonso via flang-commits flang-commits at lists.llvm.org
Wed Jun 24 05:15:34 PDT 2026


================
@@ -0,0 +1,30 @@
+! RUN: bbc -emit-hlfir -fopenmp -fopenmp-version=50 -o - %s 2>&1 | FileCheck %s
+! RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=50 -o - %s 2>&1 | FileCheck %s
+
+! An in_reduction list item that is a member of an explicitly mapped common
+! block must still get its own address-preserving (ByRef + implicit tofrom) map
+! entry, separate from the common-block map. Otherwise the in_reduction operand
+! would have no matching map_entries entry for the host-fallback redirect.
+! Verify that the common block and the member are mapped independently and that
+! the in_reduction clause references the member.
+
+!CHECK-LABEL: func.func @_QPomp_target_in_reduction_common()
+!CHECK:       %[[CB:.*]] = fir.address_of(@cb_) : !fir.ref<!fir.array<8xi8>>
+!CHECK:       %[[IDECL:.*]]:2 = hlfir.declare %{{.*}} storage(%[[CB]][0]) {uniq_name = "_QFomp_target_in_reduction_commonEi"}
+! The whole common block is mapped by the explicit map clause.
+!CHECK:       %[[CBMAP:.*]] = omp.map.info var_ptr(%[[CB]] : !fir.ref<!fir.array<8xi8>>, !fir.array<8xi8>) map_clauses(tofrom) capture(ByRef) -> {{.*}} {name = "cb"}
+! The in_reduction member additionally gets its own implicit ByRef map.
+!CHECK:       %[[IMAP:.*]] = omp.map.info var_ptr(%[[IDECL]]#1 : !fir.ref<i32>, i32) map_clauses(implicit, tofrom) capture(ByRef) -> !fir.ref<i32> {name = "i"}
+!CHECK:       omp.target in_reduction(@{{.*}} %[[IDECL]]#0 : !fir.ref<i32>)
+!CHECK-SAME:    map_entries(%[[CBMAP]] -> %{{[^ ]+}}, %[[IMAP]] -> %[[IARG:[^ ]+]] : !fir.ref<!fir.array<8xi8>>, !fir.ref<i32>)
+!CHECK:         hlfir.declare %[[IARG]]
----------------
skatrak wrote:

Add CHECK(s) to make sure the `store` instruction is to `IARG` (through `hlfir.declare`).

https://github.com/llvm/llvm-project/pull/199967


More information about the flang-commits mailing list