←back to thread

Tree Borrows

(plf.inf.ethz.ch)
564 points zdw | 3 comments | | HN request time: 0s | source
Show context
jcalvinowens ◴[] No.44513250[source]
> On the one hand, compilers would like to exploit the strong guarantees of the type system—particularly those pertaining to aliasing of pointers—in order to unlock powerful intraprocedural optimizations.

How true is this really?

Torvalds has argued for a long time that strict aliasing rules in C are more trouble than they're worth, I find his arguments compelling. Here's one of many examples: https://lore.kernel.org/all/CAHk-=wgq1DvgNVoodk7JKc6BuU1m9Un... (the entire thread worth reading if you find this sort of thing interesting)

Is Rust somehow fundamentally different? Based on limited experience, it seems not (at least, when unsafe is involved...).

replies(11): >>44513333 #>>44513357 #>>44513452 #>>44513468 #>>44513936 #>>44514234 #>>44514867 #>>44514904 #>>44516742 #>>44516860 #>>44517860 #
jcranmer ◴[] No.44514867[source]
Take anything Linus says about compilers with a grain of salt--he writes OS kernels, not compilers, and those are pretty different domains.

Alias analysis is extremely important for getting good performance these days--but it should also be remembered that the biggest benefits accrue from the simplest heuristics (like two loads that use the same SSA value as the pointer must alias each other). In LLVM terms, that's BasicAA: a collection of very simple heuristics that primarily amounts to "if we can track down the allocation sites of objects, we can definitively resolve these alias queries; otherwise, we don't know."

The real question that you're trying to ask, though, is what is the value of alias analyses that go beyond the most basic, obvious tests. At the point where the alias queries are no longer trivial to solve, then it's generally the case that what you can do as a result of those queries also shrinks dramatically, pretty much to looking for code motion hazards, and the benefits you get from that are much reduced. One of the experiments I would like to do is measure the total speedup you'd get from a theoretically perfect alias analysis, and my guess is that it's somewhere in the 20% range even on non-HPC code like the Linux kernel [1].

[1] This doesn't account for the heroic optimizations, such as data-layout transformations, that you wouldn't attempt to write without a very high-quality alias analysis. But since we already know that alias analysis doesn't exist in practice, we're not going to attempt those optimizations anyways, so it's not worth including such stuff in prospective speed gains.

replies(3): >>44515164 #>>44517072 #>>44517943 #
kunley ◴[] No.44517943[source]
Maybe Linus by writing kernels, not compilers, has even more to say, because his use-case is much more practical than anything that compiler designers could imagine.
replies(1): >>44520924 #
jcranmer ◴[] No.44520924[source]
That's kind of a rude thing to say, suggesting that compilers aren't real programmers. Nevertheless, it is the case that most optimizations in the compiler are motivated by real issues with somebody's code, as opposed to compiler engineers thinking up optimizations in their heads.
replies(1): >>44523330 #
1. kunley ◴[] No.44523330[source]
So, if my sentence is rude, and "take anything Linus says about compilers with a grain of salt" isn't, then I definitely quit this discussion.
replies(2): >>44524193 #>>44527040 #
2. jcranmer ◴[] No.44524193[source]
I'm suggesting that Linus isn't the best person to be used as an expert in compilers because his field isn't in compilers.

You're suggesting that someone who works on compilers shouldn't be used as an expert in compilers because their field is in compilers.

There is a difference between those two statements, and that difference is what makes one rude where the other isn't.

3. dwattttt ◴[] No.44527040[source]
Your statement

> by writing kernels... his use-case is much more practical than anything that compiler designers could imagine.

States that compiler designers cannot even imagine the practicalities needed to write kernels. Which is quite a blanket statement to try to make and defend.