https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97705
--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Kewen Lin <li...@gcc.gnu.org>: https://gcc.gnu.org/g:ce4ae1f4893e322495c5d24b2f0e807a7f7cf92f commit r11-4827-gce4ae1f4893e322495c5d24b2f0e807a7f7cf92f Author: Kewen Lin <li...@linux.ibm.com> Date: Sun Nov 8 20:35:21 2020 -0600 ira: Recompute regstat as max_regno changes [PR97705] As PR97705 shows, the commit r11-4637 caused some dumping comparison difference error on pass ira. It exposed one issue about the newly introduced function remove_scratches, which can increase the largest pseudo reg number if it succeeds, later some function will use the max_reg_num() to get the latest max_regno, when iterating the numbers we can access some data structures which are allocated as the previous max_regno, some out of array bound accesses can occur, the failure can be random since the values beyond the array could be random. This patch is to free/reinit/recompute the relevant data structures that is regstat_n_sets_and_refs and reg_info_p to ensure we won't access beyond some array bounds. Bootstrapped/regtested on powerpc64le-linux-gnu P9 and powerpc64-linux-gnu P8. gcc/ChangeLog: PR rtl-optimization/97705 * ira.c (ira): Refactor some regstat free/init/compute invocation into lambda function regstat_recompute_for_max_regno, and call it when max_regno increases as remove_scratches succeeds.