]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
RISC-V: update prepare_ternary_operands to handle vector-scalar case [PR120828]
authorPaul-Antoine Arras <parras@baylibre.com>
Wed, 25 Jun 2025 16:42:00 +0000 (16:42 +0000)
committerPaul-Antoine Arras <parras@baylibre.com>
Thu, 26 Jun 2025 14:46:21 +0000 (14:46 +0000)
This is a followup to 92e1893e0 "RISC-V: Add patterns for vector-scalar
multiply-(subtract-)accumulate" that caused an ICE in some cases where the mult
operands were wrongly swapped.
This patch ensures that operands are not swapped in the vector-scalar case.

PR target/120828

gcc/ChangeLog:

* config/riscv/riscv-v.cc (prepare_ternary_operands): Handle the
vector-scalar case.

gcc/config/riscv/riscv-v.cc

index 45dd9256d020d8c4814939f027ed298601eead72..a3d704e81cc4338e416620e4a9863c747dea5402 100644 (file)
@@ -4723,7 +4723,7 @@ prepare_ternary_operands (rtx *ops)
                                   ops[4], ops[1], ops[6], ops[7], ops[9]));
       ops[5] = ops[4] = ops[0];
     }
-  else
+  else if (VECTOR_MODE_P (GET_MODE (ops[2])))
     {
       /* Swap the multiplication ops if the fallback value is the
         second of the two.  */
@@ -4733,8 +4733,10 @@ prepare_ternary_operands (rtx *ops)
       /* TODO: ??? Maybe we could support splitting FMA (a, 4, b)
         into PLUS (ASHIFT (a, 2), b) according to uarchs.  */
     }
-  gcc_assert (rtx_equal_p (ops[5], RVV_VUNDEF (mode))
-             || rtx_equal_p (ops[5], ops[2]) || rtx_equal_p (ops[5], ops[4]));
+  gcc_assert (
+    rtx_equal_p (ops[5], RVV_VUNDEF (mode)) || rtx_equal_p (ops[5], ops[2])
+    || (!VECTOR_MODE_P (GET_MODE (ops[2])) && rtx_equal_p (ops[5], ops[3]))
+    || rtx_equal_p (ops[5], ops[4]));
 }
 
 /* Expand VEC_MASK_LEN_{LOAD_LANES,STORE_LANES}.  */