Why Programmer-Specified Aliasing Is a Bad Idea (2004) [pdf]
citeseerx.ist.psu.edu
citeseerx.ist.psu.edu
In rust, technically almost every pointer is non-aliasing, so you could enable "restrict" (or rather its equivalent down in the LLVM layer) by default for almost every pointer. However, this uncovered many unexercised corner cases where LLVM's restrict implementation appeared broken:
https://stackoverflow.com/questions/57259126/why-does-the-ru...
Scroll down to the answer to see how often noalias was enabled and disabled.
* initially enabled
* disabled in 1.8
* enabled in 1.27
* disabled in 1.30
* enabled 1.54 (because an issue blocked enabling it in 1.53 which pretty much guarantees there's still a bunch lurking)
Here’s the abstract.
The ISO C standard C99 has added a special keyword, named restrict to allow the programmer to specify non-aliasing as an aid to the compiler’s optimizer and to thereby possibly improve performance. However, it is the programmer’s responsibility to ensure that the annotations are correct. Therefore, in practice, restrict will be useful only when the programmer’s effort is rewarded with noticeable performance improvement. To assess the performance potential of the restrict annotation, we automatically generated best-case restrict annotations for SPEC CPU2000 benchmarks by using pointer profiling. However, even though we used the best possible restrict annotations, we found an average program speedup of less than 1% on average when using two state-of-the art optimizing compilers that implement the restrict pragma. Since the typical performance benefits do not warrant significant user effort and potential errors, we conclude that having the programmer specify non-aliasing is a bad idea.
Note that it is very program dependent, a friend got a 30% improvement on a very specialized numerical simulation.
Even a 5% speed increase is nothing to discount give that it's "free" once they have LLVM handling it correctly. I agree with the conclusion that if you have to manage the aliasing manually it's very limited in scenarios where you would want to deploy that given the failure modes of getting it wrong.
For now, it should be part of the next release (1.54).
It was originally slated for 1.53, but then a new miscompilation was discovered during the 1.53 release cycle, so it stayed off.
The thing that disables it is interior mutability- types like `Mutex` or `Cell` that can be mutated through shared references fall back to something like C without TBAA.
(though by "I wonder" I do not in any way suggest I'm qualified to have an opinion on the compiler internals themselves)
It's worth pointing out that compiler optimizations are not written as a lump of symbolic logic which then automatically goes and finds speed, there does have to be some human written code directing the transformations, so there likely is a chicken and egg here.
One complication is that in situations where aliasing is unlikely but very harmful some compilers already check for aliasing then use an optimized routine rather than a slow one that has to handle aliasing - that means user specified alias hints could only yield the elision of a branch and some instructions rather than a dramatic increase in throughput.
https://github.com/ClickHouse/ClickHouse/pull/19946#issuecom...
SPARC and Itanium are dead, and these two are the only platforms being benchmarked in the article.
This makes the article useless, we only care about AMD64 and ARM these days.
https://github.com/rurban/autoconf-archive/commit/91625ebef2...