[PATCH] D151644: [InstCombine] Propegating `nocapture` flag to callsites

Noah Goldstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 29 00:30:01 PDT 2023


goldstein.w.n added a comment.

In D151644#4378832 <https://reviews.llvm.org/D151644#4378832>, @nikic wrote:

> I don't think this is correct. Consider something like this:
>
>   define void @test(ptr nocapture %p) {
>     call void @store_ptr_in_global(ptr %p)
>     call void @do_something_with_store_pointer()
>     call void @store_ptr_in_global(ptr null)
>     ret void
>   }
>
> Here `store_ptr_in_global` escapes the pointer, but the overall function does not. It is okay to have such interior escapes as long as they are not observable by the caller.

Ah, good catch.

It should still work then in the case that the function doesn't interact with the global state after
the call?
So we could reverse iterate and while the sequence remains `pure`, it should be appliable?

My motivation is something like: https://godbolt.org/z/b4f8Krdx6
where AFAICT there is no way to write a syscall wrapper like that and actually preserve nocapture. Maybe a better approach?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151644



More information about the llvm-commits mailing list