On Fri, Aug 22, 2025 at 4:04 PM Andrew Pinski <andrew.pin...@oss.qualcomm.com> wrote: > > 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> > --- > gcc/passes.def | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/gcc/passes.def b/gcc/passes.def > index 68ce53baa0f..6349abb5360 100644 > --- a/gcc/passes.def > +++ b/gcc/passes.def > @@ -97,10 +97,10 @@ along with GCC; see the file COPYING3. If not see > NEXT_PASS (pass_dse); > NEXT_PASS (pass_cd_dce, false /* update_address_taken_p */, true /* > remove_unused_locals */); > NEXT_PASS (pass_phiopt, true /* early_p */); > + NEXT_PASS (pass_cleanup_eh);
Can you add a comment here indicating why we do this specifically before tail recursion? OK with that change. Richard. > NEXT_PASS (pass_tail_recursion); > NEXT_PASS (pass_if_to_switch); > NEXT_PASS (pass_convert_switch); > - NEXT_PASS (pass_cleanup_eh); > NEXT_PASS (pass_sccopy); > NEXT_PASS (pass_profile); > NEXT_PASS (pass_local_pure_const); > -- > 2.43.0 >