https://gcc.gnu.org/g:9062cdc4217cca6fb02fec78067a642e0a6b9a26

commit r17-6450-g9062cdc4217cca6fb02fec78067a642e0a6b9a26
Author: Guo Jie <[email protected]>
Date:   Sun Nov 8 14:22:43 2026 +0800

    LoongArch: Fix ICE moving V1TI and V2TI constants
    
    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.

Diff:
---
 gcc/config/loongarch/loongarch.cc                             |  2 +-
 .../gcc.target/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(-)

diff --git a/gcc/config/loongarch/loongarch.cc 
b/gcc/config/loongarch/loongarch.cc
index 7ab35c8d1085..4b0f8fe1a077 100644
--- a/gcc/config/loongarch/loongarch.cc
+++ b/gcc/config/loongarch/loongarch.cc
@@ -5282,7 +5282,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 000000000000..9a2e74e1e410
--- /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 000000000000..b5e346f39dcb
--- /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 };
+}

Reply via email to