[flang][hlfir] Hoist forall bounds computation when possible
authorJean Perier <jperier@nvidia.com>
Tue, 23 May 2023 07:17:36 +0000 (09:17 +0200)
committerJean Perier <jperier@nvidia.com>
Tue, 23 May 2023 07:17:44 +0000 (09:17 +0200)
commit96a003b9bf79f22ead65173ae44943df640c5431
treeeb589c96652f072ed443a3853b12f7f6bcb4b586
parenteb5902ffc97163338bab95d2fd84a953ee76e96f
[flang][hlfir] Hoist forall bounds computation when possible

When inner forall bound computations do not depend on previous
forall indices, they can be hoisted.
This is possible because:
 - bound computation are required to be pure (so evaluating them only
   once is possible).
 - If the bound computation depends on a value previously assigned, the
   forall scheduling analysis created different run for it: the
   assignment impacting the bounds value is not part of the current loop
   nest.

The reason this optimization is done at that point and not as part of
generic loop hoisting optimization is that having the all the loop
bound computation hoisted will allow allocating simple temporary
storages. The number of iteration can be pre-computed and used as the
extent for the temporary.

Differential Revision: https://reviews.llvm.org/D151110
flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp
flang/test/HLFIR/order_assignments/forall-codegen-no-conflict.fir