]> git.ipfire.org Git - thirdparty/gcc.git/commit
ifcvt: cond zero arith: elide short forward branch for signed GE 0 comparison [PR122769]
authorVineet Gupta <vineetg@rivosinc.com>
Mon, 22 Dec 2025 16:54:06 +0000 (08:54 -0800)
committerVineet Gupta <vineetg@rivosinc.com>
Mon, 22 Dec 2025 17:11:32 +0000 (09:11 -0800)
commit2a84a753afcf376a5fc0339c5ce228c130000cd7
tree71b2ea2b09d4bc4fd1e6a0be6e854236424ccd9d
parent817b03a2fb85cb6a934b06122ca261b07b70b824
ifcvt: cond zero arith: elide short forward branch for signed GE 0 comparison [PR122769]

             Before            After
      ---------------------+----------------------
        bge a0,zero,.L2    | slti      a0,a0,0
                           | czero.eqz a0,a0,a0
        xor a1,a1,a3       | xor       a0,a0,a0
      .L2                  |
        mv  a0,a1          |
        ret                | ret

This is what all the prev NFC patches have been preparing to get to.

Currently the cond arith code only handles EQ/NE zero conditions missing
ifcvt optimization for cases such as GE zero, as show in example above.
This is due to the limitation of noce_emit_czero () so switch to
noce_emit_cmove () which can handle conditions other than EQ/NE and
if needed generate additional supporting insns such as SLT.

This also allows us to remove the constraint at the entry to limit to EQ/NE
conditions, improving ifcvt outcomes in general.

PR target/122769

gcc/ChangeLog:

* ifcvt.cc (noce_try_cond_zero_arith): Use noce_emit_cmove.
Delete noce_emit_czero () no longer used.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/pr122769.c: New test.

Co-authored-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
Signed-off-by: Vineet Gupta <vineetg@rivosinc.com>
gcc/ifcvt.cc
gcc/testsuite/gcc.target/riscv/pr122769.c [new file with mode: 0644]