[all-commits] [llvm/llvm-project] 9a81d8: [flang][acc] Fix the indexing of the reduction com...

khaki3 via All-commits all-commits at lists.llvm.org
Tue Aug 26 21:27:19 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 9a81d853cee219af05ee58959ea9c5e9ac69980e
      https://github.com/llvm/llvm-project/commit/9a81d853cee219af05ee58959ea9c5e9ac69980e
  Author: khaki3 <47756807+khaki3 at users.noreply.github.com>
  Date:   2025-08-26 (Tue, 26 Aug 2025)

  Changed paths:
    M flang/lib/Lower/OpenACC.cpp
    M flang/test/Lower/OpenACC/acc-reduction-unwrap-defaultbounds.f90
    M flang/test/Lower/OpenACC/acc-reduction.f90

  Log Message:
  -----------
  [flang][acc] Fix the indexing of the reduction combiner for multidimensional static arrays (#155536)

In the following example of reducing a static 2D array, we have
incorrect coordinates for array access in the reduction combiner. This
PR reverses the order of the induction variables used for such array
indexing. For other cases of static arrays, we reverse the loop order as
well so that the innermost loop can handle the innermost dimension.

```Fortran
program main
  implicit none
  integer, parameter :: m = 2
  integer, parameter :: n = 10
  integer :: r(n,m), i

  r = 0

  !$acc parallel loop reduction(+:r(:n,:m))
  do i = 1, n
     r(i, 1) = i
  enddo

  print *, r
end program main
```

Currently, we have:
```mlir
fir.do_loop %arg2 = %c0 to %c1 step %c1 {
  fir.do_loop %arg3 = %c0 to %c9 step %c1 {
    %0 = fir.coordinate_of %arg0, %arg2, %arg3 : (!fir.ref<!fir.array<10x2xi32>>, index, index) -> !fir.ref<i32>
    %1 = fir.coordinate_of %arg1, %arg2, %arg3 : (!fir.ref<!fir.array<10x2xi32>>, index, index) -> !fir.ref<i32>
```

We'll obtain:
```mlir
fir.do_loop %arg2 = %c0 to %c1 step %c1 {
  fir.do_loop %arg3 = %c0 to %c9 step %c1 {
    %0 = fir.coordinate_of %arg0, %arg3, %arg2 : (!fir.ref<!fir.array<10x2xi32>>, index, index) -> !fir.ref<i32>
    %1 = fir.coordinate_of %arg1, %arg3, %arg2 : (!fir.ref<!fir.array<10x2xi32>>, index, index) -> !fir.ref<i32>
```



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list