<div dir="ltr"><div>Thanks Tim for your reply.</div><div><br></div><div>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?</div><div><br></div><div><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Son Tuan Vu</div></div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jul 25, 2019 at 11:58 AM Tim Northover <<a href="mailto:t.p.northover@gmail.com">t.p.northover@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Thu, 25 Jul 2019 at 09:53, Son Tuan VU via llvm-dev<br>
<<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
> - 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.<br>
<br>
IntrWriteMem means the intrinsic could write to memory *anywhere*, not<br>
just based on its argument.<br>
<br>
> - 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?<br>
<br>
I haven't checked the code, but an intrinsic that only reads memory<br>
(no other side effects) and returns void can't actually accomplish<br>
anything observable.<br>
<br>
> Am I missing something here or there are indeed bugs here?<br>
<br>
It all looks as expected to me.<br>
<br>
> Btw, can you tell me how and why 'tail' changes the optimizer behavior?<br>
<br>
>From the LangRef about tail (and musttail): "Both markers imply that<br>
the callee does not access allocas from the caller". That seems<br>
directly applicable to your example.<br>
<br>
The reason, of course, is that if a call is actually implemented as a<br>
tail call then the current stack frame is reused for the new callee.<br>
So the lifetime of objects on it has ended and accessing them is just<br>
not possible in a well-defined program.<br>
<br>
Cheers.<br>
<br>
Tim.<br>
</blockquote></div>