]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[RISC-V][PR target/125152] Don't use stale mode in conditional move expansion
authorJeff Law <jeffrey.law@oss.qualcomm.com>
Sun, 3 May 2026 01:33:35 +0000 (19:33 -0600)
committerJeff Law <jeffrey.law@oss.qualcomm.com>
Sun, 3 May 2026 01:33:35 +0000 (19:33 -0600)
This is a trivial oversight in the recently added improvement to conditional
move generation on the RISC-V port.

We have a step which canonicalizes the comparison operands. The process of
canonicalizing may change one or both operands, including giving a new pseudo
with a different mode.

The new code failed to account for that and as a result it was using a stale
mode (QI) which caused all kinds of problems later. Just swapping the code
which canonicalizes the operand with the code that extracts the mode and
everything is happy again.  Fixed a formatting nit while I was in there.

Tested on riscv32-elf and riscv64-elf.  But waiting for pre-commit CI to do its
thing.

PR target/125152
gcc/
* config/riscv/riscv.cc (riscv_expand_conditional_move): Extract the
mode after operand canonicalization.

gcc/testsuite/

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

gcc/config/riscv/riscv.cc
gcc/testsuite/gcc.target/riscv/pr125152.c [new file with mode: 0644]

index baa0de22de147b3d5f27be73b99eb8d4eb582a34..3fae7b5b9f06cfc7b35649ab51a889115a8bb159 100644 (file)
@@ -5828,10 +5828,9 @@ riscv_expand_conditional_move (rtx dest, rtx op, rtx cons, rtx alt)
        && GET_MODE_CLASS (cond_mode) == MODE_INT)
        || TARGET_COND_MOV)
     {
+      canonicalize_comparands (code, &op0, &op1);
       machine_mode mode0 = GET_MODE (op0);
 
-      canonicalize_comparands (code,&op0,&op1);
-
       /* In the fallback generic case use DST_MODE rather than WORD_MODE
         for the output of the SCC instruction, to match the mode of the NEG
         operation below.  The output of SCC is 0 or 1 boolean, so it is
diff --git a/gcc/testsuite/gcc.target/riscv/pr125152.c b/gcc/testsuite/gcc.target/riscv/pr125152.c
new file mode 100644 (file)
index 0000000..a44e341
--- /dev/null
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-mmovcc -std=gnu99" } */
+
+typedef __attribute__((__vector_size__(16))) char V;
+V v;
+char c;
+
+void
+foo()
+{
+  v |= (V){4} > c;
+}