<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jun 15, 2021 at 12:16 PM Ralf Jung via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
<br>
> The semantics you seem to want are that LLVM’s integer types cannot carry <br>
> information from pointers. But I can cast a pointer to an integer in C and <br>
> vice-versa, and compilers have de facto defined the behavior of subsequent <br>
> operations like breaking the integer up (and then putting it back together), <br>
> adding numbers to it, and so on. So no, as a C compiler writer, I do not have a <br>
> choice; I will have to use a type that can validly carry pointer information for <br>
> integers in C.<br>
<br>
Integers demonstrably do not carry provenance; see <br>
<<a href="https://www.ralfj.de/blog/2020/12/14/provenance.html" rel="noreferrer" target="_blank">https://www.ralfj.de/blog/2020/12/14/provenance.html</a>> for a detailed <br>
explanation of why.<br>
As a consequence of this, ptr-int-ptr roundtrips are lossy: some of the original <br>
provenance information is lost. This means that optimizing away such roundtrips <br>
is incorrect, and indeed doing so leads to miscompilations <br>
(<a href="https://bugs.llvm.org/show_bug.cgi?id=34548" rel="noreferrer" target="_blank">https://bugs.llvm.org/show_bug.cgi?id=34548</a>).<br>
<br>
The key difference between int and byte is that ptr-byte-ptr roundtrips are <br>
*lossless*, all the provenance is preserved. This means some extra optimizations <br>
(such as removing these roundtrips -- which implicitly happens when a <br>
redundant-store-after-load is removed), but also some lost optimizations (most <br>
notably, "x == y" does not mean x and y are equal in all respects; their <br>
provenance might still differ, so it is incorrect for GVN to replace one my the <br>
other).<br>
<br>
It's a classic tradeoff: we can *either* have lossless roundtrips</blockquote><div><br>I think an important part of explaining the motivation for "byte" would be an explanation/demonstration of what the cost of losing "lossless roundtrips" would be.<br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> *or* "x == y" <br>
implies full equality of the abstract values. Having both together leads to <br>
contradictions, which manifest as miscompilations. "byte" and "int" represent <br>
the two possible choices here; therefore, by adding "byte", LLVM would close a <br>
gap in the expressive power of its IR.<br>
<br>
Kind regards,<br>
Ralf<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div></div>