[PR target/113001] Fix incorrect operand swapping in conditional move
commit10cbfcd60f9e5bdbe486e1c0192e0f168d899b77
authorJeff Law <jlaw@ventanamicro.com>
Wed, 6 Mar 2024 16:50:44 +0000 (6 09:50 -0700)
committerJeff Law <jlaw@ventanamicro.com>
Wed, 6 Mar 2024 16:58:20 +0000 (6 09:58 -0700)
tree4413e8393700bb3edcfbe4d731e06e1179ef7e23
parent93e1d4d24ed014387da97e2ce11556d68fe98e66
[PR target/113001] Fix incorrect operand swapping in conditional move

This bug totally fell off my radar.  Sorry about that.

We have some special casing the conditional move expander to simplify a
conditional move when comparing a register against zero and that same register
is one of the arms.

Specifically a (eq (reg) (const_int 0)) where reg is also the true arm or (ne
(reg) (const_int 0)) where reg is the false arm need not use the fully
generalized conditional move, thus saving an instruction for those cases.

In the NE case we swapped the operands, but didn't swap the condition, which
led to the ICE due to an unrecognized pattern.  THe backend actually has
distinct patterns for those two cases.  So swapping the operands is neither
needed nor advisable.

Regression tested on rv64gc and verified the new tests pass.

Pushing to the trunk.

PR target/113001
PR target/112871
gcc/
* config/riscv/riscv.cc (expand_conditional_move): Do not swap
operands when the comparison operand is the same as the false
arm for a NE test.

gcc/testsuite
* gcc.target/riscv/zicond-ice-3.c: New test.
* gcc.target/riscv/zicond-ice-4.c: New test.
gcc/config/riscv/riscv.cc
gcc/testsuite/gcc.target/riscv/zicond-ice-3.c [new file with mode: 0644]
gcc/testsuite/gcc.target/riscv/zicond-ice-4.c [new file with mode: 0644]