By ref and by pointer kills performance.

Basile B. b2.temp at gmx.com
Wed Feb 14 00:59:54 UTC 2024


On Tuesday, 13 February 2024 at 15:14:06 UTC, Patrick Schluter 
wrote:
> On Tuesday, 13 February 2024 at 03:31:31 UTC, Richard (Rikki) 
> Andrew Cattermole wrote:
>> dmd having bad codegen here isn't a surprise, that is to be 
>> expected.
>>
>> Now for ldc:
>>
>> ```d
>> void fillBP(immutable(uint*) value, uint* dest) {
>>      dest[0] = *value;
>>      dest[1] = *value;
>>      dest[2] = *value;
>>      dest[3] = *value;
>> }
>> ```
>>
>> I expected that to not do the extra loads, but it did.
>>
>> ```d
>> void fillBP(immutable(uint*) value, uint* dest) {
>> 	dest[0 .. 4][] = *value;
>> }
>> ```
>>
>> And that certainly should not be doing it either.
>> Even if it wasn't immutable.
>>
>> For your code, because it is not immutable and therefore can 
>> be changed externally on another thread, the fact that the 
>> compiler has to do the loads is correct. This isn't a bug.
>
> Is not a thread issue. The memory the pointers point to only 
> needs to overlap and the loads are required to get the "right" 
> result.

It's been proven that the main problem, i.e what defeated CSE ( 
the Common Sub Expression optim pass), is the possible overlap 
between the two parameter.

However there'is still a risk on the value, i.e it can be 
modified by another thread, like mentioned Johan IIRC. The 
destination of the pointer you pass as "value" might change 
between one of the fourth assignment.

To be frank I thought this was the problem.


More information about the Digitalmars-d mailing list