On Tue, 21 Jul 2026, Richard Biener wrote:

> The following makes the recognized INSN_CODEs available to the
> backends for costing via insn_cost.
> 
> Bootstrap and regtest running on x86_64-unknown-linux-gnu.

Passed without regressions.

> I have not tried to follow the maze of recog calls in try_combine
> to validate that the three INSN_CODE variables line up with
> the insns costed in combine_validate_cost, but for the single
> i2->i3 combination I looked at it works out.

I used an artificial alternate of myself and that assesses
"Exhaustive tracing of the combine.cc source code confirms that no
mismatch between instruction patterns and INSN_CODEs exists between
combine_validate_cost and try_combine. The instruction codes and 
patterns are
kept in perfect, pairwise lockstep throughout every potential path in
try_combine leading up to the cost-validation check."

> IMO calling insn_cost on a non recognized (aka possibly unrecognizable)
> insn doesn't make much sense.
> 
> OK?  Or am I on the wrong track?

OK for trunk?

Thanks,
Richard.

> Thanks,
> Richard.
> 
>       PR target/126328
>       * combine.cc (combine_validate_cost): New arguments for
>       the insn codes.  Set INSN_CODE to recognized values
>       before calling insn_cost.
>       (try_combine): Adjust.
> ---
>  gcc/combine.cc | 13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)
> 
> diff --git a/gcc/combine.cc b/gcc/combine.cc
> index 53ea168a44b..0711db3f9a6 100644
> --- a/gcc/combine.cc
> +++ b/gcc/combine.cc
> @@ -825,7 +825,8 @@ do_SUBST_LINK (struct insn_link **into, struct insn_link 
> *newval)
>  
>  static bool
>  combine_validate_cost (rtx_insn *i0, rtx_insn *i1, rtx_insn *i2, rtx_insn 
> *i3,
> -                    rtx newpat, rtx newi2pat, rtx newotherpat)
> +                    rtx newpat, rtx newi2pat, rtx newotherpat,
> +                    int insn_code, int i2_code, int other_code)
>  {
>    int i0_cost, i1_cost, i2_cost, i3_cost;
>    int new_i2_cost, new_i3_cost;
> @@ -867,7 +868,7 @@ combine_validate_cost (rtx_insn *i0, rtx_insn *i1, 
> rtx_insn *i2, rtx_insn *i3,
>    rtx tmp = PATTERN (i3);
>    PATTERN (i3) = newpat;
>    int tmpi = INSN_CODE (i3);
> -  INSN_CODE (i3) = -1;
> +  INSN_CODE (i3) = insn_code;
>    new_i3_cost = insn_cost (i3, optimize_this_for_speed_p);
>    PATTERN (i3) = tmp;
>    INSN_CODE (i3) = tmpi;
> @@ -876,7 +877,7 @@ combine_validate_cost (rtx_insn *i0, rtx_insn *i1, 
> rtx_insn *i2, rtx_insn *i3,
>        tmp = PATTERN (i2);
>        PATTERN (i2) = newi2pat;
>        tmpi = INSN_CODE (i2);
> -      INSN_CODE (i2) = -1;
> +      INSN_CODE (i2) = i2_code;
>        new_i2_cost = insn_cost (i2, optimize_this_for_speed_p);
>        PATTERN (i2) = tmp;
>        INSN_CODE (i2) = tmpi;
> @@ -897,7 +898,7 @@ combine_validate_cost (rtx_insn *i0, rtx_insn *i1, 
> rtx_insn *i2, rtx_insn *i3,
>        tmp = PATTERN (undobuf.other_insn);
>        PATTERN (undobuf.other_insn) = newotherpat;
>        tmpi = INSN_CODE (undobuf.other_insn);
> -      INSN_CODE (undobuf.other_insn) = -1;
> +      INSN_CODE (undobuf.other_insn) = other_code;
>        new_other_cost = insn_cost (undobuf.other_insn,
>                                 optimize_this_for_speed_p);
>        PATTERN (undobuf.other_insn) = tmp;
> @@ -4134,7 +4135,9 @@ try_combine (rtx_insn *i3, rtx_insn *i2, rtx_insn *i1, 
> rtx_insn *i0,
>  
>    /* Reject this combination if insn_cost reports that the replacement
>       instructions are more expensive than the originals.  */
> -  if (!combine_validate_cost (i0, i1, i2, i3, newpat, newi2pat, other_pat))
> +  if (!combine_validate_cost (i0, i1, i2, i3, newpat, newi2pat, other_pat,
> +                           insn_code_number, i2_code_number,
> +                           other_code_number))
>      {
>        undo_all ();
>        return 0;
> 

-- 
Richard Biener <[email protected]>
SUSE Software Solutions Germany GmbH,
Frankenstrasse 146, 90461 Nuernberg, Germany;
GF: Jochen Jaser, Andrew McDonald, Abhinav Puri; (HRB 36809, AG Nuernberg)

Reply via email to