[PATCH] D138336: [AA] A global cannot escape through nocapture/nocallback call.

Johannes Doerfert via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 19 11:51:14 PST 2022


jdoerfert accepted this revision.
jdoerfert added a comment.
This revision is now accepted and ready to land.

LG

In D138336#3938844 <https://reviews.llvm.org/D138336#3938844>, @vzakhari wrote:

> Thank you for the review, Johannes!
>
> I am not sure why the hoisting was legal in the previous version.   I guess it has something to do with the fact that clobbering a part of pointer with -1 may be considering an undefined behavior, so I changed the test to store a pointer inside the loop.

So, I didn't even see the UB, which was there. It was legal to hoist, and is in the versions w/o a call, because nothing in the loop can effectively alias the `obj` global.
The store can still not alias the `obj` even if we don't figure that out right now. Consequently, the `obj` is invariant and can be hoisted just after the function that takes `obj`.
The version with the unknown call are different. If `obj` escaped earlier, then the unknown call might have an impact on it and we cannot hoist the load.

> I also added cases with an unknown call, but it cannot be just any unknown call.  Without `nosync` or `nocallback` a call may modify a global even if it was not captured.

Fair point. We want to check that we know it wasn't captured, so the annotated unknown call looks good.

We could even do better in the nocapture case w/o nocallback, maybe add a TODO as this case can be handled if all uses in the module are nocapture effectively.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138336/new/

https://reviews.llvm.org/D138336



More information about the llvm-commits mailing list