https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117838
--- Comment #4 from cuilili <lili.cui at intel dot com> --- I created a patch to remove the issue code in improve_allocation. And extra a small case from 548.exchange2_r. Fortran small case: --------------------------------------- module a integer, parameter :: b = 3, d = b contains subroutine f(g, block) integer block(:, :, :), g(:, :) logical ac do h = 1, d do i = 1, d block = d block = 0 end do if (ac) then call j call k end if do e = 0, dh end do ac = .false. if (ao > 1) then if (ac) then else ac = .true. end if end if if (allg /= 0) exit end do contains subroutine k do e = 1, d end do end subroutine k subroutine j do bg = 0, c if (count(g == 0) == 3) cycle do ax = 1, dh if (bm() /= 3) cycle end do do l = 1, cycle do end do end do end do end subroutine j end subroutine f end module a -------------------------------------------- Before improve_allocation function: a537 (cost 1896, reg42) a20 (cost 270, reg1) a13 (cost 144, spill) a551 (cost 70, reg40) a5 (cost 43, spill) a493 (cost 30, reg42) a499 (cost 12, reg40) ------------------------------ Dump info in improve_allocation function: Base: Spilling a493r125 for a5r113 Spilling a573r202 for a5r113 Spilling a499r248 for a13r106 Spilling a551r120 for a13r106 Spilling a20r237 for a551r120 With patch: Spilling a499r248 for a13r106 Spilling a551r120 for a13r106 Spilling a493r125 for a551r120 ------------------------------ After assign_hard_reg (at the end of improve_allocation): Base: a537 (cost 1896, reg1) a20 (cost 270, spill) -----> This is unreasonable a13 (cost 144, reg40) a551 (cost 70, reg1) a5 (cost 43, reg42) a493 (cost 30, spill) a499 (cost 12, reg1) With patch: a537 (cost 1896, reg42) a20 (cost 270, reg1) a13 (cost 144, reg40) a551 (cost 70, reg42) a5 (cost 43, spill) a493 (cost 30, spill) a499 (cost 12, reg42) ----------------------------- Collected spec2017 performance on Znver3/Graviton4/EMR/SRF for O2 and Ofast. No performance regression was observed. FOR multi-copy O2 SRF: 548.exchange2_r increased by 7.5%, 500.perlbench_r increased by 2.0%. EMR: 548.exchange2_r increased by 4.5%, 500.perlbench_r increased by 1.7%. Graviton4: 548.exchange2_r Increased by 2.2%, 511.povray_r increased by 2.8%. Znver3 : 500.perlbench_r increased by 2.0%.