[llvm-branch-commits] [flang] [mlir] [Flang][mlir][OpenMP] Support affinity clause codegen in Flang (PR #182222)
Tom Eccles via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Mar 4 04:22:53 PST 2026
https://github.com/tblah commented:
Thanks for the updates. I think there is a remaining issue for non-default lower bounds. For this code example
```
subroutine task_affinity_nondefault_lb()
implicit none
integer, parameter :: n = 8
integer :: a(0:n)
integer :: i
!$omp parallel
!$omp single
!$omp task affinity(iterator(i = 0:n) : a(i))
a(0) = 1
!$omp end task
!$omp end single
!$omp end parallel
end subroutine
```
We get
```
%c0_i32 = arith.constant 0 : i32
%c8_i32 = arith.constant 8 : i32
%8 = fir.convert %c0_i32 : (i32) -> index
%9 = fir.convert %c8_i32 : (i32) -> index
%c1 = arith.constant 1 : index
%10 = omp.iterator(%arg0: index) = (%8 to %9 step %c1) {
%11 = fir.convert %arg0 : (index) -> i32
%12 = fir.convert %11 : (i32) -> i64
%13 = fir.convert %12 : (i64) -> index
%14 = fir.shape %c9 : (index) -> !fir.shape<1>
%15 = fir.array_coor %3#0(%14) %13 : (!fir.box<!fir.array<9xi32>>, !fir.shape<1>, index) -> !fir.ref<i32>
%16 = fir.box_elesize %3#0 : (!fir.box<!fir.array<9xi32>>) -> index
%17 = fir.convert %16 : (index) -> i64
%18 = fir.convert %15 : (!fir.ref<i32>) -> !fir.ref<i8>
%19 = omp.affinity_entry %18, %17 : (!fir.ref<i8>, i64) -> !omp.affinity_entry_ty<!fir.ref<i8>, i64>
omp.yield(%19 : !omp.affinity_entry_ty<!fir.ref<i8>, i64>)
} -> !omp.iterated<!omp.affinity_entry_ty<!fir.ref<i8>, i64>>
```
That array_coor is getting a fir.shape not a fir.shapeshift so it won't know that it is dealing with non-default lower bounds so the 0 index is going to produce invalid code.
As a more minor thing, fir.box_elesize is overkill here because the size of the element can easily be determined at compile time. But perhaps that is better left for a later patch adding a canonicalization from a fir.box_elesize to a constant where possible.
https://github.com/llvm/llvm-project/pull/182222
More information about the llvm-branch-commits
mailing list