public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] arm: make arm_predict_doloop_p reject loops with calls
@ 2024-06-25 11:53 Andre Vieira (lists)
  2024-06-25 15:15 ` Richard Earnshaw (lists)
  0 siblings, 1 reply; 2+ messages in thread
From: Andre Vieira (lists) @ 2024-06-25 11:53 UTC (permalink / raw)
  To: gcc-patches; +Cc: Richard Earnshaw (lists)

[-- Attachment #1: Type: text/plain, Size: 1450 bytes --]

Hi,

With the introduction of low overhead loops in 
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=3dfc28dbbd21b1d708aa40064380ef4c42c994d7 
we defined arm_predict_doloop_p, this is meant to be a low-weight check 
to rule out loops we are not considering for doloop optimization and it 
is used by other passes to prevent optimizations that may hurt the 
doloop optimization later on. The reason these are meant to be 
lightweight is because it's used by pre-RTL optimizations, meaning we 
can't do the same checks that doloop does.

After the definition of arm_predict_doloop_p, when testing for 
armv8.1-m.main, tree-ssa/ivopts-3.c failed the scan-dump check as the 
dump now matched an extra '!= 0' introduced by:
Doloop cmp iv use: if (ivtmp_1 != 0)
Predict loop 1 can perform doloop optimization later.

where previously we had:
Predict doloop failure due to target specific checks.

and after this patch:
Predict doloop failure due to call in loop.
Predict doloop failure due to target specific checks.

Added a copy of the original tree-ssa/ivopts-3.c as a target specifc 
test to check for the new dump message.

Ran a regression test for arm-none-eabi with 
-march=armv8.1-m.main+mve/-mfpu=auto/-mthumb/-mfloat-abi=hard.

OK for trunk?

gcc/ChangeLog:

         * confir/arm/arm.cc (arm_predict_doloop_p): Reject loops with 
function calls that are not builtins.

gcc/testsuite/ChangeLog:

         * gcc.target/arm/mve/ivopts-3.c: New test.

[-- Attachment #2: predict_doloop.patch --]
[-- Type: text/plain, Size: 1343 bytes --]

diff --git a/gcc/config/arm/arm.cc b/gcc/config/arm/arm.cc
index 7d67d2cfee9f4edc91f187e940be40c07ff726cd..6dab65f493beb76089f80966a73a46afe037e6f9 100644
--- a/gcc/config/arm/arm.cc
+++ b/gcc/config/arm/arm.cc
@@ -35587,6 +35587,22 @@ arm_predict_doloop_p (struct loop *loop)
 			    " loop bb complexity.\n");
       return false;
     }
+  else
+    {
+      gimple_stmt_iterator gsi = gsi_after_labels (loop->header);
+      while (!gsi_end_p (gsi))
+	{
+	  if (is_gimple_call (gsi_stmt (gsi))
+	      && !gimple_call_builtin_p (gsi_stmt (gsi)))
+	    {
+	      if (dump_file && (dump_flags & TDF_DETAILS))
+		fprintf (dump_file, "Predict doloop failure due to"
+				    " call in loop.\n");
+	      return false;
+	    }
+	  gsi_next (&gsi);
+	}
+    }
 
   return true;
 }
diff --git a/gcc/testsuite/gcc.target/arm/mve/ivopts-3.c b/gcc/testsuite/gcc.target/arm/mve/ivopts-3.c
new file mode 100644
index 0000000000000000000000000000000000000000..19b2442ef12cbf13d51761ae93c7c81bb5bc07c4
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arm/mve/ivopts-3.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-ivopts-details" } */
+
+void f2 (void);
+
+int main (void)
+{
+  int i;
+  for (i = 0; i < 10; i++)
+    f2 ();
+}
+
+/* { dg-final { scan-tree-dump "Predict doloop failure due to call in loop." "ivopts" } } */

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

* Re: [PATCH] arm: make arm_predict_doloop_p reject loops with calls
  2024-06-25 11:53 [PATCH] arm: make arm_predict_doloop_p reject loops with calls Andre Vieira (lists)
@ 2024-06-25 15:15 ` Richard Earnshaw (lists)
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Earnshaw (lists) @ 2024-06-25 15:15 UTC (permalink / raw)
  To: Andre Vieira (lists), gcc-patches

On 25/06/2024 12:53, Andre Vieira (lists) wrote:
> Hi,
> 
> With the introduction of low overhead loops in https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=3dfc28dbbd21b1d708aa40064380ef4c42c994d7 we defined arm_predict_doloop_p, this is meant to be a low-weight check to rule out loops we are not considering for doloop optimization and it is used by other passes to prevent optimizations that may hurt the doloop optimization later on. The reason these are meant to be lightweight is because it's used by pre-RTL optimizations, meaning we can't do the same checks that doloop does.
> 
> After the definition of arm_predict_doloop_p, when testing for armv8.1-m.main, tree-ssa/ivopts-3.c failed the scan-dump check as the dump now matched an extra '!= 0' introduced by:
> Doloop cmp iv use: if (ivtmp_1 != 0)
> Predict loop 1 can perform doloop optimization later.
> 
> where previously we had:
> Predict doloop failure due to target specific checks.
> 
> and after this patch:
> Predict doloop failure due to call in loop.
> Predict doloop failure due to target specific checks.
> 
> Added a copy of the original tree-ssa/ivopts-3.c as a target specifc test to check for the new dump message.
> 
> Ran a regression test for arm-none-eabi with -march=armv8.1-m.main+mve/-mfpu=auto/-mthumb/-mfloat-abi=hard.
> 
> OK for trunk?
> 
> gcc/ChangeLog:
> 
>         * confir/arm/arm.cc (arm_predict_doloop_p): Reject loops with function calls that are not builtins.
> 
> gcc/testsuite/ChangeLog:
> 
>         * gcc.target/arm/mve/ivopts-3.c: New test.

OK.

R.

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

end of thread, other threads:[~2024-06-25 15:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-25 11:53 [PATCH] arm: make arm_predict_doloop_p reject loops with calls Andre Vieira (lists)
2024-06-25 15:15 ` Richard Earnshaw (lists)

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).