llvm-project
9a81d853 - [flang][acc] Fix the indexing of the reduction combiner for multidimensional static arrays (#155536)

Commit
34 days ago
[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> ```
Author
Parents
Loading