https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126912

--- Comment #7 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Andrea Pinski <[email protected]>:

https://gcc.gnu.org/g:d3481fc3f8746f823d9d4bc1fd0e5d4384d0fc37

commit r17-3999-gd3481fc3f8746f823d9d4bc1fd0e5d4384d0fc37
Author: Andrea Pinski <[email protected]>
Date:   Sun Aug 16 22:48:14 2026 -0700

    match: allow c variable for the code/operation of the result [PR126912]

    This allows a C variable for the code of the result
    to reduce how many for loops are needed and reduces the code size of
    the generated files by a factor of 6 (in some cases).
    This should allow for arm to build again at -O0.

    The way this is done is adding an optional part to the with expression
    which defines an C identifier (but not explictly in the C code).

    An example of this is:
    ```
    (for bitop (bit_and bit_ior bit_xor simple_comparison)
     (for cmp1 (tcc_comparison)
      (for cmp2 (tcc_comparison)
       (simplify
        (bitop (cmp1 @0 @1) (cmp2 @0 @1))
        (with rescmpcode (tcc_comparison)
          {
            tree_code rescmpcode;
            tree res;
            bool honor_nans = HONOR_NANS (@0);
            rescmpcode = combine_comparisons (bitop, cmp1, cmp2,
                                              type, honor_nans, &res);
          }
         (if (rescmpcode == INTEGER_CST)
          { res; }
          (if (TREE_CODE_CLASS (rescmpcode) == tcc_comparison)
           (rescmpcode @0 @1))))))))
    ```
    For comparisons with combine_comparisons/invert_comparisons we would
    need to have one more for loop and that would cause an explosion of code.

    Changes since v2:
    * v3: changed syntax to be explict define the operator rather than
implicit.

    Bootstrapped and tested on x86_64-linux-gnu.

            PR middle-end/126912
    gcc/ChangeLog:

            * doc/match-and-simplify.texi: Document new
            with optional operands.
            * genmatch.cc (fprint_indent): New function.
            (class c_code_id): New class.
            (c_code_id::gen_checking): New mthod.
            (get_operator): For c_code_id, mark it as used too.
            (lower_for): Treat c_code_id like a function.
            (get_operand_type): Handle c_code_id with cmps
            set as a comparison.
            (expr::gen_transform): Likewise.
            Call gen_checking for c_code_id and handle
            c_code_id for generic for function and tree code case.
            (dt_simplify::gen_1): Handle c_code_id.
            (parser::parse_c_with_ids): New method.
            (parser::parse_result): Handle optional part of with.
            * match.pd (`(a CMP1 b) bitop (a CMP2 b)`): Remove rcmp
            loop and update for the new syntax.
            (other comparison loops): Update for the new syntax.

    Signed-off-by: Andrea Pinski <[email protected]>

Reply via email to