If an argument is readnone we know that it isn't dereferenced. Then
it should be OK if that argument alias with a noalias argument.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/lib/Analysis/Lint.cpp | ||
---|---|---|
240 | Maybe we need to check for NoCapture as well (that would be a bit more defensive at least)? |
For reference, here is an example that made me look at this: https://godbolt.org/z/xY4hE9Kvb
The caller is doing
call void @foo(ptr nonnull sret(%struct.A) align 8 %3, ptr noundef nonnull align 8 %1)
and the callee is
define dso_local void @foo(ptr noalias nocapture writeonly sret(%struct.A) align 8 %0, ptr nocapture noundef readnone align 8 %1) local_unnamed_addr #0
And then memcpyopt will rewrite the call to use same ptr for both arguments, which then result in complaints from lint. But I think that should be OK here.
llvm/lib/Analysis/Lint.cpp | ||
---|---|---|
240 | Given the example from https://godbolt.org/z/xY4hE9Kvb If I remove NoCapture on the second argument then MemCpyOpt no longer rewrite the call. So then I actually think it would make sense to also check NoCapture here. Right? |
llvm/lib/Analysis/Lint.cpp | ||
---|---|---|
240 | I looked a bit more a MemCpyOptPass::performCallSlotOptzn to understand the logic for when it may introduce the IR when passing the ptr in multiple arguments (with some being noalias). Anyway. Not sure if the MemCpyOpt behavior is that important here. The question is when it is allowed to pass a pointer that is used in a noalias argument in another argument. |
There are test failures.
llvm/lib/Analysis/Lint.cpp | ||
---|---|---|
240 | Should use I.doesNotAccessMemory(ArgNo) to take into account both the call-site and declaration attributes. I don't think NoCapture is relevant here. noalias is a pure provenance concept, so it only cares about memory accesses. It also applies only for the duration of the call, so it does not matter if the pointer is captured and accessed later. |
Maybe we need to check for NoCapture as well (that would be a bit more defensive at least)?