<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
<br class="">
<div>
<blockquote type="cite" class="">
<div class="">On 7 Apr 2017, at 00:54, Sanjoy Das <<a href="mailto:sanjoy@playingwithpointers.com" class="">sanjoy@playingwithpointers.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div class="">+CC Artur<br class="">
<br class="">
On April 6, 2017 at 2:51:17 PM, Keno Fischer (<a href="mailto:keno@juliacomputing.com" class="">keno@juliacomputing.com</a>) wrote:<br class="">
<blockquote type="cite" class="">I left a comment on <a href="https://reviews.llvm.org/D18738" class="">
https://reviews.llvm.org/D18738</a> earlier which I<br class="">
feel is related to this discussion, so I'm reproducing it here:<br class="">
<br class="">
I wonder though if what we want to express isn't some sort of<br class="">
"type-based dereferencability annotations". For example the semantics<br class="">
I care about are essentially, "if you know you have a defereferencable<br class="">
pointer, you can go and dereference any other valid (managed) pointers<br class="">
the pointed to data references (recursively)". This has to be true for<br class="">
me, because the GC walks all pointers recursively that way. Of course<br class="">
the problem with this is that the compiler doesn't know which part of<br class="">
the referenced data are valid pointers for this purpose (and it can't<br class="">
just be based on the struct type, because we do store pointers to<br class="">
unmanaged data). So if we had a way to express to the compiler "here<br class="">
are the pointers in this struct that you may assume dereferencable",<br class="">
that would work very well for me.<br class="">
</blockquote>
<br class="">
That is very close to what we (Azul) do internally (I think Artur<br class="">
covered some of this on his EuroLLVM talk).<br class="">
</div>
</div>
</blockquote>
The slides and videos from the conference have not yet been published, but I posted my slides on slideshare:</div>
<div><a href="https://www.slideshare.net/secret/Bj7JJPimlxjwGb" class="">https://www.slideshare.net/secret/Bj7JJPimlxjwGb</a></div>
<div><br class="">
</div>
<div>In a few words, we introduced the notion of Java types which are expressed in the IR using attributes and metadata, we derive various facts from the Java types including dereferenceability.  </div>
<div><br class="">
</div>
<div>Artur<br class="">
<blockquote type="cite" class="">
<div class="">
<div class=""><br class="">
If we have:<br class="">
<br class="">
if (x instanceof java.lang.String) {<br class="">
  if (arbitraryCondition) {<br class="">
    char[]v = x.value;<br class="">
  }<br class="">
}<br class="">
<br class="">
we know we can hoist the load of x.value outside the<br class="">
arbitraryCondition check (modulo aliasing).<br class="">
<br class="">
-- Sanjoy<br class="">
<br class="">
<blockquote type="cite" class=""><br class="">
On Thu, Apr 6, 2017 at 5:47 PM, Sanjoy Das via llvm-dev<br class="">
wrote:<br class="">
<blockquote type="cite" class="">Hi Piotr,<br class="">
<br class="">
On April 6, 2017 at 9:28:58 AM, Piotr Padlewski<br class="">
(<a href="mailto:piotr.padlewski@gmail.com" class="">piotr.padlewski@gmail.com</a>) wrote:<br class="">
<blockquote type="cite" class="">Hi Sanjoy,<br class="">
My point is that this it is exactly the same way as normal !dereferenceable<br class="">
introduces UB.<br class="">
<br class="">
ptr = load i8*, i8** %ptrptr, !dereferenceable !{i64 8}<br class="">
if (false) {<br class="">
int val = *ptr;<br class="">
}<br class="">
</blockquote>
<br class="">
These are two different things.<br class="">
<br class="">
In the above example, your original program executes a load that was<br class="">
supposed to produce a dereferenceable value, but it did not. This<br class="">
means the original program is undefined, so we can optimize it to do<br class="">
whatever we want.<br class="">
<br class="">
OTOH, look at this program:<br class="">
<br class="">
void main() {<br class="">
if (false) {<br class="">
// ptrptr does not contain a dereferenceable pointer, but is<br class="">
itself dereferenceable<br class="">
ptr = load i8*, i8** %ptrptr, !dereferenceable !{i64 8}, !global<br class="">
int val = *ptr;<br class="">
}<br class="">
}<br class="">
<br class="">
What is the behavior of the above program? It better be well defined,<br class="">
since it does nothing!<br class="">
<br class="">
However, if we follow your rules, we can first xform it to<br class="">
<br class="">
void main() {<br class="">
ptr = load i8*, i8** %ptrptr, !dereferenceable !{i64 8}, !global<br class="">
if (false) {<br class="">
int val = *ptr;<br class="">
}<br class="">
}<br class="">
<br class="">
and then to<br class="">
<br class="">
void main() {<br class="">
ptr = load i8*, i8** %ptrptr, !dereferenceable !{i64 8}, !global<br class="">
int val = *ptr;<br class="">
if (false) {<br class="">
}<br class="">
}<br class="">
<br class="">
which introduces UB into a program that was well defined to begin<br class="">
with.<br class="">
<br class="">
<blockquote type="cite" class="">If frontend says that something is dereferenceable, which is not actually<br class="">
dereferenceable, then it is UB and everything can happen - like the<br class="">
execution of dead instruction.<br class="">
This is exactly the same with the global properties - we are giving a<br class="">
guarantee that pointer it is dereferenceable even if we would hoist or sink<br class="">
it, and if it is not true then it is UB.<br class="">
</blockquote>
<br class="">
But then you're saying dead code (code that would not actually execute<br class="">
in the original program) can affect program behavior, and: "if (false)<br class="">
X;" is not a no-op for some values of X. It is in this respect that<br class="">
your proposal is similar to the speculatable proposal.<br class="">
<br class="">
-- Sanjoy<br class="">
_______________________________________________<br class="">
LLVM Developers mailing list<br class="">
<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><br class="">
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev<br class="">
</blockquote>
<br class="">
</blockquote>
</div>
</div>
</blockquote>
</div>
<br class="">
</body>
</html>