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

--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jeff Law <[email protected]>:

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

commit r17-6821-gd2ad1dba8cb9d4f2a6a585bf3abca6502300c393
Author: Jeff Law <[email protected]>
Date:   Sun Nov 29 17:24:21 2026 -0700

    [PR target/125167][RISC-V] Improve selects between 0/3, 0/5 and 0/9 for
RISC-V

    This is another small set of improvements to the RISC-V port.

    PR125167 describes a case of selects where we don't generate good code;
this
    patch targets 0/3, 0/5 and 0/9 which are naturals for taking the output of
an
    scc insn and using it as both source arguments to a shift-add pattern. 
This
    squashes out a few more million instructions from x264, mostly from one
    routine, with single digits hits in other places.  I'm sick of writing
patterns
    that only differ because of the limited forms of scc insns on RISC-V.

    This patch detects those as an if-then-else with one arm 0, the other 3, 5
or
    9.  It introduces a new operator predicate for scc insns we can implement
in a
    single insn -- that can probably be used to clean up other code in
zicond.md
    going forward, but that's not appropriate for stage3 IMHO.  However, there
are
    some in-flight things that might be able to make use of it, we'll see.

    Full disclosure, I did let Claude handle generation of the first prototype
    pattern and attempts to explore and generalize to other cases.  What's in
this
    patch is different in many ways from Claude's exploration efforts.  But the
    core pattern can only be written in a few ways and does look substantially
    close to what Claude generated.

    Assisted-By: Claude for discovery, testcase generation, early prototype
    solution.

    Tested on riscv32-elf and riscv64-elf.  Waiting on Sashiko before going
    forward.

            PR target/125167
    gcc
            * config/riscv/riscv-protos.h (riscv_flag_select_code): Prototype.
            * config/riscv/predicates.md (int_cmp_operator): New code iterator.
            * config/riscv/riscv.cc (riscv_single_scc_p): New function.
            (riscv_flag_select_code): New functio.
            * config/riscv/zicond.md: New splitter to optimize selecting across
            0/3, 0/5 and 0/9.

    gcc/testsuite
            * gcc.target/riscv/pr125167-1.c: New test.
            * gcc.target/riscv/pr125167-2.c: New test.
            * gcc.target/riscv/pr125167-3.c: New test.
            * gcc.target/riscv/pr125167-4.c: New test.

Reply via email to