<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<br>
<div class="moz-cite-prefix">On 11/05/2014 01:48 PM, Reid Kleckner
wrote:<br>
</div>
<blockquote
cite="mid:CACs=tyKmn8st7gdgpjSWDpw-tUkxnFgSx2ZT6vJ+Btv9B0qCGw@mail.gmail.com"
type="cite">
<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 moz-do-not-send="true"
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>
</blockquote>
If I'm understanding you right, we'd have something like this:<br>
<div><br>
</div>
<div>void f(int x) {<br>
(space for y reserved, no lifetime start)<br>
</div>
<div> while (x) {</div>
{<br>
y = g();
<div> x -= y;</div>
<div> // lifetime.end</div>
<div> }<br>
}<br>
}<br>
<br>
I don't see the problem here. <br>
<br>
We have a BB (or set of BBs) which contains:<br>
{<br>
<div> y = g();</div>
<div> x -= y;</div>
<div> // lifetime.end(y)</div>
}<br>
with *two* predecessors. *One* of those predecessors contains the
lifetime.end, the other does not. Thus there is a path where the
store for y is defined. <br>
<br>
If I'm interpreting the original code correctly, that's exactly
the right semantic. This code is poorly defined if-and-only-if
the backedge is taken. To say this differently, the original
program had a dynamic trace (before optimization) where two "ends"
where not separated by a "start". That's a bug in the frontend.
To fix it, the frontend needs a lifetime.start in the source of
the goto. <br>
<br>
(We haven't actually settled the semantics of a sequence of
end,start,end. My view is there are reasonable semantics - which
I'm using here - for that sequence and important use cases in
loops. As the actual documentation says at this point, the
lifetime markers would have to be outside the loop. That's just
"obviously" silly though.) <br>
<br>
Philip<br>
</div>
<br>
</body>
</html>