* [PATCH] Fix PR78413
@ 2016-11-18 16:27 Bill Schmidt
2016-11-18 16:34 ` Markus Trippelsdorf
2016-11-21 9:51 ` Richard Biener
0 siblings, 2 replies; 4+ messages in thread
From: Bill Schmidt @ 2016-11-18 16:27 UTC (permalink / raw)
To: GCC Patches, Richard Biener
Hi,
The if-conversion patch for PR77848 missed a case where an outer loop
should not be versioned for vectorization; this was caught by an assert
in tests recorded in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78413.
This patch fixes the problem by ensuring that both inner and outer loop
latches have a single predecessor before versioning an outer loop.
Bootstrapped and tested on powerpc64le-unknown-linux-gnu with no
regressions. Is this ok for trunk?
Thanks,
Bill
[gcc]
2016-11-18 Bill Schmidt <wschmidt@linux.vnet.ibm.com>
PR tree-optimization/78413
* tree-if-conv.c (versionable_outer_loop_p): Require that both
inner and outer loop latches have single predecessors.
[gcc/testsuite]
2016-11-18 Bill Schmidt <wschmidt@linux.vnet.ibm.com>
PR tree-optimization/78413
* gcc.dg/tree-ssa/pr78413.c: New test.
Index: gcc/testsuite/gcc.dg/tree-ssa/pr78413.c
===================================================================
--- gcc/testsuite/gcc.dg/tree-ssa/pr78413.c (revision 0)
+++ gcc/testsuite/gcc.dg/tree-ssa/pr78413.c (working copy)
@@ -0,0 +1,35 @@
+/* PR78413. These previously failed in tree if-conversion due to a loop
+ latch with multiple predecessors that the code did not anticipate. */
+/* { dg-do compile } */
+/* { dg-options "-O3 -ffast-math" } */
+
+extern long long int llrint(double x);
+int a;
+double b;
+__attribute__((cold)) void decode_init() {
+ int c, d = 0;
+ for (; d < 12; d++) {
+ if (d)
+ b = 0;
+ c = 0;
+ for (; c < 6; c++)
+ a = b ? llrint(b) : 0;
+ }
+}
+
+struct S {
+ _Bool bo;
+};
+int a, bb, c, d;
+void fn1() {
+ do
+ do
+ do {
+ struct S *e = (struct S *)1;
+ do
+ bb = a / (e->bo ? 2 : 1);
+ while (bb);
+ } while (0);
+ while (d);
+ while (c);
+}
Index: gcc/tree-if-conv.c
===================================================================
--- gcc/tree-if-conv.c (revision 242551)
+++ gcc/tree-if-conv.c (working copy)
@@ -2575,6 +2575,8 @@ version_loop_for_if_conversion (struct loop *loop)
- The loop has a single exit.
- The loop header has a single successor, which is the inner
loop header.
+ - Each of the inner and outer loop latches have a single
+ predecessor.
- The loop exit block has a single predecessor, which is the
inner loop's exit block. */
@@ -2586,7 +2588,9 @@ versionable_outer_loop_p (struct loop *loop)
|| loop->inner->next
|| !single_exit (loop)
|| !single_succ_p (loop->header)
- || single_succ (loop->header) != loop->inner->header)
+ || single_succ (loop->header) != loop->inner->header
+ || !single_pred_p (loop->latch)
+ || !single_pred_p (loop->inner->latch))
return false;
basic_block outer_exit = single_pred (loop->latch);
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Fix PR78413
2016-11-18 16:27 [PATCH] Fix PR78413 Bill Schmidt
@ 2016-11-18 16:34 ` Markus Trippelsdorf
2016-11-18 16:42 ` Bill Schmidt
2016-11-21 9:51 ` Richard Biener
1 sibling, 1 reply; 4+ messages in thread
From: Markus Trippelsdorf @ 2016-11-18 16:34 UTC (permalink / raw)
To: Bill Schmidt; +Cc: GCC Patches, Richard Biener
On 2016.11.18 at 10:27 -0600, Bill Schmidt wrote:
> ===================================================================
> --- gcc/testsuite/gcc.dg/tree-ssa/pr78413.c (revision 0)
> +++ gcc/testsuite/gcc.dg/tree-ssa/pr78413.c (working copy)
> @@ -0,0 +1,35 @@
> +/* PR78413. These previously failed in tree if-conversion due to a loop
> + latch with multiple predecessors that the code did not anticipate. */
> +/* { dg-do compile } */
> +/* { dg-options "-O3 -ffast-math" } */
Please add -fno-strict-aliasing, otherwise fn1() wouldn't ICE.
> +extern long long int llrint(double x);
> +int a;
> +double b;
> +__attribute__((cold)) void decode_init() {
> + int c, d = 0;
> + for (; d < 12; d++) {
> + if (d)
> + b = 0;
> + c = 0;
> + for (; c < 6; c++)
> + a = b ? llrint(b) : 0;
> + }
> +}
> +
> +struct S {
> + _Bool bo;
> +};
> +int a, bb, c, d;
> +void fn1() {
> + do
> + do
> + do {
> + struct S *e = (struct S *)1;
> + do
> + bb = a / (e->bo ? 2 : 1);
> + while (bb);
> + } while (0);
> + while (d);
> + while (c);
> +}
--
Markus
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Fix PR78413
2016-11-18 16:34 ` Markus Trippelsdorf
@ 2016-11-18 16:42 ` Bill Schmidt
0 siblings, 0 replies; 4+ messages in thread
From: Bill Schmidt @ 2016-11-18 16:42 UTC (permalink / raw)
To: Markus Trippelsdorf; +Cc: GCC Patches, Richard Biener
> On Nov 18, 2016, at 10:33 AM, Markus Trippelsdorf <markus@trippelsdorf.de> wrote:
>
> On 2016.11.18 at 10:27 -0600, Bill Schmidt wrote:
>> ===================================================================
>> --- gcc/testsuite/gcc.dg/tree-ssa/pr78413.c (revision 0)
>> +++ gcc/testsuite/gcc.dg/tree-ssa/pr78413.c (working copy)
>> @@ -0,0 +1,35 @@
>> +/* PR78413. These previously failed in tree if-conversion due to a loop
>> + latch with multiple predecessors that the code did not anticipate. */
>> +/* { dg-do compile } */
>> +/* { dg-options "-O3 -ffast-math" } */
>
> Please add -fno-strict-aliasing, otherwise fn1() wouldn't ICE.
Whoops. Yes indeed, sorry I missed the flag difference for the second failure.
Bill
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Fix PR78413
2016-11-18 16:27 [PATCH] Fix PR78413 Bill Schmidt
2016-11-18 16:34 ` Markus Trippelsdorf
@ 2016-11-21 9:51 ` Richard Biener
1 sibling, 0 replies; 4+ messages in thread
From: Richard Biener @ 2016-11-21 9:51 UTC (permalink / raw)
To: Bill Schmidt; +Cc: GCC Patches
On Fri, Nov 18, 2016 at 5:27 PM, Bill Schmidt
<wschmidt@linux.vnet.ibm.com> wrote:
> Hi,
>
> The if-conversion patch for PR77848 missed a case where an outer loop
> should not be versioned for vectorization; this was caught by an assert
> in tests recorded in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78413.
> This patch fixes the problem by ensuring that both inner and outer loop
> latches have a single predecessor before versioning an outer loop.
>
> Bootstrapped and tested on powerpc64le-unknown-linux-gnu with no
> regressions. Is this ok for trunk?
Ok (with the suggested testcase adjustment).
Maybe as a followup we can factor out a common predicate usable by the
vectorizer and if-conversion. I'll see if I can do that.
Thanks,
Richard.
> Thanks,
> Bill
>
>
> [gcc]
>
> 2016-11-18 Bill Schmidt <wschmidt@linux.vnet.ibm.com>
>
> PR tree-optimization/78413
> * tree-if-conv.c (versionable_outer_loop_p): Require that both
> inner and outer loop latches have single predecessors.
>
> [gcc/testsuite]
>
> 2016-11-18 Bill Schmidt <wschmidt@linux.vnet.ibm.com>
>
> PR tree-optimization/78413
> * gcc.dg/tree-ssa/pr78413.c: New test.
>
>
> Index: gcc/testsuite/gcc.dg/tree-ssa/pr78413.c
> ===================================================================
> --- gcc/testsuite/gcc.dg/tree-ssa/pr78413.c (revision 0)
> +++ gcc/testsuite/gcc.dg/tree-ssa/pr78413.c (working copy)
> @@ -0,0 +1,35 @@
> +/* PR78413. These previously failed in tree if-conversion due to a loop
> + latch with multiple predecessors that the code did not anticipate. */
> +/* { dg-do compile } */
> +/* { dg-options "-O3 -ffast-math" } */
> +
> +extern long long int llrint(double x);
> +int a;
> +double b;
> +__attribute__((cold)) void decode_init() {
> + int c, d = 0;
> + for (; d < 12; d++) {
> + if (d)
> + b = 0;
> + c = 0;
> + for (; c < 6; c++)
> + a = b ? llrint(b) : 0;
> + }
> +}
> +
> +struct S {
> + _Bool bo;
> +};
> +int a, bb, c, d;
> +void fn1() {
> + do
> + do
> + do {
> + struct S *e = (struct S *)1;
> + do
> + bb = a / (e->bo ? 2 : 1);
> + while (bb);
> + } while (0);
> + while (d);
> + while (c);
> +}
> Index: gcc/tree-if-conv.c
> ===================================================================
> --- gcc/tree-if-conv.c (revision 242551)
> +++ gcc/tree-if-conv.c (working copy)
> @@ -2575,6 +2575,8 @@ version_loop_for_if_conversion (struct loop *loop)
> - The loop has a single exit.
> - The loop header has a single successor, which is the inner
> loop header.
> + - Each of the inner and outer loop latches have a single
> + predecessor.
> - The loop exit block has a single predecessor, which is the
> inner loop's exit block. */
>
> @@ -2586,7 +2588,9 @@ versionable_outer_loop_p (struct loop *loop)
> || loop->inner->next
> || !single_exit (loop)
> || !single_succ_p (loop->header)
> - || single_succ (loop->header) != loop->inner->header)
> + || single_succ (loop->header) != loop->inner->header
> + || !single_pred_p (loop->latch)
> + || !single_pred_p (loop->inner->latch))
> return false;
>
> basic_block outer_exit = single_pred (loop->latch);
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-11-21 9:51 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-18 16:27 [PATCH] Fix PR78413 Bill Schmidt
2016-11-18 16:34 ` Markus Trippelsdorf
2016-11-18 16:42 ` Bill Schmidt
2016-11-21 9:51 ` 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).