[flang-commits] [flang] [mlir] [RFC][mlir] ViewLikeOpInterface method for detecting partial views. (PR #164020)

Slava Zakharin via flang-commits flang-commits at lists.llvm.org
Mon Nov 3 11:15:11 PST 2025


vzakhari wrote:

Thank you for the thorough review, @matthias-springer!

> ```
> This patch also modifies LocalAliasAnalysis to stop returning
> MustAlias in cases where both MustAlias and PartialAlias
> are possible - we will return MayAlias now, which is conservatively
> correct.
> ```
> 
> What's the reasoning for this? `MustAlias` seems to be a better choice because it gives stronger guarantees.
> 
> * In what cases do we find both `MustAlias` and `PartialAlias`?

I will use the same example as above:
```
  %obj = ...
  %view1 = view of %obj with offset 0
  %view2 = view of %obj with offset %off
  access %view1
  access %view2
```

Depending on the value of `%off` it might be either `MustAlias` or `PartialAlias` (and maybe `NoAlias`, if we would like to take into account any "access" of zero size - I believe this is what LLVM alias analysis is doing).  The current implementation of `LocalAliasAnalysis` would return `MustAlias` in this case, which is not quite correct.

> * Why would we fall back to `MayAlias` instead of `PartialAlias`?

I would like to suggest using `MayAlias` currently given that I am not trying to change `LocalAliasAnalysis` a lot (my main goal is to simplify FIR alias analysis implementation).  Let's take an example:
```
  %obj = ...
  %view1 = view of %obj with offset 10
  %view2 = view of %obj with offset 20
  access %view1
  access %view2
```

In its current implementation, `LocalAliasAnalysis` will return `MustAlias`, which is incorrect.

With my changes to propagate only `maybeOffset`, I can detect that we've reached `%obj` definition with some potentially different offsets. So I have an option to return either `PartialAlias` or `MayAlias`.  Returning `PartialAlias` may be incorrect, since I am not taking into account the offset values and the sizes of the accesses.  This means that I can actually have either `NoAlias`, `PartialAlias` or `MustAlias` depending on the offsets/sizes.  `MayAlias` seems to be the most conservatively correct reply within the current implementation.

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


More information about the flang-commits mailing list