By ref and by pointer kills performance.
Walter Bright
newshound2 at digitalmars.com
Wed Feb 14 04:49:28 UTC 2024
On 2/12/2024 7:31 PM, Richard (Rikki) Andrew Cattermole wrote:
> dmd having bad codegen here isn't a surprise, that is to be expected.
I'm used to people saying that DMD doesn't do data flow analysis. It does. In
fact, it is based on my OptimumC, which was the first C compiler on DOS to do
DFA back in the 1980s.
This isn't a case of buggy DFA. It's a case of doing DFA correctly.
The issue is pointer aliasing. A pointer can point to anything, including const
data. Therefore, storing through a pointer can alter any value that is reachable
via a pointer. Therefore, storing through a pointer invalidates any cached value
already read.
This is what you're seeing.
C99 tried to address this with __restrict, but few people use it or understand
it. D didn't bother with it because people will inevitably misuse __restrict and
get their data mysteriously corrupted.
More information about the Digitalmars-d
mailing list