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

--- 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:459271227c094af5cc47ab429ed879bc5e9bc119

commit r17-6704-g459271227c094af5cc47ab429ed879bc5e9bc119
Author: Souradipto Das <[email protected]>
Date:   Wed Nov 25 16:32:40 2026 -0700

    [PATCH v3] ifcvt: Look through extraneous copy in noce_try_cond_arith
[PR122335]

    This patch helps the noce_try_cond_arith look through a copy insn
    which makes that block not simple, given that the else was simple
    in the first place. Only a single copy insn is looked through here
    so the insn where the copy's value is defined is the first insn in
    that block ignoring the note and debug insns. SET_SRC gets to the
    definition if all the conditions are satisfied and successfully
    looks through the copy.

    This patch relies on the liveness check on bb_valid_for_noce_process_p.
    I also included the PATTERN check so as to not drop a clobber along with
    the check that original destination is a register so that it cannot hold
    a reference to the dropped if_info->a.

    Bootstrapped and regtested in x86_64-pc-linux-gnu with no new fails
    except for gcc.target/i386/shift-gf2p8affine-2.c.It fails with SIGILL
    on my test machine, which lacks AVX512 (my earlier baseline was from
    a machine that had it), and it fails the same way without the patch.
    and I also ran the riscv.exp (compile tests) with -march=rv64gcb_zicond
    -mabi=lp64d and noticed no new fails.

    ---
    v2: https://gcc.gnu.org/pipermail/gcc-patches/2026-November/739349.html
    Changes in v3:
     -I looked into Sashiko's concerns about not checking if if_info->orig_x
referenced if_info->a.
      Even though I didn't find a testcase that can reproduce the error, I
still added the condition
      checking it from my reading of noce_process_if_block, as a defensive
check.
     -Added the check if_info->else_bb so as to not reject the blocks with no
else arm. (I did not find
      an input that reaches this case, the no-else shapes I tried are converted
earlier
      by noce_convert_multiple_sets.)
    **I am posting this v3 because I failed to address all the concerns of
Sashiko as Jeff suggested on v1's thread
    (as new concerns popped up on v2 from sashiko, because I changed the
position of the patch on v2 to make
    the change less destructive when it didn't have a clear optimization path).
Is this okay now?

            PR rtl-optimization/122335

    gcc/ChangeLog:

            * ifcvt.cc (noce_try_cond_arith): Made the function look through a
copy insn
            given the conditions passed.

    gcc/testsuite/ChangeLog:

            * gcc.target/riscv/pr122335-1.c : New Test.
            * gcc.target/riscv/pr122335-2.c : New Test which failed on v1.

    Signed-off-by: Souradipto Das <[email protected]>

Reply via email to