From f30d4934a90a6121674d882d391dc09d8fce190c Mon Sep 17 00:00:00 2001 From: Bin Cheng Date: Tue, 26 Mar 2019 11:12:37 +0000 Subject: [PATCH] re PR tree-optimization/81740 (wrong code at -O3 in both 32-bit and 64-bit modes on x86_64-linux-gnu) 2019-03-26 Bin Cheng PR tree-optimization/81740 * tree-vect-data-refs.c (vect_analyze_data_ref_dependence): In case of outer loop vectorization, check for backward dependence at the inner loop if outer loop dependence is reversed. * gcc.dg/vect/pr81740-1.c: New testcase. * gcc.dg/vect/pr81740-2.c: Likewise. From-SVN: r269938 --- gcc/ChangeLog | 7 +++++++ gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/gcc.dg/vect/pr81740-1.c | 22 ++++++++++++++++++++++ gcc/testsuite/gcc.dg/vect/pr81740-2.c | 24 ++++++++++++++++++++++++ gcc/tree-vect-data-refs.c | 18 ++++++++++++++++-- 5 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/vect/pr81740-1.c create mode 100644 gcc/testsuite/gcc.dg/vect/pr81740-2.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 4af4550..2801b39 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2019-03-26 Bin Cheng + + PR tree-optimization/81740 + * tree-vect-data-refs.c (vect_analyze_data_ref_dependence): + In case of outer loop vectorization, check for backward dependence + at the inner loop if outer loop dependence is reversed. + 2019-03-26 Alan Modra * config/rs6000/rs6000.c (rs6000_init_hard_regno_mode_ok): Correct diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 88751b0..39fb944 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2019-03-26 Bin Cheng + + PR tree-optimization/81740 + * gcc.dg/vect/pr81740-1.c: New testcase. + * gcc.dg/vect/pr81740-2.c: Likewise. + 2019-03-26 Iain Buclaw * gdc.test/gdc-test.exp (gdc-do-test): Sort and remove duplicate diff --git a/gcc/testsuite/gcc.dg/vect/pr81740-1.c b/gcc/testsuite/gcc.dg/vect/pr81740-1.c new file mode 100644 index 0000000..d2226fc --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr81740-1.c @@ -0,0 +1,22 @@ +/* { dg-do run } */ +/* { dg-require-effective-target vect_int } */ + +#include "tree-vect.h" + +int a[8][10] = { [2][5] = 4 }, c; + +int +main () +{ + short b; + int i, d; + check_vect (); + for (b = 4; b >= 0; b--) + for (c = 0; c <= 6; c++) + a[c + 1][b + 2] = a[c][b + 1]; + for (i = 0; i < 8; i++) + for (d = 0; d < 10; d++) + if (a[i][d] != (i == 3 && d == 6) * 4) + __builtin_abort (); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/vect/pr81740-2.c b/gcc/testsuite/gcc.dg/vect/pr81740-2.c new file mode 100644 index 0000000..76637ad --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr81740-2.c @@ -0,0 +1,24 @@ +/* { dg-do run } */ +/* { dg-require-effective-target vect_int } */ + +#include "tree-vect.h" + +int a[8][10] = { [2][5] = 4 }, c; + +int +main () +{ + short b; + int i, d; + check_vect (); + for (b = 4; b >= 0; b--) + for (c = 6; c >= 0; c--) + a[c + 1][b + 2] = a[c][b + 1]; + for (i = 0; i < 8; i++) + for (d = 0; d < 10; d++) + if (a[i][d] != (i == 3 && d == 6) * 4) + __builtin_abort (); + return 0; +} + +/* { dg-final { scan-tree-dump "OUTER LOOP VECTORIZED" "vect" } } */ diff --git a/gcc/tree-vect-data-refs.c b/gcc/tree-vect-data-refs.c index 7bbd47f..1380088 100644 --- a/gcc/tree-vect-data-refs.c +++ b/gcc/tree-vect-data-refs.c @@ -473,8 +473,22 @@ vect_analyze_data_ref_dependence (struct data_dependence_relation *ddr, reversed (to make distance vector positive), and the actual distance is negative. */ if (dump_enabled_p ()) - dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, + dump_printf_loc (MSG_NOTE, vect_location, "dependence distance negative.\n"); + /* When doing outer loop vectorization, we need to check if there is + a backward dependence at the inner loop level if the dependence + at the outer loop is reversed. See PR81740. */ + if (nested_in_vect_loop_p (loop, stmtinfo_a) + || nested_in_vect_loop_p (loop, stmtinfo_b)) + { + unsigned inner_depth = index_in_loop_nest (loop->inner->num, + DDR_LOOP_NEST (ddr)); + if (dist_v[inner_depth] < 0) + return opt_result::failure_at (stmtinfo_a->stmt, + "not vectorized, dependence " + "between data-refs %T and %T\n", + DR_REF (dra), DR_REF (drb)); + } /* Record a negative dependence distance to later limit the amount of stmt copying / unrolling we can perform. Only need to handle read-after-write dependence. */ @@ -490,7 +504,7 @@ vect_analyze_data_ref_dependence (struct data_dependence_relation *ddr, { /* The dependence distance requires reduction of the maximal vectorization factor. */ - *max_vf = abs (dist); + *max_vf = abs_dist; if (dump_enabled_p ()) dump_printf_loc (MSG_NOTE, vect_location, "adjusting maximal vectorization factor to %i\n", -- 2.7.4