Hi,
Consider this test-case (reduced from ira-color.c):
...
unsigned int b;
unsigned int
fn1 (unsigned int d)
{
int i;
for (i = 0; i < 1000; i++)
b |= d;
return b;
}
...
When compiling with -O2 -ftree-parallelize-loops=2, we run into a segfault.
Before parloops, we have reduction stmt _6 with loop phi prephitmp_11:
...
<bb 2>:
pretmp_1 = b;
<bb 3>:
# i_13 = PHI <i_8(4), 0(2)>
# prephitmp_11 = PHI <_6(4), pretmp_1(2)>
# ivtmp_4 = PHI <ivtmp_12(4), 1000(2)>
_6 = d_5(D) | prephitmp_11;
i_8 = i_13 + 1;
ivtmp_12 = ivtmp_4 - 1;
if (ivtmp_12 != 0)
goto <bb 4>;
else
goto <bb 5>;
<bb 4>:
goto <bb 3>;
<bb 5>:
# _9 = PHI <_6(3)>
# b_lsm.4_17 = PHI <_6(3)>
b = b_lsm.4_17;
return _9;
...
There are however two corresponding loop exit phis: _9 and b_lsm.4_17.
We only track one exit phi in the keep_res field of struct
reduction_info, and the segfault is a result of that discrepancy.
The seqfault only happens when using transform_to_exit_first_loop_alt,
so only trunk needs this fix.
The patch fixes the segfault conservatively by bailing out of
parallelizing the loop if a reduction has more than one exit phi.
Bootstrapped and reg-tested on x86_64.
Committed to trunk.
Thanks,
- Tom
Only allow single exit phi for reduction in try_create_reduction_list
2016-01-07 Tom de Vries <t...@codesourcery.com>
PR tree-optimization/69039
* tree-parloops.c (try_create_reduction_list): Only allow single exit
phi for reduction.
* gcc.dg/autopar/pr69039.c: New test.
---
gcc/testsuite/gcc.dg/autopar/pr69039.c | 15 +++++++++++++++
gcc/tree-parloops.c | 8 ++++++++
2 files changed, 23 insertions(+)
diff --git a/gcc/testsuite/gcc.dg/autopar/pr69039.c b/gcc/testsuite/gcc.dg/autopar/pr69039.c
new file mode 100644
index 0000000..556f700
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/autopar/pr69039.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -ftree-parallelize-loops=2" } */
+
+unsigned int b;
+
+unsigned int
+fn1 (unsigned int d)
+{
+ int i;
+
+ for (i = 0; i < 1000; i++)
+ b |= d;
+
+ return b;
+}
diff --git a/gcc/tree-parloops.c b/gcc/tree-parloops.c
index 84f18bd..394aba8 100644
--- a/gcc/tree-parloops.c
+++ b/gcc/tree-parloops.c
@@ -2595,6 +2595,14 @@ try_create_reduction_list (loop_p loop,
" FAILED: it is not a part of reduction.\n");
return false;
}
+ if (red->keep_res != NULL)
+ {
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ fprintf (dump_file,
+ " FAILED: reduction has multiple exit phis.\n");
+ return false;
+ }
+ red->keep_res = phi;
if (dump_file && (dump_flags & TDF_DETAILS))
{
fprintf (dump_file, "reduction phi is ");