https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115201
--- Comment #12 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Andrew Pinski <pins...@gcc.gnu.org>: https://gcc.gnu.org/g:6750f5902c600907a56b9a72b4bae7d9762515c9 commit r16-3443-g6750f5902c600907a56b9a72b4bae7d9762515c9 Author: Andrew Pinski <andrew.pin...@oss.qualcomm.com> Date: Thu Aug 21 21:37:59 2025 -0700 passes: Move cleanup_eh before first tailr [PR115201] So the current pass order is: ``` NEXT_PASS (pass_tail_recursion); NEXT_PASS (pass_if_to_switch); NEXT_PASS (pass_convert_switch); NEXT_PASS (pass_cleanup_eh); ``` But nothing in if_to_switch nor convert_switch will change the IR such that cleanup eh will take into account. tail_recusion benifits the most by not having "almost" empty landing pads. This order was originally done when cleanup_eh was added in r0-92178-ga8da523f8a442f but it looks like it was just done just before inlining rather than thinking it could improve passes before hand. An example where this helps is PR 115201 where we have: ``` ;; basic block 5, loop depth 0, maybe hot ;; prev block 4, next block 6, flags: (NEW, REACHABLE, VISITED) ;; pred: 4 (TRUE_VALUE,EXECUTABLE) [LP 1] # .MEM_19 = VDEF <.MEM_45> # USE = nonlocal escaped # CLB = nonlocal escaped D.4770 = _Z12binarySearchIi2itIiEET0_RKT_S2_S2_D.4690 (item_15(D), startD.4711, midD.4717); goto <bb 7>; [INV] ;; succ: 8 (EH,EXECUTABLE) ;; 7 (FALLTHRU,EXECUTABLE) ... ;; basic block 8, loop depth 0, maybe hot ;; prev block 7, next block 1, flags: (NEW, REACHABLE, VISITED) ;; pred: 5 (EH,EXECUTABLE) ;; 6 (EH,EXECUTABLE) # .MEM_7 = PHI <.MEM_19(5), .MEM_18(6)> <L6>: [LP 1] # .MEM_20 = VDEF <.MEM_7> midD.4717 ={v} {CLOBBER(eos)}; resx 1 ;; succ: ``` As you can see the empty landing pad should be able to remove away and then a tail recursion can happen. Bootstrapped and tested x86_64-linux-gnu. PR tree-optimization/115201 gcc/ChangeLog: * passes.def: Move cleanup_eh before first tail_recursion. Signed-off-by: Andrew Pinski <andrew.pin...@oss.qualcomm.com>