[flang-commits] [flang] [flang][OpenMP] Improve reduction of Scalar ArrayElement types (PR #163940)

Tom Eccles via flang-commits flang-commits at lists.llvm.org
Fri Oct 17 10:29:13 PDT 2025


tblah wrote:

When generating the body of the construct containing the reduction clause, we need to ensure that the references to the reduced value use the private reduction variable and not some host variable. The way this works for reductions (and I think privatisation) is that we create a host associated symbol for the variable being reduced and that shadows the original shared copy: ensuring that lowering of references to that symbol inside of the body instead point to the reduction block argument.

This works well when whole symbols are reduced, but not when an expression is what is reduced. We don't have a convenient way to instruct lowering to replace all instances of a parse tree expression with a new value (the reduction block argument). I couldn't think of a way to add that without changing a lot of non-openmp code. This work around is to rewrite something like
```
!$omp parallel reduction(+: a(10))
...
a(10) = a(10) + 10 
!$omp end parallel
```
into
```
tmp = a(10)
!$omp parallel reduction(+: tmp)
...
tmp = tmp + 10 
!$omp end parallel
a(10) = tmp
```

This is a first step towards supporting reductions on components of derived types (which will be handled with a temporary in a similar way).

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


More information about the flang-commits mailing list