public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] LoongArch: Fix infinite secondary reloading of FCCmode [PR113148]
@ 2023-12-26 22:37 Xi Ruoyao
  2023-12-27  6:08 ` chenglulu
  0 siblings, 1 reply; 2+ messages in thread
From: Xi Ruoyao @ 2023-12-26 22:37 UTC (permalink / raw)
  To: gcc-patches; +Cc: chenglulu, i, xuchenghua, c, Xi Ruoyao

The GCC internal doc says:

     X might be a pseudo-register or a 'subreg' of a pseudo-register,
     which could either be in a hard register or in memory.  Use
     'true_regnum' to find out; it will return -1 if the pseudo is in
     memory and the hard register number if it is in a register.

So "MEM_P (x)" is not enough for checking if we are reloading from/to
the memory.  This bug has caused reload pass to stall and finally ICE
complaining with "maximum number of generated reload insns per insn
achieved", since r14-6814.

Check if "true_regnum (x)" is -1 besides "MEM_P (x)" to fix the issue.

gcc/ChangeLog:

	PR target/113148
	* config/loongarch/loongarch.cc (loongarch_secondary_reload):
	Check if regno == -1 besides MEM_P (x) for reloading FCCmode
	from/to FPR to/from memory.

gcc/testsuite/ChangeLog:

	PR target/113148
	* gcc.target/loongarch/pr113148.c: New test.
---

Bootstrapped & regtested on loongarch64-linux-gnu.  Ok for trunk?

 gcc/config/loongarch/loongarch.cc             |  3 +-
 gcc/testsuite/gcc.target/loongarch/pr113148.c | 44 +++++++++++++++++++
 2 files changed, 46 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.target/loongarch/pr113148.c

diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc
index 5ffd06ce9be..c0a0af3dda5 100644
--- a/gcc/config/loongarch/loongarch.cc
+++ b/gcc/config/loongarch/loongarch.cc
@@ -6951,7 +6951,8 @@ loongarch_secondary_reload (bool in_p ATTRIBUTE_UNUSED, rtx x,
 	  return NO_REGS;
 	}
 
-      if (reg_class_subset_p (rclass, FP_REGS) && MEM_P (x))
+      if (reg_class_subset_p (rclass, FP_REGS)
+	  && (regno == -1 || MEM_P (x)))
 	return GR_REGS;
 
       return NO_REGS;
diff --git a/gcc/testsuite/gcc.target/loongarch/pr113148.c b/gcc/testsuite/gcc.target/loongarch/pr113148.c
new file mode 100644
index 00000000000..cf48e552053
--- /dev/null
+++ b/gcc/testsuite/gcc.target/loongarch/pr113148.c
@@ -0,0 +1,44 @@
+/* PR 113148: ICE caused by infinite reloading */
+/* { dg-do compile } */
+/* { dg-options "-O2 -march=la464 -mfpu=64 -mabi=lp64d" } */
+
+struct bound
+{
+  double max;
+} drawQuadrant_bound;
+double w4, innerXfromXY_y, computeBound_right_0;
+struct arc_def
+{
+  double w, h;
+  double a0, a1;
+};
+static void drawQuadrant (struct arc_def *);
+static void
+computeBound (struct arc_def *def, struct bound *bound)
+{
+  double ellipsex_1, ellipsex_0;
+  bound->max = def->a1 ?: __builtin_sin (w4) * def->h;
+  if (def->a0 == 5 && def->w == def->h)
+    ;
+  else
+    ellipsex_0 = def->a0 == 0.0 ?: __builtin_cos (w4);
+  if (def->a1 == 5 && def->w == def->h)
+    ellipsex_1 = bound->max;
+  __builtin_sqrt (ellipsex_1 * innerXfromXY_y * innerXfromXY_y * w4);
+  computeBound_right_0 = ellipsex_0;
+}
+void
+drawArc ()
+{
+  struct arc_def foo;
+  for (;;)
+    drawQuadrant (&foo);
+}
+void
+drawQuadrant (struct arc_def *def)
+{
+  int y, miny;
+  computeBound (def, &drawQuadrant_bound);
+  while (y >= miny)
+    ;
+}
-- 
2.43.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] LoongArch: Fix infinite secondary reloading of FCCmode [PR113148]
  2023-12-26 22:37 [PATCH] LoongArch: Fix infinite secondary reloading of FCCmode [PR113148] Xi Ruoyao
@ 2023-12-27  6:08 ` chenglulu
  0 siblings, 0 replies; 2+ messages in thread
