[gcc(refs/vendors/riscv/heads/gcc-15-with-riscv-opts)] [to-be-committed][RISC-V] Handle 32bit operands in condition for conditional moves
Jeff Law
law@gcc.gnu.org
Sat Sep 13 16:14:15 GMT 2025
https://gcc.gnu.org/g:0c20acfa89617aec33000027503f0810a91be5b2
commit 0c20acfa89617aec33000027503f0810a91be5b2
Author: Jeff Law <jlaw@ventanamicro.com>
Date: Sat Jun 7 07:48:46 2025 -0600
[to-be-committed][RISC-V] Handle 32bit operands in condition for conditional moves
So here's the next chunk of conditional move work from Shreya.
It's been a long standing wart that the conditional move expander does not
support sub-word operands in the comparison. Particularly since we have
support routines to handle the necessary extensions for that case.
This patch adjusts the expander to use riscv_extend_comparands rather than fail
for that case. I've built spec2017 before/after this and we definitely get
more conditional moves and they look sensible from a performance standpoint.
None are likely hitting terribly hot code, so I wouldn't expect any performance
jumps.
Waiting on pre-commit testing to do its thing.
* config/riscv/riscv.cc (riscv_expand_conditional_move): Use
riscv_extend_comparands to extend sub-word comparison arguments.
Co-authored-by: Jeff Law <jlaw@ventanamicro.com>
(cherry picked from commit 59a3da733a79f621700dd9ddc11a0efc07237c3a)
Diff:
---
gcc/config/riscv/riscv.cc | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 3b7e5cbf5ac4..8aa02110b682 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -5437,13 +5437,18 @@ riscv_expand_conditional_move (rtx dest, rtx op, rtx cons, rtx alt)
machine_mode mode0 = GET_MODE (op0);
machine_mode mode1 = GET_MODE (op1);
- /* An integer comparison must be comparing WORD_MODE objects. We
- must enforce that so that we don't strip away a sign_extension
- thinking it is unnecessary. We might consider using
- riscv_extend_operands if they are not already properly extended. */
+ /* An integer comparison must be comparing WORD_MODE objects.
+ Extend the comparison arguments as necessary. */
if ((INTEGRAL_MODE_P (mode0) && mode0 != word_mode)
|| (INTEGRAL_MODE_P (mode1) && mode1 != word_mode))
- return false;
+ riscv_extend_comparands (code, &op0, &op1);
+
+ /* We might have been handed back a SUBREG. Just to make things
+ easy, force it into a REG. */
+ if (!REG_P (op0) && !CONST_INT_P (op0))
+ op0 = force_reg (word_mode, op0);
+ if (!REG_P (op1) && !CONST_INT_P (op1))
+ op1 = force_reg (word_mode, op1);
/* In the fallback generic case use MODE rather than WORD_MODE for
the output of the SCC instruction, to match the mode of the NEG
More information about the Gcc-cvs
mailing list