The loongarch_output_move only attempts the vldi/xvldi constant path
when the first vector element is CONST_INT.  V1TI and V2TI vectors
contain CONST_WIDE_INT elements instead.  Nevertheless, the YI operand
constraint accepts these constants because loongarch_const_vector_vldi
can encode them, so recog accepts the move and the failure is deferred
until final instruction output.  The loongarch_output_move then skips
the vldi/xvldi path and reaches gcc_unreachable, causing an ICE.

gcc/ChangeLog:

        * config/loongarch/loongarch.cc (loongarch_output_move): Use
        CONST_SCALAR_INT_P instead of CONST_INT_P when checking vector
        constants for vldi/xvldi, allowing CONST_WIDE_INT elements in
        V1TI and V2TI constants.

gcc/testsuite/ChangeLog:

        * gcc.target/loongarch/vector/lasx/v2ti-const-move.c: New test.
        * gcc.target/loongarch/vector/lsx/v1ti-const-move.c: New test.
---
 gcc/config/loongarch/loongarch.cc                     |  2 +-
 .../loongarch/vector/lasx/v2ti-const-move.c           | 11 +++++++++++
 .../gcc.target/loongarch/vector/lsx/v1ti-const-move.c | 11 +++++++++++
 3 files changed, 23 insertions(+), 1 deletion(-)
 create mode 100644 
gcc/testsuite/gcc.target/loongarch/vector/lasx/v2ti-const-move.c
 create mode 100644 
gcc/testsuite/gcc.target/loongarch/vector/lsx/v1ti-const-move.c

diff --git a/gcc/config/loongarch/loongarch.cc 
b/gcc/config/loongarch/loongarch.cc
index bf401602394..10e9af41196 100644
--- a/gcc/config/loongarch/loongarch.cc
+++ b/gcc/config/loongarch/loongarch.cc
@@ -5252,7 +5252,7 @@ loongarch_output_move (rtx *operands)
   if ((lsx_p || lasx_p)
       && dest_code == REG && FP_REG_P (REGNO (dest))
       && src_code == CONST_VECTOR
-      && CONST_INT_P (CONST_VECTOR_ELT (src, 0)))
+      && CONST_SCALAR_INT_P (CONST_VECTOR_ELT (src, 0)))
     {
       operands[1] = loongarch_const_vector_vldi (src, mode);
       gcc_assert (operands[1]);
diff --git a/gcc/testsuite/gcc.target/loongarch/vector/lasx/v2ti-const-move.c 
b/gcc/testsuite/gcc.target/loongarch/vector/lasx/v2ti-const-move.c
new file mode 100644
index 00000000000..9a2e74e1e41
--- /dev/null
+++ b/gcc/testsuite/gcc.target/loongarch/vector/lasx/v2ti-const-move.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mlasx" } */
+
+typedef __int128 v2ti __attribute__ ((vector_size (32)));
+
+v2ti
+v2ti_xvldi (void)
+{
+  __int128 x = ((__int128)0xff00ff00000000LL << 64) | 0xff00ff00000000LL;
+  return (v2ti){ x, x };
+}
diff --git a/gcc/testsuite/gcc.target/loongarch/vector/lsx/v1ti-const-move.c 
b/gcc/testsuite/gcc.target/loongarch/vector/lsx/v1ti-const-move.c
new file mode 100644
index 00000000000..b5e346f39dc
--- /dev/null
+++ b/gcc/testsuite/gcc.target/loongarch/vector/lsx/v1ti-const-move.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mlsx" } */
+
+typedef long long v2di __attribute__ ((vector_size (16)));
+typedef __int128 v1ti __attribute__ ((vector_size (16)));
+
+v1ti
+v1ti_vldi (void)
+{
+  return (v1ti)(v2di){ 0xff00ff00000000LL, 0xff00ff00000000LL };
+}
-- 
2.55.0

Reply via email to