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

--- 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:3db44cde59ea85c5f9bb9fb3ad7f775dc75ff578

commit r17-6807-g3db44cde59ea85c5f9bb9fb3ad7f775dc75ff578
Author: Jeff Law <[email protected]>
Date:   Sun Nov 29 10:10:45 2026 -0700

    [RISC-V][PR rtl-optimization/128448] Improve select between -1 and C for
RISC-V

    So this turned out to be simpler than I realized.

    When I first looked at this issue I concluded that there wasn't any viable
path
    forward for a define_split and as a result we were going to have to look at
a
    match.pd pattern or something in simplify-rtx.

    But upon re-review of the .combine dump I saw a 3->2 split when selecting
    across 0/-1.   That was enough to improve the sequence.  There's a handful
of
    generalizations.  It saves a few million instructions in x264, very much on
the
    marginal side by turning this:

    long f (int c) { return c ? -1 : 0x0202020202020202L; }

    li        a4,33685504
    addi      t0,a4,514
    slli      a5,t0,32
    add       t1,a5,t0
    li        t2,-1
    czero.nez a1,t1,a0
    czero.eqz a0,t2,a0
    add       a0,a0,a1

    Into this:

    li        a4,33685504
    addi      t0,a4,514
    slli      a5,t0,32
    add       t1,a5,t0
    czero.nez s6,s7,a2
    snez      t1,a2
    sub       t5,s6,t1

    I think this can be made to work in ifcvt.cc, but I'm hesitant to go down
that
    path due to the unresolved issues around pr126914.  Andrea's sequence might
be
    slightly better from an encoding standpoint (I didn't check) and doing this
in
    match.pd would help other targets, I'm not going to consider this BZ fully
    resolved.

    Anyway, tested on riscv32-elf, riscv64-elf.  RISC-V bootstraps are in
progress.
    Planning to commit once Sashiko renders its verdict.

    Assisted-By: Claude for assembly analysis to identify issue and testcase
generation.

            PR rtl-optimization/128448
    gcc/
            * config/riscv/zicond.md (-1/0 selector): New define_split.

    gcc/testsuite
            * gcc.target/riscv/pr128448.c: New test.

Reply via email to