From: chenglulu @ 2023-12-27  6:08 UTC (permalink / raw)
  To: Xi Ruoyao, gcc-patches; +Cc: i, xuchenghua, c


在 2023/12/27 上午6:37, Xi Ruoyao 写道:
> The GCC internal doc says:
>
>       X might be a pseudo-register or a 'subreg' of a pseudo-register,
>       which could either be in a hard register or in memory.  Use
>       'true_regnum' to find out; it will return -1 if the pseudo is in
>       memory and the hard register number if it is in a register.
>
> So "MEM_P (x)" is not enough for checking if we are reloading from/to
> the memory.  This bug has caused reload pass to stall and finally ICE
> complaining with "maximum number of generated reload insns per insn
> achieved", since r14-6814.
>
> Check if "true_regnum (x)" is -1 besides "MEM_P (x)" to fix the issue.
>
> gcc/ChangeLog:
>
> 	PR target/113148
> 	* config/loongarch/loongarch.cc (loongarch_secondary_reload):
> 	Check if regno == -1 besides MEM_P (x) for reloading FCCmode
> 	from/to FPR to/from memory.
>
> gcc/testsuite/ChangeLog:
>
> 	PR target/113148
> 	* gcc.target/loongarch/pr113148.c: New test.
> ---
>
> Bootstrapped & regtested on loongarch64-linux-gnu.  Ok for trunk?

LGTM!

Thanks!

>
>   gcc/config/loongarch/loongarch.cc             |  3 +-
>   gcc/testsuite/gcc.target/loongarch/pr113148.c | 44 +++++++++++++++++++
>   2 files changed, 46 insertions(+), 1 deletion(-)
>   create mode 100644 gcc/testsuite/gcc.target/loongarch/pr113148.c
>
> diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc
> index 5ffd06ce9be..c0a0af3dda5 100644
> --- a/gcc/config/loongarch/loongarch.cc
> +++ b/gcc/config/loongarch/loongarch.cc
> @@ -6951,7 +6951,8 @@ loongarch_secondary_reload (bool in_p ATTRIBUTE_UNUSED, rtx x,
>   	  return NO_REGS;
>   	}
>   
> -      if (reg_class_subset_p (rclass, FP_REGS) && MEM_P (x))
> +      if (reg_class_subset_p (rclass, FP_REGS)
> +	  && (regno == -1 || MEM_P (x)))
>   	return GR_REGS;
>   
>         return NO_REGS;
> diff --git a/gcc/testsuite/gcc.target/loongarch/pr113148.c b/gcc/testsuite/gcc.target/loongarch/pr113148.c
> new file mode 100644
> index 00000000000..cf48e552053
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/loongarch/pr113148.c
> @@ -0,0 +1,44 @@
> +/* PR 113148: ICE caused by infinite reloading */
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -march=la464 -mfpu=64 -mabi=lp64d" } */
> +
> +struct bound
> +{
> +  double max;
> +} drawQuadrant_bound;
> +double w4, innerXfromXY_y, computeBound_right_0;
> +struct arc_def
> +{
> +  double w, h;
> +  double a0, a1;
> +};
> +static void drawQuadrant (struct arc_def *);
> +static void
> +computeBound (struct arc_def *def, struct bound *bound)
> +{
> +  double ellipsex_1, ellipsex_0;
> +  bound->max = def->a1 ?: __builtin_sin (w4) * def->h;
> +  if (def->a0 == 5 && def->w == def->h)
> +    ;
> +  else
> +    ellipsex_0 = def->a0 == 0.0 ?: __builtin_cos (w4);
> +  if (def->a1 == 5 && def->w == def->h)
> +    ellipsex_1 = bound->max;
> +  __builtin_sqrt (ellipsex_1 * innerXfromXY_y * innerXfromXY_y * w4);
> +  computeBound_right_0 = ellipsex_0;
> +}
> +void
> +drawArc ()
> +{
> +  struct arc_def foo;
> +  for (;;)
> +    drawQuadrant (&foo);
> +}
> +void
> +drawQuadrant (struct arc_def *def)
> +{
> +  int y, miny;
> +  computeBound (def, &drawQuadrant_bound);
> +  while (y >= miny)
> +    ;
> +}


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-12-27  6:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-26 22:37 [PATCH] LoongArch: Fix infinite secondary reloading of FCCmode [PR113148] Xi Ruoyao
2023-12-27  6:08 ` chenglulu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).