]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
LoongArch: Fix bug123807.
authorLulu Cheng <chenglulu@loongson.cn>
Mon, 26 Jan 2026 03:38:59 +0000 (11:38 +0800)
committerLulu Cheng <chenglulu@loongson.cn>
Fri, 30 Jan 2026 01:23:45 +0000 (09:23 +0800)
In the function loongarch_expand_vector_init_same, if same is MEM and
the mode of same does not match imode, it will cause an ICE
in force_reg (imode, same).

PR target/123807

gcc/ChangeLog:

* config/loongarch/loongarch.cc
(loongarch_expand_vector_init_same): When same is MEM and
GET_MODE(same) != imode, first load the data from memory
and then process it further.

gcc/testsuite/ChangeLog:

* gcc.target/loongarch/vector/lsx/pr123807.c: New test.

gcc/config/loongarch/loongarch.cc
gcc/testsuite/gcc.target/loongarch/vector/lsx/pr123807.c [new file with mode: 0644]

index 30f8bc057470ba451f52993bba3c6bdd48f79d19..27e0c79d29a357aa359b8fa17dc44884c13f0f71 100644 (file)
@@ -10436,7 +10436,16 @@ loongarch_expand_vector_init_same (rtx target, rtx vals, unsigned nvar)
        }
     }
 
-  temp = force_reg (imode, same);
+  if (GET_CODE (same) == MEM && GET_MODE (same) != imode)
+    {
+      rtx reg_tmp = gen_reg_rtx (GET_MODE (same));
+      loongarch_emit_move (reg_tmp, same);
+      temp = lowpart_subreg (imode, reg_tmp, GET_MODE (reg_tmp));
+    }
+  else
+    temp = same;
+
+  temp = force_reg (imode, temp);
 
   switch (vmode)
     {
diff --git a/gcc/testsuite/gcc.target/loongarch/vector/lsx/pr123807.c b/gcc/testsuite/gcc.target/loongarch/vector/lsx/pr123807.c
new file mode 100644 (file)
index 0000000..7ec514a
--- /dev/null
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-O0 -msimd=lsx" } */
+
+typedef long long v2i64 __attribute__ ((__vector_size__ (16)));
+v2i64 a, b;
+void
+test (int imm8)
+{
+  b = a << imm8;
+}