https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97705
--- Comment #4 from Kewen Lin <linkw at gcc dot gnu.org> --- I think my commit just exposed one bug in ira. The newly introduced function remove_scratches can bump the max_regno, then the data structures regstat_n_sets_and_refs and reg_info_p which are allocated according to max_regno become stale. When we call print_pseudo_costs to dump some register information, it use the latest regno with max_reg_num (), it leads we can access some regno which don't have relevant data structures which have been allocated, the read values can be random (out of array bound access). The fix can be to free/re-init/re-compute the relevant data structures when we know the max_regno already changes like remove_scratches succeeds.