]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
RISC-V: Correct lmul estimation
authorZhongyao Chen <chenzhongyao.hit@gmail.com>
Thu, 18 Sep 2025 15:31:18 +0000 (09:31 -0600)
committerJeff Law <jlaw@ventanamicro.com>
Thu, 18 Sep 2025 15:32:20 +0000 (09:32 -0600)
The vectorizer's compute_estimated_lmul function could previously
return a bad value when the estimated lmul was larger than RVV_M8.
This is corrected to return RVV_M8, preventing a register spill.

The patch includes a new regression test for PR target/121910, based
on the x264 mc_chroma function. The test uses scan-tree-dump to
confirm that the compiler chooses the expected vector mode (RVVM1QI)
at -O3, verifying the fix.

PR target/121910
gcc/ChangeLog:

* config/riscv/riscv-vector-costs.cc (compute_estimated_lmul):
Return RVV_M8 when estimated lmul is too large.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/pr121910.c: New file.

gcc/config/riscv/riscv-vector-costs.cc
gcc/testsuite/gcc.target/riscv/rvv/autovec/pr121910.c [new file with mode: 0644]

index 5e6cb671490ca3b2a415b4ba10efb067f61e766a..27ced61e815d43b8b622764fa6fa9d485e71cb46 100644 (file)
@@ -632,7 +632,7 @@ compute_estimated_lmul (loop_vec_info loop_vinfo, machine_mode mode)
       int estimated_lmul = estimated_vf * GET_MODE_BITSIZE (mode).to_constant ()
                           / TARGET_MIN_VLEN;
       if (estimated_lmul > RVV_M8)
-       return regno_alignment;
+       return RVV_M8;
       else
        return estimated_lmul;
     }
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr121910.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr121910.c
new file mode 100644 (file)
index 0000000..024aae3
--- /dev/null
@@ -0,0 +1,34 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -ftree-vectorize -mabi=lp64d -march=rv64gcv -mrvv-max-lmul=dynamic -fdump-tree-vect-all" } */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-O2" "-Os" "-Og" "-Oz" } } */
+
+#include <stdint-gcc.h>
+
+/* full chroma mc (ie until 1/8 pixel)*/
+void mc_chroma(uint8_t* dst, int i_dst_stride, uint8_t* src, int i_src_stride,
+               int mvx, int mvy, int i_width, int i_height) {
+    uint8_t* srcp;
+
+    int d8x = mvx & 0x07;
+    int d8y = mvy & 0x07;
+    int cA = (8 - d8x) * (8 - d8y);
+    int cB = d8x * (8 - d8y);
+    int cC = (8 - d8x) * d8y;
+    int cD = d8x * d8y;
+
+    src += (mvy >> 3) * i_src_stride + (mvx >> 3);
+    srcp = &src[i_src_stride];
+
+    for (int y = 0; y < i_height; y++) {
+        for (int x = 0; x < i_width; x++)
+            dst[x] = (cA * src[x] + cB * src[x + 1] + cC * srcp[x] +
+                      cD * srcp[x + 1] + 32) >>
+                     6;
+        dst += i_dst_stride;
+        src = srcp;
+        srcp += i_src_stride;
+    }
+}
+
+/* { dg-final { scan-tree-dump "LOOP VECTORIZED" "vect" } } */
+/* { dg-final { scan-tree-dump "Choosing vector mode RVVM1QI" "vect" } } */