* [PATCH]middle-end: skip checking loop exits if loop malformed [PR111878]
@ 2023-11-15 14:40 Tamar Christina
2023-11-16 7:00 ` Richard Biener
0 siblings, 1 reply; 2+ messages in thread
From: Tamar Christina @ 2023-11-15 14:40 UTC (permalink / raw)
To: gcc-patches; +Cc: nd, rguenther, jlaw
[-- Attachment #1: Type: text/plain, Size: 1991 bytes --]
Hi All,
Before my refactoring if the loop->latch was incorrect then find_loop_location
skipped checking the edges and would eventually return a dummy location.
It turns out that a loop can have
loops_state_satisfies_p (LOOPS_HAVE_RECORDED_EXITS) but also not have a latch
in which case get_loop_exit_edges traps.
This restores the old behavior.
Bootstrapped Regtested on x86_64-pc-linux-gnu and no issues.
Ok for master?
Thanks,
Tamar
gcc/ChangeLog:
PR tree-optimization/111878
* tree-vect-loop-manip.cc (find_loop_location): Skip edges check if
latch incorrect.
gcc/testsuite/ChangeLog:
PR tree-optimization/111878
* gcc.dg/graphite/pr111878.c: New test.
--- inline copy of patch --
diff --git a/gcc/testsuite/gcc.dg/graphite/pr111878.c b/gcc/testsuite/gcc.dg/graphite/pr111878.c
new file mode 100644
index 0000000000000000000000000000000000000000..6722910062e43c827e94c53b43f106af1848852a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/graphite/pr111878.c
@@ -0,0 +1,19 @@
+/* { dg-options "-O3 -fgraphite-identity -fsave-optimization-record" } */
+
+int long_c2i_ltmp;
+int *long_c2i_cont;
+
+void
+long_c2i (long utmp, int i)
+{
+ int neg = 1;
+ switch (long_c2i_cont[0])
+ case 0:
+ neg = 0;
+ for (; i; i++)
+ if (neg)
+ utmp |= long_c2i_cont[i] ^ 5;
+ else
+ utmp |= long_c2i_cont[i];
+ long_c2i_ltmp = utmp;
+}
diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc
index b9161274ce401a7307f3e61ad23aa036701190d7..ff188840c1762d0b5fb6655cb93b5a8662b31343 100644
--- a/gcc/tree-vect-loop-manip.cc
+++ b/gcc/tree-vect-loop-manip.cc
@@ -1792,7 +1792,8 @@ find_loop_location (class loop *loop)
if (!loop)
return dump_user_location_t ();
- if (loops_state_satisfies_p (LOOPS_HAVE_RECORDED_EXITS))
+ if (loops_state_satisfies_p (LOOPS_HAVE_RECORDED_EXITS)
+ && loop->latch != EXIT_BLOCK_PTR_FOR_FN (cfun))
{
/* We only care about the loop location, so use any exit with location
information. */
--
[-- Attachment #2: rb18010.patch --]
[-- Type: text/plain, Size: 1285 bytes --]
diff --git a/gcc/testsuite/gcc.dg/graphite/pr111878.c b/gcc/testsuite/gcc.dg/graphite/pr111878.c
new file mode 100644
index 0000000000000000000000000000000000000000..6722910062e43c827e94c53b43f106af1848852a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/graphite/pr111878.c
@@ -0,0 +1,19 @@
+/* { dg-options "-O3 -fgraphite-identity -fsave-optimization-record" } */
+
+int long_c2i_ltmp;
+int *long_c2i_cont;
+
+void
+long_c2i (long utmp, int i)
+{
+ int neg = 1;
+ switch (long_c2i_cont[0])
+ case 0:
+ neg = 0;
+ for (; i; i++)
+ if (neg)
+ utmp |= long_c2i_cont[i] ^ 5;
+ else
+ utmp |= long_c2i_cont[i];
+ long_c2i_ltmp = utmp;
+}
diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc
index b9161274ce401a7307f3e61ad23aa036701190d7..ff188840c1762d0b5fb6655cb93b5a8662b31343 100644
--- a/gcc/tree-vect-loop-manip.cc
+++ b/gcc/tree-vect-loop-manip.cc
@@ -1792,7 +1792,8 @@ find_loop_location (class loop *loop)
if (!loop)
return dump_user_location_t ();
- if (loops_state_satisfies_p (LOOPS_HAVE_RECORDED_EXITS))
+ if (loops_state_satisfies_p (LOOPS_HAVE_RECORDED_EXITS)
+ && loop->latch != EXIT_BLOCK_PTR_FOR_FN (cfun))
{
/* We only care about the loop location, so use any exit with location
information. */
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH]middle-end: skip checking loop exits if loop malformed [PR111878]
2023-11-15 14:40 [PATCH]middle-end: skip checking loop exits if loop malformed [PR111878] Tamar Christina
@ 2023-11-16 7:00 ` Richard Biener
0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2023-11-16 7:00 UTC (permalink / raw)
To: Tamar Christina; +Cc: gcc-patches, nd, jlaw
On Wed, 15 Nov 2023, Tamar Christina wrote:
> Hi All,
>
> Before my refactoring if the loop->latch was incorrect then find_loop_location
> skipped checking the edges and would eventually return a dummy location.
>
> It turns out that a loop can have
> loops_state_satisfies_p (LOOPS_HAVE_RECORDED_EXITS) but also not have a latch
> in which case get_loop_exit_edges traps.
>
> This restores the old behavior.
>
> Bootstrapped Regtested on x86_64-pc-linux-gnu and no issues.
>
> Ok for master?
>
> Thanks,
> Tamar
>
> gcc/ChangeLog:
>
> PR tree-optimization/111878
> * tree-vect-loop-manip.cc (find_loop_location): Skip edges check if
> latch incorrect.
>
> gcc/testsuite/ChangeLog:
>
> PR tree-optimization/111878
> * gcc.dg/graphite/pr111878.c: New test.
>
> --- inline copy of patch --
> diff --git a/gcc/testsuite/gcc.dg/graphite/pr111878.c b/gcc/testsuite/gcc.dg/graphite/pr111878.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..6722910062e43c827e94c53b43f106af1848852a
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/graphite/pr111878.c
> @@ -0,0 +1,19 @@
> +/* { dg-options "-O3 -fgraphite-identity -fsave-optimization-record" } */
> +
> +int long_c2i_ltmp;
> +int *long_c2i_cont;
> +
> +void
> +long_c2i (long utmp, int i)
> +{
> + int neg = 1;
> + switch (long_c2i_cont[0])
> + case 0:
> + neg = 0;
> + for (; i; i++)
> + if (neg)
> + utmp |= long_c2i_cont[i] ^ 5;
> + else
> + utmp |= long_c2i_cont[i];
> + long_c2i_ltmp = utmp;
> +}
> diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc
> index b9161274ce401a7307f3e61ad23aa036701190d7..ff188840c1762d0b5fb6655cb93b5a8662b31343 100644
> --- a/gcc/tree-vect-loop-manip.cc
> +++ b/gcc/tree-vect-loop-manip.cc
> @@ -1792,7 +1792,8 @@ find_loop_location (class loop *loop)
> if (!loop)
The testcase asks for the location of the root of the loop tree,
I think it's more sensible to explicitly handle this case adding
/* For the root of the loop tree return the function location. */
if (!loop_outer (loop))
return dump_user_location_t::from_function_decl (cfun->decl);
OK with that change.
Richard.
> return dump_user_location_t ();
>
> - if (loops_state_satisfies_p (LOOPS_HAVE_RECORDED_EXITS))
> + if (loops_state_satisfies_p (LOOPS_HAVE_RECORDED_EXITS)
> + && loop->latch != EXIT_BLOCK_PTR_FOR_FN (cfun))
> {
> /* We only care about the loop location, so use any exit with location
> information. */
>
>
>
>
>
--
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH,
Frankenstrasse 146, 90461 Nuernberg, Germany;
GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-11-16 7:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-15 14:40 [PATCH]middle-end: skip checking loop exits if loop malformed [PR111878] Tamar Christina
2023-11-16 7:00 ` Richard Biener
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).