> -----Original Message----- > From: Richard Biener <[email protected]> > Sent: Friday, September 11, 2026 4:03 PM > To: xiezhiheng <[email protected]> > Cc: [email protected] > Subject: Re: [PATCH] sched: Change max_lookahead_tries type to int64_t > > On Fri, Sep 11, 2026 at 9:45 AM xiezhiheng <[email protected]> wrote: > > > > Thanks, could you please help push the patch, since I do not have write > > access. > > On a 2nd thought, re-trying that many times doesn't make much sense, so can > you rework to only aovid the overflow when computing max_lookahead_tries. > Your original patch is almost OK for that, but the artificial number > 10000 should > instead be INT_MAX I think. The int64_t can still overflow, so possibly break > from the loop when max_tries > INT_MAX.
Sure, the new patch is attached below.
Bootstrapped and tested on aarch64-linux-gnu and x86_64-linux-gnu, no
regression.
Issue_rate values on modern cores keep increasing, and the maximum
issue_rate in the AArch64 backend has reached 10, causing an overflow
in the calculation of max_lookahead_tries. Fix it.
gcc/ChangeLog:
* haifa-sched.cc (max_issue): Cap max_lookahead_tries
---
gcc/haifa-sched.cc | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/gcc/haifa-sched.cc b/gcc/haifa-sched.cc
index 879749e9785..17457dd0ac4 100644
--- a/gcc/haifa-sched.cc
+++ b/gcc/haifa-sched.cc
@@ -5956,9 +5956,14 @@ max_issue (struct ready_list *ready, int privileged_n,
state_t state,
/* Init MAX_LOOKAHEAD_TRIES. */
if (max_lookahead_tries == 0)
{
- max_lookahead_tries = 100;
+ int64_t max_tries = 100;
for (i = 0; i < issue_rate; i++)
- max_lookahead_tries *= dfa_lookahead;
+ {
+ max_tries *= dfa_lookahead;
+ if (max_tries > INT_MAX)
+ break;
+ }
+ max_lookahead_tries = MIN (max_tries, INT_MAX);
}
/* Init max_points. */
@@ -6054,7 +6059,9 @@ max_issue (struct ready_list *ready, int privileged_n,
state_t state,
else if (!ready_try [i])
{
tries_num++;
- if (tries_num > max_lookahead_tries)
+ /* max_lookahead_tries is capped at INT_MAX, use the >= comparison
+ to prevent tries_num from overflowing. */
+ if (tries_num >= max_lookahead_tries)
break;
insn = ready_element (ready, i);
delay = state_transition (state, insn);
--
2.43.0
>
> Thanks,
> Richard.
>
> > From: Richard Biener<[email protected]>
> > To: xiezhiheng<[email protected]>
> > Cc: [email protected]
> > Subject: Re: [PATCH] sched: Change max_lookahead_tries type to int64_t
> > Time: 2026-09-11 14:33:54
> >
> > On Fri, Sep 11, 2026 at 5:13 AM xiezhiheng <[email protected]> wrote:
> > >
> > > As mentioned in
> > > https://gcc.gnu.org/pipermail/gcc-patches/2026-September/730781.html,
> > > issue_rate values on modern cores keep increasing, and the maximum
> > > issue_rate in the AArch64 backend has reached 10, causing an overflow
> > > in the calculation of max_lookahead_tries. Change its type to int64_t.
> > >
> > > Bootstrapped and tested on aarch64-linux-gnu and x86_64-linux-gnu, no
> > > regression.
> >
> > OK.
> >
> > > gcc/ChangeLog:
> > >
> > > * haifa-sched.cc (max_issue): Change max_lookahead_tries type to
> > > int64_t
> > > ---
> > > gcc/haifa-sched.cc | 5 +++--
> > > 1 file changed, 3 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/gcc/haifa-sched.cc b/gcc/haifa-sched.cc
> > > index 879749e9785..733a83034bf 100644
> > > --- a/gcc/haifa-sched.cc
> > > +++ b/gcc/haifa-sched.cc
> > > @@ -5921,7 +5921,7 @@ int dfa_lookahead;
> > > might be incomplete and such insn might occur. For such
> > > descriptions, the complexity of algorithm (without the constraint)
> > > could achieve DFA_LOOKAHEAD ** N , where N is the queue length. */
> > > -static int max_lookahead_tries;
> > > +static int64_t max_lookahead_tries;
> > >
> > > /* The following function returns maximal (or close to maximal) number
> > > of insns which can be issued on the same cycle and one of which
> > > @@ -5941,8 +5941,9 @@ int
> > > max_issue (struct ready_list *ready, int privileged_n, state_t state,
> > > bool first_cycle_insn_p, int *index)
> > > {
> > > - int n, i, all, n_ready, best, delay, tries_num;
> > > + int n, i, all, n_ready, best, delay;
> > > int more_issue;
> > > + int64_t tries_num;
> > > struct choice_entry *top;
> > > rtx_insn *insn;
> > >
> > > --
> > > 2.43.0
> > >
0001-sched-Cap-max_lookahead_tries.patch
Description: 0001-sched-Cap-max_lookahead_tries.patch
