From 3c8b06dcc68be1ba6dbb01fbbd32ba2a337dd3b8 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Fri, 22 Feb 2019 08:36:30 +0000 Subject: [PATCH] re PR tree-optimization/87609 (miscompilation with restrict and loop) 2019-02-22 Richard Biener PR tree-optimization/87609 * tree-core.h (tree_base): Document special clique values. * tree-inline.c (remap_dependence_clique): Do not use the special clique value of one. (maybe_set_dependence_info): Use clique one. (clear_dependence_clique): New callback. (compute_dependence_clique): Clear clique one from all refs before assigning it (again). From-SVN: r269097 --- gcc/ChangeLog | 11 +++++++++++ gcc/tree-core.h | 4 +++- gcc/tree-inline.c | 7 ++++++- gcc/tree-ssa-structalias.c | 36 +++++++++++++++++++++++++++++++++++- 4 files changed, 55 insertions(+), 3 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c8cecb35de0..a35b0aa1a51 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,14 @@ +2019-02-22 Richard Biener + + PR tree-optimization/87609 + * tree-core.h (tree_base): Document special clique values. + * tree-inline.c (remap_dependence_clique): Do not use the + special clique value of one. + (maybe_set_dependence_info): Use clique one. + (clear_dependence_clique): New callback. + (compute_dependence_clique): Clear clique one from all refs + before assigning it (again). + 2019-02-21 Martin Sebor * doc/extend.texi (__clear_cache): Correct signature. diff --git a/gcc/tree-core.h b/gcc/tree-core.h index 4541c955403..552196b1b42 100644 --- a/gcc/tree-core.h +++ b/gcc/tree-core.h @@ -1032,7 +1032,9 @@ struct GTY(()) tree_base { expression trees and specify known data non-dependences. For two memory references in a function they are known to not alias if dependence_info.clique are equal and dependence_info.base - are distinct. */ + are distinct. Clique number zero means there is no information, + clique number one is populated from function global information + and thus needs no remapping on transforms like loop unrolling. */ struct { unsigned short clique; unsigned short base; diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 98cfbe31b82..9017da878b1 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -911,7 +911,12 @@ remap_dependence_clique (copy_body_data *id, unsigned short clique) bool existed; unsigned short &newc = id->dependence_map->get_or_insert (clique, &existed); if (!existed) - newc = ++cfun->last_clique; + { + /* Clique 1 is reserved for local ones set by PTA. */ + if (cfun->last_clique == 0) + cfun->last_clique = 1; + newc = ++cfun->last_clique; + } return newc; } diff --git a/gcc/tree-ssa-structalias.c b/gcc/tree-ssa-structalias.c index f930d87840c..15f0872a2af 100644 --- a/gcc/tree-ssa-structalias.c +++ b/gcc/tree-ssa-structalias.c @@ -7495,7 +7495,11 @@ maybe_set_dependence_info (gimple *, tree base, tree, void *data) if (MR_DEPENDENCE_CLIQUE (base) == 0) { if (clique == 0) - clique = ++cfun->last_clique; + { + if (cfun->last_clique == 0) + cfun->last_clique = 1; + clique = 1; + } if (restrict_var->ruid == 0) restrict_var->ruid = ++last_ruid; MR_DEPENDENCE_CLIQUE (base) = clique; @@ -7506,12 +7510,42 @@ maybe_set_dependence_info (gimple *, tree base, tree, void *data) return false; } +/* Clear dependence info for the clique DATA. */ + +static bool +clear_dependence_clique (gimple *, tree base, tree, void *data) +{ + unsigned short clique = (uintptr_t)data; + if ((TREE_CODE (base) == MEM_REF + || TREE_CODE (base) == TARGET_MEM_REF) + && MR_DEPENDENCE_CLIQUE (base) == clique) + { + MR_DEPENDENCE_CLIQUE (base) = 0; + MR_DEPENDENCE_BASE (base) = 0; + } + + return false; +} + /* Compute the set of independend memory references based on restrict tags and their conservative propagation to the points-to sets. */ static void compute_dependence_clique (void) { + /* First clear the special "local" clique. */ + basic_block bb; + if (cfun->last_clique != 0) + FOR_EACH_BB_FN (bb, cfun) + for (gimple_stmt_iterator gsi = gsi_start_bb (bb); + !gsi_end_p (gsi); gsi_next (&gsi)) + { + gimple *stmt = gsi_stmt (gsi); + walk_stmt_load_store_ops (stmt, (void *)(uintptr_t) 1, + clear_dependence_clique, + clear_dependence_clique); + } + unsigned short clique = 0; unsigned short last_ruid = 0; bitmap rvars = BITMAP_ALLOC (NULL); -- 2.30.2