[llvm-dev] Intrinsics InstrReadMem memory properties
Son Tuan VU via llvm-dev
llvm-dev at lists.llvm.org
Thu Jul 25 03:20:25 PDT 2019
Thanks Tim for your reply.
What about the case where the intrinsic is ReadNone and doesn't get
optimized? Also when it is WriteOnly, memset() does not get DSE'd?
Son Tuan Vu
On Thu, Jul 25, 2019 at 11:58 AM Tim Northover <t.p.northover at gmail.com>
wrote:
> On Thu, 25 Jul 2019 at 09:53, Son Tuan VU via llvm-dev
> <llvm-dev at lists.llvm.org> wrote:
> > - IntrWriteMem: memset() optimized away by DSE but the intrinsic isn't.
> I would expect both to be removed, since the intrinsic is now also a dead
> store.
>
> IntrWriteMem means the intrinsic could write to memory *anywhere*, not
> just based on its argument.
>
> > - IntrReadMem: memset() and the intrinsic are both optimized away
> *unexpectedly* (CSE removes the intrinsic, then InstCombine removes
> memset). The latter is understandable, but why the intrinsic gets optimized
> in the first place?
>
> I haven't checked the code, but an intrinsic that only reads memory
> (no other side effects) and returns void can't actually accomplish
> anything observable.
>
> > Am I missing something here or there are indeed bugs here?
>
> It all looks as expected to me.
>
> > Btw, can you tell me how and why 'tail' changes the optimizer behavior?
>
> From the LangRef about tail (and musttail): "Both markers imply that
> the callee does not access allocas from the caller". That seems
> directly applicable to your example.
>
> The reason, of course, is that if a call is actually implemented as a
> tail call then the current stack frame is reused for the new callee.
> So the lifetime of objects on it has ended and accessing them is just
> not possible in a well-defined program.
>
> Cheers.
>
> Tim.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190725/bded98ee/attachment.html>
More information about the llvm-dev
mailing list