From d5b5a232d4555659943c2776d1df753e5c0387f3 Mon Sep 17 00:00:00 2001 From: Aditya Kumar Date: Mon, 28 Sep 2015 17:29:59 +0000 Subject: [PATCH] re PR tree-optimization/67700 ([graphite] miscompile due to wrong codegen) fix PR67700 The patch makes the detection of scop parameters in parameter_index_in_region a bit more conservative by discarding scalar variables defined in function of data references defined in the scop. 2015-09-25 Aditya Kumar Sebastian Pop PR tree-optimization/67700 * graphite-sese-to-poly.c (parameter_index_in_region): Call invariant_in_sese_p_rec. (extract_affine): Same. (rewrite_cross_bb_scalar_deps): Call update_ssa. * sese.c (invariant_in_sese_p_rec): Export. Handle vdefs and vuses. * sese.h (invariant_in_sese_p_rec): Declare. * testsuite/gcc.dg/graphite/run-id-pr67700.c: New. Co-Authored-By: Sebastian Pop From-SVN: r228214 --- gcc/ChangeLog | 11 ++++++ gcc/graphite-sese-to-poly.c | 8 ++++- gcc/sese.c | 14 ++++++-- gcc/sese.h | 1 + gcc/testsuite/ChangeLog | 6 ++++ .../gcc.dg/graphite/run-id-pr67700.c | 36 +++++++++++++++++++ 6 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/graphite/run-id-pr67700.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f55f53d8ad2..b7721444a16 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,14 @@ +2015-09-28 Aditya Kumar + Sebastian Pop + + PR tree-optimization/67700 + * graphite-sese-to-poly.c (parameter_index_in_region): Call + invariant_in_sese_p_rec. + (extract_affine): Same. + (rewrite_cross_bb_scalar_deps): Call update_ssa. + * sese.c (invariant_in_sese_p_rec): Export. Handle vdefs and vuses. + * sese.h (invariant_in_sese_p_rec): Declare. + 2015-09-28 David Wohlferd * doc/extend.texi (Asm Labels): Break out text for data vs diff --git a/gcc/graphite-sese-to-poly.c b/gcc/graphite-sese-to-poly.c index 09a2f912f08..3b8dd56d642 100644 --- a/gcc/graphite-sese-to-poly.c +++ b/gcc/graphite-sese-to-poly.c @@ -758,6 +758,9 @@ parameter_index_in_region (tree name, sese region) if (TREE_CODE (TREE_TYPE (name)) != INTEGER_TYPE) return -1; + if (!invariant_in_sese_p_rec (name, region)) + return -1; + i = parameter_index_in_region_1 (name, region); if (i != -1) return i; @@ -813,7 +816,8 @@ extract_affine (scop_p s, tree e, __isl_take isl_space *space) break; case SSA_NAME: - gcc_assert (-1 != parameter_index_in_region_1 (e, SCOP_REGION (s))); + gcc_assert (-1 != parameter_index_in_region_1 (e, s->region) + || !invariant_in_sese_p_rec (e, s->region)); res = extract_affine_name (s, e, space); break; @@ -2462,6 +2466,8 @@ rewrite_cross_bb_scalar_deps (scop_p scop, gimple_stmt_iterator *gsi) def, use_stmt); } + update_ssa (TODO_update_ssa); + return res; } diff --git a/gcc/sese.c b/gcc/sese.c index db8c6291991..2050e2d2a1f 100644 --- a/gcc/sese.c +++ b/gcc/sese.c @@ -760,9 +760,10 @@ set_ifsese_condition (ifsese if_region, tree condition) gsi_insert_after (&gsi, cond_stmt, GSI_NEW_STMT); } -/* Return false if T is completely defined outside REGION. */ +/* Return true when T is defined outside REGION or when no definitions are + variant in REGION. */ -static bool +bool invariant_in_sese_p_rec (tree t, sese region) { ssa_op_iter iter; @@ -776,9 +777,18 @@ invariant_in_sese_p_rec (tree t, sese region) || gimple_code (stmt) == GIMPLE_CALL) return false; + /* VDEF is variant when it is in the region. */ + if (tree vdef = gimple_vdef (stmt)) + return false; + + /* A VUSE may or may not be variant following the VDEFs. */ + if (tree vuse = gimple_vuse (stmt)) + return invariant_in_sese_p_rec (vuse, region); + FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE) { tree use = USE_FROM_PTR (use_p); + if (!defined_in_sese_p (use, region)) continue; diff --git a/gcc/sese.h b/gcc/sese.h index 6ce5cc87ead..0d13d87d2fc 100644 --- a/gcc/sese.h +++ b/gcc/sese.h @@ -64,6 +64,7 @@ extern edge copy_bb_and_scalar_dependences (basic_block, sese, edge, vec , bool *); extern struct loop *outermost_loop_in_sese (sese, basic_block); extern tree scalar_evolution_in_region (sese, loop_p, tree); +extern bool invariant_in_sese_p_rec (tree, sese); /* Check that SESE contains LOOP. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c2f693b7e33..bee7aedf77d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2015-09-28 Aditya Kumar + Sebastian Pop + + PR tree-optimization/67700 + * testsuite/gcc.dg/graphite/run-id-pr67700.c: New. + 2015-09-28 Oleg Endo PR target/54236 diff --git a/gcc/testsuite/gcc.dg/graphite/run-id-pr67700.c b/gcc/testsuite/gcc.dg/graphite/run-id-pr67700.c new file mode 100644 index 00000000000..81d9e7f2680 --- /dev/null +++ b/gcc/testsuite/gcc.dg/graphite/run-id-pr67700.c @@ -0,0 +1,36 @@ +#include +#include + +struct abc { + int a[81]; +} *abcd; + +#define FPMATH_SSE 2 +int global; + +void __attribute__ ((noinline)) foo() +{ + int pos = 0; + int i; + + if (!((global & FPMATH_SSE) != 0)) + for (i = 8; i <= 15; i++) + abcd->a[pos++] = i; + + for (i = 29; i <= 36; i++) + abcd->a[pos++] = i; +} + +int main() +{ + int i; + abcd = (struct abc*) malloc (sizeof (struct abc)); + for (i = 0; i <= 80; i++) + abcd->a[i] = 0; + + foo(); + + assert (abcd->a[8] == 29); + + return 0; +} -- 2.30.2