[llvm] [MSSA] Don't check non-AA memory effects when using template access (PR #76142)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 22 00:38:51 PST 2023


nikic wrote:

> I think that's possible but I may be missing edge cases not covered by current tests. Something like this resolves the testcases in this PR:

I think this may chose an incorrect defining access in some cases.

Let's say we have the following initial structure:

```
writes x
writes y
now_readnone (defining: writes x)
reads y (defining: now_readnone)
```

The important part is that the defining access of `now_readnone` skips an intermediate MemoryDef for whatever reason (say TBAA metadata).

Then, I think your new code would set the defining access of clone(reads y) to clone(writes x), even though the correct one would be clone(writes y).

> If you move fwd with creating accesses for non-memory affecting instructions, a follow up optimization could be to remember those accesses that were still created using a template, then call removeMemoryAccess (leaving optimizePhis to false) on those, after cloning and new phi assignment is complete. This should redirect the defining accesses properly.

Something we could also do is to already clean up such accesses inside LoopInstSimplify. That is, if we see that a callee has been replaced by a constant, check whether the access can be removed. This has the benefit that we'll simplify the original access as well, not just the cloned access. (Though I don't think we should rely on this happening, as there's just too many ways in that AA results can change.)

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


More information about the llvm-commits mailing list