On 1/7/24 17:06, Maciej W. Rozycki wrote:
Complement commit c1e8cb3d9f94 ("RISC-V: Rework branch costing model for
if-conversion") and also handle extraneous sign extend operations that
are sometimes produced by `noce_try_cmove_arith' instead of zero extend
operations, making branch costing consistent.  It is unclear what the
condition is for the middle end to choose between the zero extend and
sign extend operation, but the test case included uses sign extension
with 64-bit targets, preventing if-conversion from triggering across all
the architectural variants.

There are further anomalies revealed by the test case, specifically the
exceedingly high branch cost of 6 required for the `-mmovcc' variant
despite that the final branchless sequence only uses 4 instructions, the
missed conversion at -O1 for 32-bit targets even though code is machine
word size agnostic, and the missed conversion at -Os and -Oz for 32-bit
Zicond targets even though the branchless sequence would be shorter than
the branched one.  These will have to be handled separately.

        gcc/
        * config/riscv/riscv.cc (riscv_noce_conversion_profitable_p):
        Also handle sign extension.

        gcc/testsuite/
        * gcc.target/riscv/cset-sext-sfb.c: New test.
        * gcc.target/riscv/cset-sext-thead.c: New test.
        * gcc.target/riscv/cset-sext-ventana.c: New test.
        * gcc.target/riscv/cset-sext-zicond.c: New test.
        * gcc.target/riscv/cset-sext.c: New test.
---
Hi,

  This is still in regression-testing, but as a branch costing adjustment
only I don't expect any code correctness issues, and the performance
advantage seems very obvious as the sign extend operation applied to the
result of a conditional set instruction is always a no-op, just as with
the zero extension.

  Depending on how you look at it you may qualify this as a bug fix (for
the commit referred; it's surely rare enough a case I missed in original
testing) or a missed optimisation.  Either way it's a narrow-scoped very
small change, almost an obviously correct one.  I'll be very happy to get
it off my plate now, but if it has to wait for GCC 15, I'll accept the
decision.

  OK to apply then or shall I wait?
OK to apply.

jeff

Reply via email to