]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
LoongArch: Add support for the TARGET_MODES_TIEABLE_P vectorization type.
authorchenxiaolong <chenxiaolong@loongson.cn>
Thu, 11 Dec 2025 02:49:05 +0000 (10:49 +0800)
committerLulu Cheng <chenglulu@loongson.cn>
Thu, 18 Dec 2025 09:08:56 +0000 (17:08 +0800)
v1->v2:
Add the TARGET_MODES_TIEABLE_P function description and analyze the
reasons for the cost change of Subreg type rtx after supporting
vectorization.

This hook returns true if a value of mode mode1 is accessible in mode
mode2 without copying. On LA, for vector types V4SF and V8SF, the lower
128 bit data can be shared. After adding vector support in this hook,
the cost of type conversion for the subreg operation from the V4SF to
the V8SF registers can be made zero, and some rtx optimization
operations can be completed in the combine traversal. The comparison
of the backend support vectors before and after is as follows:

support before:

(insn 7 4 9 2 (set (reg:V8SF 82 [ _6 ])
        (subreg:V8SF (reg:V4SF 86 [ aD.7906 ]) 0))
(insn 9 7 10 2 (set (reg:V8SF 80 [ _4 ])
        (plus:V8SF (reg:V8SF 82 [ _6 ])
            (reg:V8SF 82 [ _6 ])))

===>

support after:

(insn 9 7 10 2 (set (reg:V8SF 80 [ _4 ])
        (plus:V8SF (subreg:V8SF (reg:V4SF 86 [ aD.7906 ]) 0)
            (subreg:V8SF (reg:V4SF 86 [ aD.7906 ]) 0)))

gcc/ChangeLog:

* config/loongarch/loongarch.cc (loongarch_modes_tieable_p):
Add support for vector conversion.

gcc/testsuite/ChangeLog:

* gcc.target/loongarch/vector/lasx/vect-extract-256-128.c:
After supporting the vectorized type corresponding to subreg in
the backend, the cost of rtx becomes 0. In fwprop1 pass,
memory-loaded rtx cannot be propagated to this insn, which leads
to xvld not being optimized into vld instructions.
* gcc.target/loongarch/vect-mode-tieable.c: New test.

gcc/config/loongarch/loongarch.cc
gcc/testsuite/gcc.target/loongarch/vect-mode-tieable.c [new file with mode: 0644]
gcc/testsuite/gcc.target/loongarch/vector/lasx/vect-extract-256-128.c

index cc0523f2ab72fbb2cc8d6ee5d285ef21fd9683e7..06d0dcc5efdabb8dc226e25b1656c4fc9b6d9441 100644 (file)
@@ -7514,7 +7514,11 @@ loongarch_modes_tieable_p (machine_mode mode1, machine_mode mode2)
          || (GET_MODE_CLASS(mode1) == MODE_FLOAT
              && GET_MODE_CLASS(mode2) == MODE_INT)
          || (GET_MODE_CLASS(mode2) == MODE_FLOAT
-             && GET_MODE_CLASS(mode1) == MODE_INT));
+             && GET_MODE_CLASS(mode1) == MODE_INT)
+         || (GET_MODE_CLASS (mode1) == MODE_VECTOR_INT
+             && GET_MODE_CLASS (mode2) == MODE_VECTOR_INT)
+         || (GET_MODE_CLASS (mode1) == MODE_VECTOR_FLOAT
+             &&  GET_MODE_CLASS (mode2) == MODE_VECTOR_FLOAT));
 }
 
 /* Implement TARGET_PREFERRED_RELOAD_CLASS.  */
diff --git a/gcc/testsuite/gcc.target/loongarch/vect-mode-tieable.c b/gcc/testsuite/gcc.target/loongarch/vect-mode-tieable.c
new file mode 100644 (file)
index 0000000..d156f92
--- /dev/null
@@ -0,0 +1,47 @@
+/* { dg-do compile { target { loongarch64*-*-* } } } */
+/* { dg-options "-mabi=lp64d -O2 -mlasx" } */
+/* { dg-final { check-function-bodies "**" "" } } */
+
+#include <lasxintrin.h>
+
+/*
+**foo1:
+**     vinsgr2vr.d     (\$vr[0-9]+),\$r5,0
+**     vinsgr2vr.d     (\$vr[0-9]+),\$r6,1
+**     xvadd.d (\$xr[0-9]+),(\$xr[0-9]+),(\$xr[0-9]+)
+**     xvst    (\$xr[0-9]+),\$r4,0
+**     jr      \$r1
+*/
+__m256i
+foo1 (__m128i a)
+{
+  return __lasx_xvadd_d (__lasx_cast_128 (a), __lasx_cast_128 (a));
+}
+
+/*
+**foo2:
+**     vinsgr2vr.d     (\$vr[0-9]+),\$r5,0
+**     vinsgr2vr.d     (\$vr[0-9]+),\$r6,1
+**     xvfadd.s        (\$xr[0-9]+),(\$xr[0-9]+),(\$xr[0-9]+)
+**     xvst    (\$xr[0-9]+),\$r4,0
+**     jr      \$r1
+*/
+__m256
+foo2 (__m128 a)
+{
+  return __lasx_xvfadd_s (__lasx_cast_128_s (a), __lasx_cast_128_s (a));
+}
+
+/*
+**foo3:
+**     vinsgr2vr.d     (\$vr[0-9]+),\$r5,0
+**     vinsgr2vr.d     (\$vr[0-9]+),\$r6,1
+**     xvfadd.d        (\$xr[0-9]+),(\$xr[0-9]+),(\$xr[0-9]+)
+**     xvst    (\$xr[0-9]+),\$r4,0
+**     jr      \$r1
+*/
+__m256d
+foo3 (__m128d a)
+{
+  return __lasx_xvfadd_d (__lasx_cast_128_d (a), __lasx_cast_128_d (a));
+}
index d2219ea82de2df95d3f7ca3a66fe689d22f52566..bdf6e160ace5ccf36cb7a20e22362c10f480c6cb 100644 (file)
@@ -6,7 +6,7 @@
 
 /*
 **foo1_lo:
-**     vld     (\$vr[0-9]+),\$r4,0
+**     xvld    (\$xr[0-9]+),\$r4,0
 **     vpickve2gr.du   \$r4,(\$vr[0-9]+),0
 **     vpickve2gr.du   \$r5,(\$vr[0-9]+),1
 **     jr      \$r1
@@ -33,7 +33,7 @@ foo1_hi (__m256 x)
 
 /*
 **foo2_lo:
-**     vld     (\$vr[0-9]+),\$r4,0
+**     xvld    (\$xr[0-9]+),\$r4,0
 **     vpickve2gr.du   \$r4,(\$vr[0-9]+),0
 **     vpickve2gr.du   \$r5,(\$vr[0-9]+),1
 **     jr      \$r1
@@ -60,7 +60,7 @@ foo2_hi (__m256d x)
 
 /*
 **foo3_lo:
-**     vld     (\$vr[0-9]+),\$r4,0
+**     xvld    (\$xr[0-9]+),\$r4,0
 **     vpickve2gr.du   \$r4,(\$vr[0-9]+),0
 **     vpickve2gr.du   \$r5,(\$vr[0-9]+),1
 **     jr      \$r1