https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129161
Bug ID: 129161
Summary: Improve conditional move support for RISC-V
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: rtl-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: law at gcc dot gnu.org
Target Milestone: ---
If we have a select across two values where the selector is not a single insn,
then RISC-V will tend to emit less than ideal code. Consider this:
long
f (int x, long a, long b)
{
return x > 2 ? a : b;
}
RISC-V can't implement the x > 2 test in a single insn, so we get:
li a5,2
sgt t0,a0,a5
czero.nez a1,a1,t0
czero.eqz t1,a2,t0
add a0,t1,a1
We could invert the condition and swap the operands which would allow us to
generate:
slti a0, a0, 3
czero.eqz a1, a1, a0
czero.nez a0, a2, a0
add a0, a0, a1
This really isn't viable as a combiner pattern. It'd be 5->4, so no. We can't
see the "2" in the conditional move expander, though we could in theory loosen
the operand predicates which would allow us to make better decisions about the
condition.
We might be able to do better up in gimple, but it's far from guaranteed that
would make things better.
Anyway, just getting this recorded.