[flang-commits] [flang] [flang][AddAliasTags] Generalise tbaa tags beyond functions (PR #92379)
Slava Zakharin via flang-commits
flang-commits at lists.llvm.org
Thu May 23 22:15:05 PDT 2024
vzakhari wrote:
Tom, regarding your example, while I understand the desire to provide better aliasing information for the OpenMP isolated from above operations, I do not think this is related to FIR (meaning Fortran) aliasing rules. And, in general, I do not think FIR AliasAnalysis can apply Fortran aliasing rules just based on the fact that the memory references originate from the block arguments of some isolated from above operation. Just think of a pass that, for whatever reason, outlines a set of FIR operations into a standalone function, and some live-in memrefs become block arguments of the function: at this point there is no guarantee that this function follows Fortran aliasing rules for these blocks arguments, since they do not represent dummy arguments in Fortran terms.
I think it is more appropriate to rely on the Fortran rules only when it is known that a source of a memory reference comes from an instantiation of a declaration of a Fortran dummy argument, which is conveyed in via `fir.declare` with a `dummy_scope` operand.
So maybe it is better to actually generate such `fir.declare` operations for the block arguments of the reduction operations, if we can guarantee that the two input memory references never alias. These `fir.declare` will not help right away, because without `getInstantiationPoint` (from #92472) set to true we will still pass through the `fir.declare`'s. I think `getSource` run from `fir::AliasAnalysis::alias` should actually collect sets of instantiation points for each memory reference, which will be multiple `fir.declare` operations in the use-def chain. Then the two sets for the two memory references may be checked element per element to see if any pair of `fir.declare`'s comes from the same function instantiation scope - then the best aliasing rule might be applied across such pairs. To make this work within `fir::AliasAnalysis` we will need some function scope attribute on all `fir.declare`'s: right now, for example, `fir.declare` for a module variable's instantiation does not have any scope attribute and I have to use the dominance information to find the scope - I think it will be unacceptable to use the dominance information in `fir::AliasAnalysis::alias`, so having the scoping information attached to all `fir.declare` will allow to avoid this.
With all that said, I would advise not merging this.
https://github.com/llvm/llvm-project/pull/92379
More information about the flang-commits
mailing list