https://gcc.gnu.org/g:bac903e29145adb3d611cf37e03fd553954c9ffb

commit r14-12197-gbac903e29145adb3d611cf37e03fd553954c9ffb
Author: Vladimir N. Makarov <[email protected]>
Date:   Thu Dec 11 09:21:00 2025 -0500

    [PR122215, IRA]: Fix undefined behaviour of improve_allocation
    
    Register filters are used in one loop of improve_allocation to ignore some
    hard regs for cost calculation but it is missed in the subsequent loop
    using the costs.  This results in usage of random (undefined) register costs
    and in sporadic code generation for riscv32 which uses the filters.
    
    gcc/ChangeLog:
    
            PR rtl-optimization/122215
            * ira-color.cc (improve_allocation): Use register filter for all
            loop on hard regs.

Diff:
---
 gcc/ira-color.cc | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gcc/ira-color.cc b/gcc/ira-color.cc
index b9ae32d1b4da..ae374243147c 100644
--- a/gcc/ira-color.cc
+++ b/gcc/ira-color.cc
@@ -3320,6 +3320,9 @@ improve_allocation (void)
       for (j = 0; j < class_size; j++)
        {
          hregno = ira_class_hard_regs[aclass][j];
+         if (NUM_REGISTER_FILTERS
+             && !test_register_filters (ALLOCNO_REGISTER_FILTERS (a), hregno))
+           continue;
          if (check_hard_reg_p (a, hregno,
                                conflicting_regs, profitable_hard_regs)
              && min_cost > costs[hregno])

Reply via email to