<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 4, 2017 at 8:35 PM, Sanjoy Das <span dir="ltr"><<a href="mailto:sanjoy@playingwithpointers.com" target="_blank">sanjoy@playingwithpointers.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);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.  "readonly may-unwind" is fine because even if the EH<br>
handler writes to memory, the code in the normal execution path does<br>
not have worry about the memory clobbers.<br>
<br>
I thought I had this figured out, but now it looks like I gotta think more. :)<br>
<br>
@Danny: I agree with your assessment of the example; unless the<br>
compiler knows that `cos` won't throw (which it may very well know<br>
since it is the standard library function, but I don't know GCC<br>
internals), the transform is wrong.<br>
<span class="gmail-HOEnZb"><font color="#888888"><br></font></span></blockquote><div>It does not know that, actually. </div><div>I would say that GCC pretty much is a grab bag, since i wrote that for the gcc regression testsuite, and it's still tested  :)<br></div><div><br></div><div>There are like 3 optimization testcases that use nothrow, and john's example happens to just fall into this case:</div><div><div><br></div><div>   if (stmt_ends_bb_p (stmt)</div><div>       || gimple_has_volatile_ops (stmt)</div><div>       || gimple_has_side_effects (stmt)</div><div>       || stmt_could_throw_p (stmt))</div><div>     return MOVE_IMPOSSIBLE;</div></div><div><br></div><div><br></div><div>Some of the passes check throwing, some of them don't.</div><div><br></div></div></div></div>