loongarch: exclude LARCH_PROLOGUE_TEMP from SIBCALL_REGS [PR 106096]
authorXi Ruoyao <xry111@xry111.site>
Tue, 28 Jun 2022 08:00:14 +0000 (16:00 +0800)
committerXi Ruoyao <xry111@xry111.site>
Tue, 28 Jun 2022 11:03:04 +0000 (19:03 +0800)
The epilogue may clobber LARCH_PROLOGUE_TEMP ($r13/$t1), so it cannot be
used for sibcalls.

gcc/ChangeLog:

PR target/106096
* config/loongarch/loongarch.h (REG_CLASS_CONTENTS): Exclude
$r13 from SIBCALL_REGS.
* config/loongarch/loongarch.cc (loongarch_regno_to_class):
Change $r13 to JIRL_REGS.

gcc/testsuite/ChangeLog:

PR target/106096
* g++.target/loongarch/loongarch.exp: New test support file.
* g++.target/loongarch/pr106096.C: New test.

gcc/config/loongarch/loongarch.cc
gcc/config/loongarch/loongarch.h
gcc/testsuite/g++.target/loongarch/loongarch.exp [new file with mode: 0644]
gcc/testsuite/g++.target/loongarch/pr106096.C [new file with mode: 0644]

index 80046b6..c8502b0 100644 (file)
@@ -189,7 +189,7 @@ const enum reg_class loongarch_regno_to_class[FIRST_PSEUDO_REGISTER] = {
     GR_REGS,        GR_REGS,         GR_REGS,         GR_REGS,
     JIRL_REGS,       JIRL_REGS,       JIRL_REGS,       JIRL_REGS,
     JIRL_REGS,       JIRL_REGS,       JIRL_REGS,       JIRL_REGS,
-    SIBCALL_REGS,    SIBCALL_REGS,    SIBCALL_REGS,    SIBCALL_REGS,
+    SIBCALL_REGS,    JIRL_REGS,       SIBCALL_REGS,    SIBCALL_REGS,
     SIBCALL_REGS,    SIBCALL_REGS,    SIBCALL_REGS,    SIBCALL_REGS,
     SIBCALL_REGS,    GR_REGS,        GR_REGS,         JIRL_REGS,
     JIRL_REGS,       JIRL_REGS,       JIRL_REGS,       JIRL_REGS,
index 4d107a4..f9de9a6 100644 (file)
@@ -511,7 +511,7 @@ enum reg_class
 #define REG_CLASS_CONTENTS                                             \
 {                                                                      \
   { 0x00000000, 0x00000000, 0x00000000 },      /* NO_REGS  */          \
-  { 0x001ff000, 0x00000000, 0x00000000 },      /* SIBCALL_REGS  */     \
+  { 0x001fd000, 0x00000000, 0x00000000 },      /* SIBCALL_REGS  */     \
   { 0xff9ffff0, 0x00000000, 0x00000000 },      /* JIRL_REGS  */        \
   { 0xfffffffc, 0x00000000, 0x00000000 },      /* CSR_REGS  */         \
   { 0xffffffff, 0x00000000, 0x00000000 },      /* GR_REGS  */          \
diff --git a/gcc/testsuite/g++.target/loongarch/loongarch.exp b/gcc/testsuite/g++.target/loongarch/loongarch.exp
new file mode 100644 (file)
index 0000000..4fd1194
--- /dev/null
@@ -0,0 +1,34 @@
+# Copyright (C) 2019-2022 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+# GCC testsuite that uses the `dg.exp' driver.
+
+# Exit immediately if this isn't a LoongArch target.
+if ![istarget loongarch*-*-*] then {
+  return
+}
+
+# Load support procs.
+load_lib g++-dg.exp
+
+# Initialize `dg'.
+dg-init
+
+# Main loop.
+dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.C]] "" ""
+
+# All done.
+dg-finish
diff --git a/gcc/testsuite/g++.target/loongarch/pr106096.C b/gcc/testsuite/g++.target/loongarch/pr106096.C
new file mode 100644 (file)
index 0000000..5edbda2
--- /dev/null
@@ -0,0 +1,75 @@
+/* PR target/106096
+   Reduced from gimple-range-path.cc.  It was miscompiled with -O2 and
+   caused ICE (segfault) building stage 2 libgcc.  */
+
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+enum E
+{
+  TS_TYPED
+} a;
+int b, c;
+char d, e;
+
+__attribute__ ((cold, noipa, noinline)) void
+cold (int *, E, char *, int, char *)
+{
+  __builtin_trap ();
+}
+
+int *
+contains_struct_check (E x)
+{
+  if (a)
+    cold (&b, x, &d, c, &e);
+  return &b;
+}
+
+struct vrange
+{
+  virtual void set_varying (int *);
+};
+
+struct int_range : vrange
+{
+  int *m_ranges[510];
+};
+
+__attribute__ ((noipa, noinline)) void
+vrange::set_varying (int *)
+{
+}
+
+struct Value_Range
+{
+  Value_Range (int *);
+  int_range m_irange;
+};
+
+__attribute__ ((noipa, noinline)) Value_Range::Value_Range (int *) {}
+
+struct path_range_query
+{
+  void ssa_range_in_phi (vrange &);
+  bool m_resolve;
+};
+
+__attribute__ ((noipa, noinline)) void
+path_range_query::ssa_range_in_phi (vrange &r)
+{
+  if (m_resolve)
+    {
+      Value_Range (contains_struct_check (TS_TYPED));
+      return;
+    }
+  r.set_varying (contains_struct_check (TS_TYPED));
+}
+
+int
+main ()
+{
+  path_range_query prq{ 0 };
+  vrange vr;
+  prq.ssa_range_in_phi (vr);
+  return 0;
+}