<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<p><br>
</p>
<div class="moz-cite-prefix">On 7/29/20 9:00 PM, John McCall via
cfe-dev wrote:<br>
</div>
<blockquote type="cite" cite="mid:A2893A68-6F52-4E36-BE90-C7F3B87D8BBB@apple.com">
<div style="font-family:sans-serif">
<div style="white-space:normal">
<p dir="auto">On 29 Jul 2020, at 17:42, Richard Smith wrote:</p>
</div>
<div style="white-space:normal">
<blockquote style="border-left:2px solid #777; color:#777;
margin:0 0 5px; padding-left:5px">
<p dir="auto">On Wed, 29 Jul 2020 at 12:52, John McCall
<a class="moz-txt-link-rfc2396E" href="mailto:rjmccall@apple.com"><rjmccall@apple.com></a> wrote:<br>
</p>
...</blockquote>
</div>
<div style="white-space:normal">
<blockquote style="border-left:2px solid #777; color:#777;
margin:0 0 5px; padding-left:5px">
<p dir="auto">I think concretely, the escape hatch doesn't
stop things from going wrong,<br>
because -- as you note -- even though we *could* have made
a copy, it's<br>
observable whether or not we *did* make a copy. For
example:</p>
</blockquote>
</div>
<div style="white-space:normal">
<p dir="auto">I would say that it’s observable whether the
parameter variable has<br>
the same address as the argument. That doesn’t <em>have</em>
to be the same<br>
question as whether a copy was performed: we could consider
there to be<br>
a formal copy (or series of copies) that ultimately creates
<em>an</em> object<br>
at the same address, but it’s not the <em>same</em> object
and so pointers<br>
to the old object no longer validly pointer to it. But I
guess that<br>
would probably violate the lifetime rules, because it would
make accesses<br>
through old pointers UB when in fact they should at worst
access a valid<br>
object that’s just unrelated to the parameter object.</p>
</div>
</div>
</blockquote>
<p><br>
</p>
<p>I think that it would be great to be able to do this, but
unfortunately, I think that the point that you raise here is a key
issue. Whether or not the copy is performed is visible in the
model, and so we can't simply act as though there was a copy when
optimizing. Someone could easily have code that looks like:</p>
<p>Foo DefaultX;</p>
<p>...</p>
<p>void something(Foo &A, Foo &B) {</p>
<p> if (&A == &B) { ... }<br>
</p>
<p>}<br>
</p>
<p>void bar(Foo X) { something(X, DefaultX); }</p>
<p>As Richard's example shows, the code doesn't need to explicitly
compare the addresses to detect the copy either. Any code that
reads/writes to the objects can do it. A perhaps-more-realistic
example might be:</p>
<p> int Cnt = A.RefCnt; ++A.RefCnt; ++B.RefCnt; if (Cnt + 1 !=
A.RefCnt) { /* same object case */ }</p>
<p>The best suggestion that I have so far is that we could add an
attribute like 'can_copy' indicating that the optimizer can make a
formal copy of the argument in the callee and use that instead of
the original pointer if that seems useful. I can certainly imagine
a transformation such as LICM making use of such a thing (although
the cost modeling would probably need to be fairly conservative).<br>
</p>
<p> -Hal</p>
<p><br>
</p>
<blockquote type="cite" cite="mid:A2893A68-6F52-4E36-BE90-C7F3B87D8BBB@apple.com">
<div style="font-family:sans-serif">
<div style="white-space:normal">
</div>
...<br>
<div style="white-space:normal">
<p dir="auto">John.</p>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
cfe-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a>
</pre>
</blockquote>
<pre class="moz-signature" cols="72">--
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory</pre>
</body>
</html>