<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Jan 5, 2017 at 9:19 AM, Hal Finkel via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><br>
On 01/05/2017 10:55 AM, Sanjoy Das wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Hal,<br>
<br>
On Thu, Jan 5, 2017 at 6:12 AM, Hal Finkel <<a href="mailto:hfinkel@anl.gov" target="_blank">hfinkel@anl.gov</a>> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On 01/04/2017 10:35 PM, Sanjoy Das via llvm-dev wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I just realized that there's an annoying corner case to this scheme --<br>
I can't DSE stores across readnone maythrow function calls because the<br>
exception handler could read memory. That is, in:<br>
<br>
try {<br>
    *a = 10;<br>
    call void @readnone_mayunwind_fn();<br>
    *a = 20;<br>
} catch (...) {<br>
    assert(*a == 10);<br>
}<br>
<br>
I can't DSE the `*a = 10` store.<br>
<br>
As far as I can tell, the most restrictive memory attribute for a<br>
potentially throwing function is readonly.  "readnone may-unwind" does<br>
not make sense.<br>
</blockquote>
<br>
Why not? I've not followed this thread in detail, but it seems like you're<br>
discussing allowing the modeling of EH schemes that don't access accessible<br>
memory. In that case, a may-unwind readnone function is just one that makes<br>
its decision about if/what to throw based only on its arguments.<br>
</blockquote>
If the call to @readnone_mayunwind_fn throws and I've DSE'ed the "*a =<br>
10" store, the exception handler will fail the *a == 10 assert (assume<br>
*a is not 10 to begin with).  The function call itself is readnone,<br>
but its exceptional continuation may read any part of the heap.<br>
<br>
This isn't a big deal, but it means that "readnone may-unwind" will<br>
effectively have to be treated as "readonly may-unwind" -- I don't see<br>
any optimization that would be applicable to one and not the other.<br>
Maybe we should just move ahead with that (that readnone may-unwind is<br>
allowed, but if you want readnone-like optimizations then you need to<br>
also mark it as nounwind)?<br>
</blockquote>
<br></div></div>
Yes, I think that makes sense. The attribute only applies to the function anyway, so what exception handlers might do (which is assumed to be reading/writing any memory that might be available to them) must be reasoned about separately.<br></blockquote><div><br></div><div>I don't think we need or want to do that. The way I see it, readonly implies that the exception handler cannot write memory readable by LLVM. Similarly, readnone should imply that the exception handler does not read memory written by LLVM. Basically, any function that may unwind but also has these attributes asserts that the exception handler is operating outside of memory modeled by LLVM.</div><div><br></div><div>I don't think we'll do DSE in your example because the store isn't dead, it's visible along the invoke's unwind edge, and we don't need to change the semantics of readnone to see that.</div></div></div></div>