Date: Sun, 9 Apr 2023 22:09:30 +0200
On 09/04/2023 16.38, Thiago Macieira via Std-Proposals wrote:
> On Sunday, 9 April 2023 08:48:56 -03 Jan Schultke via Std-Proposals wrote:
>> After discussing this with a few very well-versed people: you're most
>> likely right and this is a missed optimization. In that code sample,
>> the compiler could have used another callee-preserved register to save
>> on moves from memory.
>
> But is it worth it? There are relatively few callee-preserved registers, so
> each one of them is precious and could be used to store something else. I
> doubt a compiler would spill a memory location to the stack, even if it is to
> benefit from processor techniques that assign registers to stack locations.
> Meanwhile, the memory location is read-only and likely to be in the cache
> because it was used by the callee anyway.
While this is all true, compilers should and can make an informed
decision what to do when register pressure becomes too high.
Spilling modified stuff to the stack is certainly worse than
re-reading read-only data.
In this case (no register pressure at all), avoiding the memory
read wasn't even on the table, it seems.
Jens
> On Sunday, 9 April 2023 08:48:56 -03 Jan Schultke via Std-Proposals wrote:
>> After discussing this with a few very well-versed people: you're most
>> likely right and this is a missed optimization. In that code sample,
>> the compiler could have used another callee-preserved register to save
>> on moves from memory.
>
> But is it worth it? There are relatively few callee-preserved registers, so
> each one of them is precious and could be used to store something else. I
> doubt a compiler would spill a memory location to the stack, even if it is to
> benefit from processor techniques that assign registers to stack locations.
> Meanwhile, the memory location is read-only and likely to be in the cache
> because it was used by the callee anyway.
While this is all true, compilers should and can make an informed
decision what to do when register pressure becomes too high.
Spilling modified stuff to the stack is certainly worse than
re-reading read-only data.
In this case (no register pressure at all), avoiding the memory
read wasn't even on the table, it seems.
Jens
Received on 2023-04-09 20:09:59