<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Nov 5, 2014 at 11:17 AM, Philip Reames <span dir="ltr"><<a href="mailto:listmail@philipreames.com" target="_blank">listmail@philipreames.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000"><span class="">
<br>
<div>On 11/05/2014 10:54 AM, Reid Kleckner
wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">
<div class="gmail_extra">
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">This seems fine to
me. The optimizer can (soundly) conclude that %p is
dead after the "lifetime.end" (for the two
instructions), and dead before the "lifetime.start" (for
the *single* instruction in that basic block, *not* for
the previous BB). This seems like the proper result for
this example, am I missing something?</div>
</blockquote>
<div><br>
</div>
<div>What if I put that in a loop, unroll it once, and prove
that the lifetime.start is unreachable? We would end up
with IR like:</div>
<div><br>
</div>
<div>loop:</div>
<div> ... use %p</div>
<div> call void @lifetime.end( %p )</div>
<div>
<div> ... use %p</div>
<div> call void @lifetime.end( %p )</div>
</div>
<div> br i1 %c, label %loop, label %exit</div>
<div><br>
</div>
<div>Are the second uses of %p uses of dead memory?</div>
</div>
</div>
</div>
</blockquote></span>
It's hard to discuss this without being specific about the starting
IR and transforms. My general response is that either a) such a
transform wouldn't be valid or b) the behaviour of the original
program was undefined. </div></blockquote><div><br></div><div>The starting IR would be something that jumps into the middle of a lifetime region, like the example that Arnaud gave. This was assuming the current state of the world where we haven't added a second lifetime start call prior to the goto branch.</div><div><br></div><div>Start with something like:</div><div><br></div><div>void f(int x) {</div><div> while (x) {</div><div> goto skip_start;</div><div> {</div><div> int y; // lifetime.start</div><div>skip_start:</div><div> y = g();</div><div> x -= y;</div><div> // lifetime.end</div><div> }<br> }<br>}</div><div><br></div><div>The block containing the lifetime start of y is unreachable and can be deleted.</div></div></div></div>