Commit 53b8a710 by Richard Biener Committed by Richard Biener

re PR tree-optimization/84013 (wrong __restrict clique with inline asm operand)

2018-10-24  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/84013
	* tree-ssa-structalias.c (struct msdi_data): New struct for
	marshalling data to walk_stmt_load_store_ops.
	(maybe_set_dependence_info): Refactor as callback for
	walk_stmt_load_store_ops.
	(compute_dependence_clique): Set restrict info on all stmt kinds.

	* gcc.dg/tree-ssa/restrict-9.c: New testcase.

From-SVN: r265455
parent 19b55958
2018-10-24 Richard Biener <rguenther@suse.de>
PR tree-optimization/84013
* tree-ssa-structalias.c (struct msdi_data): New struct for
marshalling data to walk_stmt_load_store_ops.
(maybe_set_dependence_info): Refactor as callback for
walk_stmt_load_store_ops.
(compute_dependence_clique): Set restrict info on all stmt kinds.
2018-10-24 Martin Liska <mliska@suse.cz> 2018-10-24 Martin Liska <mliska@suse.cz>
* cgraph.c (cgraph_node::dump): * cgraph.c (cgraph_node::dump):
2018-10-24 Richard Biener <rguenther@suse.de> 2018-10-24 Richard Biener <rguenther@suse.de>
PR tree-optimization/84013
* gcc.dg/tree-ssa/restrict-9.c: New testcase.
2018-10-24 Richard Biener <rguenther@suse.de>
PR tree-optimization/87665 PR tree-optimization/87665
* gcc.dg/torture/pr87665.c: New testcase. * gcc.dg/torture/pr87665.c: New testcase.
......
/* { dg-do compile } */
/* { dg-options "-O2 -fdump-tree-optimized-alias" } */
int *abc(int** __restrict a, int** __restrict b)
{
*a = 0; // clique 1 base 1
asm volatile("":"+m"(*b)); // clique 0 base 0 (wrong)
*a = 0; // clique 1 base 1
return *b; // clique 1 base 2 (what it should be)
}
/* { dg-final { scan-tree-dump-times "clique 1 base \[12\]" 5 "optimized" } } */
/* On RTL we can DSE one of the stores of zero, on the GIMPLE level we
do not bother to do disambiguation against asms. */
/* { dg-final { scan-tree-dump-times " = 0;" 1 "optimized" { xfail *-*-* } } } */
/* { dg-final { scan-assembler-times "mov\[^\n\r\]*0" 1 { target { x86_64-*-* i?86-*-* } } } } */
...@@ -7466,33 +7466,40 @@ visit_loadstore (gimple *, tree base, tree ref, void *data) ...@@ -7466,33 +7466,40 @@ visit_loadstore (gimple *, tree base, tree ref, void *data)
return false; return false;
} }
/* If REF is a MEM_REF then assign a clique, base pair to it, updating struct msdi_data {
CLIQUE, *RESTRICT_VAR and LAST_RUID. Return whether dependence info tree ptr;
was assigned to REF. */ unsigned short *clique;
unsigned short *last_ruid;
varinfo_t restrict_var;
};
/* If BASE is a MEM_REF then assign a clique, base pair to it, updating
CLIQUE, *RESTRICT_VAR and LAST_RUID as passed via DATA.
Return whether dependence info was assigned to BASE. */
static bool static bool
maybe_set_dependence_info (tree ref, tree ptr, maybe_set_dependence_info (gimple *, tree base, tree, void *data)
unsigned short &clique, varinfo_t restrict_var,
unsigned short &last_ruid)
{ {
while (handled_component_p (ref)) tree ptr = ((msdi_data *)data)->ptr;
ref = TREE_OPERAND (ref, 0); unsigned short &clique = *((msdi_data *)data)->clique;
if ((TREE_CODE (ref) == MEM_REF unsigned short &last_ruid = *((msdi_data *)data)->last_ruid;
|| TREE_CODE (ref) == TARGET_MEM_REF) varinfo_t restrict_var = ((msdi_data *)data)->restrict_var;
&& TREE_OPERAND (ref, 0) == ptr) if ((TREE_CODE (base) == MEM_REF
|| TREE_CODE (base) == TARGET_MEM_REF)
&& TREE_OPERAND (base, 0) == ptr)
{ {
/* Do not overwrite existing cliques. This avoids overwriting dependence /* Do not overwrite existing cliques. This avoids overwriting dependence
info inlined from a function with restrict parameters inlined info inlined from a function with restrict parameters inlined
into a function with restrict parameters. This usually means we into a function with restrict parameters. This usually means we
prefer to be precise in innermost loops. */ prefer to be precise in innermost loops. */
if (MR_DEPENDENCE_CLIQUE (ref) == 0) if (MR_DEPENDENCE_CLIQUE (base) == 0)
{ {
if (clique == 0) if (clique == 0)
clique = ++cfun->last_clique; clique = ++cfun->last_clique;
if (restrict_var->ruid == 0) if (restrict_var->ruid == 0)
restrict_var->ruid = ++last_ruid; restrict_var->ruid = ++last_ruid;
MR_DEPENDENCE_CLIQUE (ref) = clique; MR_DEPENDENCE_CLIQUE (base) = clique;
MR_DEPENDENCE_BASE (ref) = restrict_var->ruid; MR_DEPENDENCE_BASE (base) = restrict_var->ruid;
return true; return true;
} }
} }
...@@ -7565,18 +7572,11 @@ compute_dependence_clique (void) ...@@ -7565,18 +7572,11 @@ compute_dependence_clique (void)
imm_use_iterator ui; imm_use_iterator ui;
gimple *use_stmt; gimple *use_stmt;
bool used = false; bool used = false;
msdi_data data = { ptr, &clique, &last_ruid, restrict_var };
FOR_EACH_IMM_USE_STMT (use_stmt, ui, ptr) FOR_EACH_IMM_USE_STMT (use_stmt, ui, ptr)
{ used |= walk_stmt_load_store_ops (use_stmt, &data,
/* ??? Calls and asms. */ maybe_set_dependence_info,
if (!gimple_assign_single_p (use_stmt)) maybe_set_dependence_info);
continue;
used |= maybe_set_dependence_info (gimple_assign_lhs (use_stmt),
ptr, clique, restrict_var,
last_ruid);
used |= maybe_set_dependence_info (gimple_assign_rhs1 (use_stmt),
ptr, clique, restrict_var,
last_ruid);
}
if (used) if (used)
{ {
bitmap_set_bit (rvars, restrict_var->id); bitmap_set_bit (rvars, restrict_var->id);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment