On 11/21/25 1:30 AM, Alexandre Oliva wrote:
Using hashes of data structures for tie breaking makes sorting
dependent on type sizes, padding, and endianness, i.e., unstable
across different hosts.
ira-color.cc's allocno_hard_regs_compare does that, and it causes
different register allocations to be chosen for the same target
depending on the host. That's undesirable.
Compare the HARD_REG_SETs directly instead, looking for the
lowest-numbered difference register to use as the tie breaker for the
cost compare.
With a hardware implementation of ctz, this is likely faster than the
hash used to break ties before.
The patch is ok for me.
We could make hashing target independent. But even in this case,
although hash conflicts should be a rare event, I think it would be not
hard to find such conflict as we use non-cryptographic hashes. So the
patch definitely improves the robustness and predictability of the compiler.
I am also agree using ctz should be faster. Btw, golang RA uses bit
count in the register mask and finding first non-zero bit in the mask
all the way.
Out of the patch scope, I believe we could improve hashing. Bob Jenkies
hash is too old (almost 30 years old). There are a lot of much faster
and better quality hashes.
Another topic is that GCC is now used as a JIT compiler. If JIT
generates functions from the application inputs it is possible to find
inputs for which the same hashes are generated during compilation of the
functions. This can result in quadratic behavior of the table and
denying attack when, for example, a jit is used inside a server
application. It is very difficult to implement such attack, but it is
possible. So it would be nice to provide api to make hashes
unpredictable (using random seeds) in JIT mode.
Thank you for the patch, Alex.
Regstrapped on x86_64-linux-gnu, bootstrapped with x86_64-linux-gnum32
(64-bit stage1, 32-bit stage[23]), smoke-tested with m68k-elf (for
FIRST_PSEUDO_REGISTER<=32). I suppose it's too late to fix this
long-time issue in this cycle, but is it ok for the next stage1?
for gcc/ChangeLog
PR rtl-optimization/122767
* ira-color.cc (allocno_hard_regs_compare): Break ties
using...
* hard-reg-set.h (hard_reg_set_first_diff): ... this. New
HARD_REG_SET API entry point.