* [PATCH] Fix IPA CP where it forgot to add a reference in cgraph
@ 2016-12-19 10:17 Martin Liška
2016-12-19 10:19 ` Jakub Jelinek
2016-12-20 10:22 ` Martin Jambor
0 siblings, 2 replies; 9+ messages in thread
From: Martin Liška @ 2016-12-19 10:17 UTC (permalink / raw)
To: GCC Patches; +Cc: Jan Hubicka, Martin Jambor
[-- Attachment #1: Type: text/plain, Size: 395 bytes --]
Hello.
Building mariadb with -flto exposes a bug which I also used to see in Firefox. It's
caused by IPA CP starting from r236418, where the pass started to propagate const
VAR_DECLs. Problem is that the pass does not update call graph by adding IPA_REF_READ
of the propagated variable.
Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.
Ready to be installed?
Martin
[-- Attachment #2: 0001-Fix-IPA-CP-where-it-forgot-to-add-a-reference-in-cgr.patch --]
[-- Type: text/x-patch, Size: 2393 bytes --]
From 477e81fde08d0520ce552ec8baa0349590dc683c Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Mon, 19 Dec 2016 11:03:34 +0100
Subject: [PATCH] Fix IPA CP where it forgot to add a reference in cgraph
gcc/ChangeLog:
2016-12-19 Martin Liska <mliska@suse.cz>
* cgraphclones.c (cgraph_node::create_virtual_clone):
Create either IPA_REF_LOAD of IPA_REF_READ depending on
whether new_tree is a VAR_DECL or an ADDR_EXPR.
* ipa-cp.c (create_specialized_node): Add reference just for
ADDR_EXPRs.
* symtab.c (symtab_node::maybe_create_reference): Remove guard
as it's guarded in callers.
---
gcc/cgraphclones.c | 6 +++++-
gcc/ipa-cp.c | 3 ++-
gcc/symtab.c | 2 --
3 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/gcc/cgraphclones.c b/gcc/cgraphclones.c
index 349892dab67..93c86e6a1cc 100644
--- a/gcc/cgraphclones.c
+++ b/gcc/cgraphclones.c
@@ -624,7 +624,11 @@ cgraph_node::create_virtual_clone (vec<cgraph_edge *> redirect_callers,
|| in_lto_p)
new_node->unique_name = true;
FOR_EACH_VEC_SAFE_ELT (tree_map, i, map)
- new_node->maybe_create_reference (map->new_tree, IPA_REF_ADDR, NULL);
+ {
+ ipa_ref_use use_type
+ = TREE_CODE (map->new_tree) == VAR_DECL ? IPA_REF_ADDR : IPA_REF_LOAD;
+ new_node->maybe_create_reference (map->new_tree, use_type, NULL);
+ }
if (ipa_transforms_to_apply.exists ())
new_node->ipa_transforms_to_apply
diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c
index d3b50524457..fd312b56fde 100644
--- a/gcc/ipa-cp.c
+++ b/gcc/ipa-cp.c
@@ -3787,7 +3787,8 @@ create_specialized_node (struct cgraph_node *node,
args_to_skip, "constprop");
ipa_set_node_agg_value_chain (new_node, aggvals);
for (av = aggvals; av; av = av->next)
- new_node->maybe_create_reference (av->value, IPA_REF_ADDR, NULL);
+ if (TREE_CODE (av->value) == ADDR_EXPR)
+ new_node->maybe_create_reference (av->value, IPA_REF_ADDR, NULL);
if (dump_file && (dump_flags & TDF_DETAILS))
{
diff --git a/gcc/symtab.c b/gcc/symtab.c
index 73168a8db09..562a4a2f6a6 100644
--- a/gcc/symtab.c
+++ b/gcc/symtab.c
@@ -598,8 +598,6 @@ symtab_node::maybe_create_reference (tree val, enum ipa_ref_use use_type,
gimple *stmt)
{
STRIP_NOPS (val);
- if (TREE_CODE (val) != ADDR_EXPR)
- return NULL;
val = get_base_var (val);
if (val && VAR_OR_FUNCTION_DECL_P (val))
{
--
2.11.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] Fix IPA CP where it forgot to add a reference in cgraph
2016-12-19 10:17 [PATCH] Fix IPA CP where it forgot to add a reference in cgraph Martin Liška
@ 2016-12-19 10:19 ` Jakub Jelinek
2016-12-20 10:22 ` Martin Jambor
1 sibling, 0 replies; 9+ messages in thread
From: Jakub Jelinek @ 2016-12-19 10:19 UTC (permalink / raw)
To: Martin Liška; +Cc: GCC Patches, Jan Hubicka, Martin Jambor
Hi!
Just a nit, defer actual review to Honza or Richard.
On Mon, Dec 19, 2016 at 11:09:52AM +0100, Martin Liška wrote:
> + ipa_ref_use use_type
> + = TREE_CODE (map->new_tree) == VAR_DECL ? IPA_REF_ADDR : IPA_REF_LOAD;
= VAR_P (map->new_tree) ? IPA_REF_ADDR : IPA_REF_LOAD.
please.
Jakub
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] Fix IPA CP where it forgot to add a reference in cgraph
2016-12-19 10:17 [PATCH] Fix IPA CP where it forgot to add a reference in cgraph Martin Liška
2016-12-19 10:19 ` Jakub Jelinek
@ 2016-12-20 10:22 ` Martin Jambor
2016-12-20 14:57 ` Martin Liška
1 sibling, 1 reply; 9+ messages in thread
From: Martin Jambor @ 2016-12-20 10:22 UTC (permalink / raw)
To: Martin Liška; +Cc: GCC Patches, Jan Hubicka
Hi,
On Mon, Dec 19, 2016 at 11:09:52AM +0100, Martin Liska wrote:
> Hello.
>
> Building mariadb with -flto exposes a bug which I also used to see
> in Firefox. It's caused by IPA CP starting from r236418, where the
> pass started to propagate const VAR_DECLs. Problem is that the pass
> does not update call graph by adding IPA_REF_READ of the propagated
> variable.
>
> Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.
>
> Ready to be installed?
Honza needs to have a look at this but since I have suggested this
approach, I am of course fine with it, except that...
> Martin
> From 477e81fde08d0520ce552ec8baa0349590dc683c Mon Sep 17 00:00:00 2001
> From: marxin <mliska@suse.cz>
> Date: Mon, 19 Dec 2016 11:03:34 +0100
> Subject: [PATCH] Fix IPA CP where it forgot to add a reference in cgraph
>
> gcc/ChangeLog:
>
> 2016-12-19 Martin Liska <mliska@suse.cz>
>
> * cgraphclones.c (cgraph_node::create_virtual_clone):
> Create either IPA_REF_LOAD of IPA_REF_READ depending on
> whether new_tree is a VAR_DECL or an ADDR_EXPR.
> * ipa-cp.c (create_specialized_node): Add reference just for
> ADDR_EXPRs.
> * symtab.c (symtab_node::maybe_create_reference): Remove guard
> as it's guarded in callers.
> ---
> gcc/cgraphclones.c | 6 +++++-
> gcc/ipa-cp.c | 3 ++-
> gcc/symtab.c | 2 --
> 3 files changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/gcc/cgraphclones.c b/gcc/cgraphclones.c
> index 349892dab67..93c86e6a1cc 100644
> --- a/gcc/cgraphclones.c
> +++ b/gcc/cgraphclones.c
> @@ -624,7 +624,11 @@ cgraph_node::create_virtual_clone (vec<cgraph_edge *> redirect_callers,
> || in_lto_p)
> new_node->unique_name = true;
> FOR_EACH_VEC_SAFE_ELT (tree_map, i, map)
> - new_node->maybe_create_reference (map->new_tree, IPA_REF_ADDR, NULL);
> + {
> + ipa_ref_use use_type
> + = TREE_CODE (map->new_tree) == VAR_DECL ? IPA_REF_ADDR : IPA_REF_LOAD;
...this test should be for ADDR_EXPR here. Or you could switch the
IPA_REF_* constants the other way round which I bet is going to have
the same effect in practice, but personally, I'd test for ADDR_EXPR.
Thanks,
Martin
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] Fix IPA CP where it forgot to add a reference in cgraph
2016-12-20 10:22 ` Martin Jambor
@ 2016-12-20 14:57 ` Martin Liška
2017-01-10 10:50 ` Martin Liška
2017-01-18 22:32 ` Jan Hubicka
0 siblings, 2 replies; 9+ messages in thread
From: Martin Liška @ 2016-12-20 14:57 UTC (permalink / raw)
To: GCC Patches, Jan Hubicka
[-- Attachment #1: Type: text/plain, Size: 365 bytes --]
On 12/20/2016 11:06 AM, Martin Jambor wrote:
> ...this test should be for ADDR_EXPR here. Or you could switch the
> IPA_REF_* constants the other way round which I bet is going to have
> the same effect in practice, but personally, I'd test for ADDR_EXPR.
Thanks for the note, fixed (and tested in second version of the patch).
Martin
>
> Thanks,
>
> Martin
[-- Attachment #2: 0001-Fix-IPA-CP-where-it-forgot-to-add-a-reference-in-cgr-v2.patch --]
[-- Type: text/x-patch, Size: 2394 bytes --]
From 2e29080e44cce899f9d5181185aba0a8a8791a9a Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Mon, 19 Dec 2016 11:03:34 +0100
Subject: [PATCH] Fix IPA CP where it forgot to add a reference in cgraph
gcc/ChangeLog:
2016-12-19 Martin Liska <mliska@suse.cz>
* cgraphclones.c (cgraph_node::create_virtual_clone):
Create either IPA_REF_LOAD of IPA_REF_READ depending on
whether new_tree is a VAR_DECL or an ADDR_EXPR.
* ipa-cp.c (create_specialized_node): Add reference just for
ADDR_EXPRs.
* symtab.c (symtab_node::maybe_create_reference): Remove guard
as it's guarded in callers.
---
gcc/cgraphclones.c | 6 +++++-
gcc/ipa-cp.c | 3 ++-
gcc/symtab.c | 2 --
3 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/gcc/cgraphclones.c b/gcc/cgraphclones.c
index 349892dab67..6c8fe156f23 100644
--- a/gcc/cgraphclones.c
+++ b/gcc/cgraphclones.c
@@ -624,7 +624,11 @@ cgraph_node::create_virtual_clone (vec<cgraph_edge *> redirect_callers,
|| in_lto_p)
new_node->unique_name = true;
FOR_EACH_VEC_SAFE_ELT (tree_map, i, map)
- new_node->maybe_create_reference (map->new_tree, IPA_REF_ADDR, NULL);
+ {
+ ipa_ref_use use_type
+ = TREE_CODE (map->new_tree) == ADDR_EXPR ? IPA_REF_ADDR : IPA_REF_LOAD;
+ new_node->maybe_create_reference (map->new_tree, use_type, NULL);
+ }
if (ipa_transforms_to_apply.exists ())
new_node->ipa_transforms_to_apply
diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c
index d3b50524457..fd312b56fde 100644
--- a/gcc/ipa-cp.c
+++ b/gcc/ipa-cp.c
@@ -3787,7 +3787,8 @@ create_specialized_node (struct cgraph_node *node,
args_to_skip, "constprop");
ipa_set_node_agg_value_chain (new_node, aggvals);
for (av = aggvals; av; av = av->next)
- new_node->maybe_create_reference (av->value, IPA_REF_ADDR, NULL);
+ if (TREE_CODE (av->value) == ADDR_EXPR)
+ new_node->maybe_create_reference (av->value, IPA_REF_ADDR, NULL);
if (dump_file && (dump_flags & TDF_DETAILS))
{
diff --git a/gcc/symtab.c b/gcc/symtab.c
index 73168a8db09..562a4a2f6a6 100644
--- a/gcc/symtab.c
+++ b/gcc/symtab.c
@@ -598,8 +598,6 @@ symtab_node::maybe_create_reference (tree val, enum ipa_ref_use use_type,
gimple *stmt)
{
STRIP_NOPS (val);
- if (TREE_CODE (val) != ADDR_EXPR)
- return NULL;
val = get_base_var (val);
if (val && VAR_OR_FUNCTION_DECL_P (val))
{
--
2.11.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] Fix IPA CP where it forgot to add a reference in cgraph
2016-12-20 14:57 ` Martin Liška
@ 2017-01-10 10:50 ` Martin Liška
2017-01-18 22:32 ` Jan Hubicka
1 sibling, 0 replies; 9+ messages in thread
From: Martin Liška @ 2017-01-10 10:50 UTC (permalink / raw)
To: GCC Patches, Jan Hubicka
PING^1
On 12/20/2016 03:55 PM, Martin Liška wrote:
> On 12/20/2016 11:06 AM, Martin Jambor wrote:
>> ...this test should be for ADDR_EXPR here. Or you could switch the
>> IPA_REF_* constants the other way round which I bet is going to have
>> the same effect in practice, but personally, I'd test for ADDR_EXPR.
>
> Thanks for the note, fixed (and tested in second version of the patch).
>
> Martin
>
>>
>> Thanks,
>>
>> Martin
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] Fix IPA CP where it forgot to add a reference in cgraph
2016-12-20 14:57 ` Martin Liška
2017-01-10 10:50 ` Martin Liška
@ 2017-01-18 22:32 ` Jan Hubicka
2017-01-19 15:09 ` Martin Liška
1 sibling, 1 reply; 9+ messages in thread
From: Jan Hubicka @ 2017-01-18 22:32 UTC (permalink / raw)
To: Martin Liška; +Cc: GCC Patches, Jan Hubicka
>
> 2016-12-19 Martin Liska <mliska@suse.cz>
>
> * cgraphclones.c (cgraph_node::create_virtual_clone):
> Create either IPA_REF_LOAD of IPA_REF_READ depending on
> whether new_tree is a VAR_DECL or an ADDR_EXPR.
> * ipa-cp.c (create_specialized_node): Add reference just for
> ADDR_EXPRs.
> * symtab.c (symtab_node::maybe_create_reference): Remove guard
> as it's guarded in callers.
> ---
> gcc/cgraphclones.c | 6 +++++-
> gcc/ipa-cp.c | 3 ++-
> gcc/symtab.c | 2 --
> 3 files changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/gcc/cgraphclones.c b/gcc/cgraphclones.c
> index 349892dab67..6c8fe156f23 100644
> --- a/gcc/cgraphclones.c
> +++ b/gcc/cgraphclones.c
> @@ -624,7 +624,11 @@ cgraph_node::create_virtual_clone (vec<cgraph_edge *> redirect_callers,
> || in_lto_p)
> new_node->unique_name = true;
> FOR_EACH_VEC_SAFE_ELT (tree_map, i, map)
> - new_node->maybe_create_reference (map->new_tree, IPA_REF_ADDR, NULL);
> + {
> + ipa_ref_use use_type
> + = TREE_CODE (map->new_tree) == ADDR_EXPR ? IPA_REF_ADDR : IPA_REF_LOAD;
> + new_node->maybe_create_reference (map->new_tree, use_type, NULL);
> + }
>
> if (ipa_transforms_to_apply.exists ())
> new_node->ipa_transforms_to_apply
> diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c
> index d3b50524457..fd312b56fde 100644
> --- a/gcc/ipa-cp.c
> +++ b/gcc/ipa-cp.c
> @@ -3787,7 +3787,8 @@ create_specialized_node (struct cgraph_node *node,
> args_to_skip, "constprop");
> ipa_set_node_agg_value_chain (new_node, aggvals);
> for (av = aggvals; av; av = av->next)
> - new_node->maybe_create_reference (av->value, IPA_REF_ADDR, NULL);
> + if (TREE_CODE (av->value) == ADDR_EXPR)
> + new_node->maybe_create_reference (av->value, IPA_REF_ADDR, NULL);
>
> if (dump_file && (dump_flags & TDF_DETAILS))
> {
> diff --git a/gcc/symtab.c b/gcc/symtab.c
> index 73168a8db09..562a4a2f6a6 100644
> --- a/gcc/symtab.c
> +++ b/gcc/symtab.c
> @@ -598,8 +598,6 @@ symtab_node::maybe_create_reference (tree val, enum ipa_ref_use use_type,
> gimple *stmt)
> {
> STRIP_NOPS (val);
> - if (TREE_CODE (val) != ADDR_EXPR)
> - return NULL;
Perhaps maybe_create_reference should drop the use_type argument (it is used
with IPA_REF_ADDR only anyway) and should do the parsing itself?
I.e. if there is reference do IPA_REF_LOAD and if there is ADDR_EXPR do
IPA_REF_ADDR. Why one can not have handled component refs in there?
Honza
> val = get_base_var (val);
> if (val && VAR_OR_FUNCTION_DECL_P (val))
> {
> --
> 2.11.0
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] Fix IPA CP where it forgot to add a reference in cgraph
2017-01-18 22:32 ` Jan Hubicka
@ 2017-01-19 15:09 ` Martin Liška
2017-01-19 15:14 ` Jan Hubicka
0 siblings, 1 reply; 9+ messages in thread
From: Martin Liška @ 2017-01-19 15:09 UTC (permalink / raw)
To: Jan Hubicka; +Cc: GCC Patches
[-- Attachment #1: Type: text/plain, Size: 2883 bytes --]
On 01/18/2017 11:18 PM, Jan Hubicka wrote:
>>
>> 2016-12-19 Martin Liska <mliska@suse.cz>
>>
>> * cgraphclones.c (cgraph_node::create_virtual_clone):
>> Create either IPA_REF_LOAD of IPA_REF_READ depending on
>> whether new_tree is a VAR_DECL or an ADDR_EXPR.
>> * ipa-cp.c (create_specialized_node): Add reference just for
>> ADDR_EXPRs.
>> * symtab.c (symtab_node::maybe_create_reference): Remove guard
>> as it's guarded in callers.
>> ---
>> gcc/cgraphclones.c | 6 +++++-
>> gcc/ipa-cp.c | 3 ++-
>> gcc/symtab.c | 2 --
>> 3 files changed, 7 insertions(+), 4 deletions(-)
>>
>> diff --git a/gcc/cgraphclones.c b/gcc/cgraphclones.c
>> index 349892dab67..6c8fe156f23 100644
>> --- a/gcc/cgraphclones.c
>> +++ b/gcc/cgraphclones.c
>> @@ -624,7 +624,11 @@ cgraph_node::create_virtual_clone (vec<cgraph_edge *> redirect_callers,
>> || in_lto_p)
>> new_node->unique_name = true;
>> FOR_EACH_VEC_SAFE_ELT (tree_map, i, map)
>> - new_node->maybe_create_reference (map->new_tree, IPA_REF_ADDR, NULL);
>> + {
>> + ipa_ref_use use_type
>> + = TREE_CODE (map->new_tree) == ADDR_EXPR ? IPA_REF_ADDR : IPA_REF_LOAD;
>> + new_node->maybe_create_reference (map->new_tree, use_type, NULL);
>> + }
>>
>> if (ipa_transforms_to_apply.exists ())
>> new_node->ipa_transforms_to_apply
>> diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c
>> index d3b50524457..fd312b56fde 100644
>> --- a/gcc/ipa-cp.c
>> +++ b/gcc/ipa-cp.c
>> @@ -3787,7 +3787,8 @@ create_specialized_node (struct cgraph_node *node,
>> args_to_skip, "constprop");
>> ipa_set_node_agg_value_chain (new_node, aggvals);
>> for (av = aggvals; av; av = av->next)
>> - new_node->maybe_create_reference (av->value, IPA_REF_ADDR, NULL);
>> + if (TREE_CODE (av->value) == ADDR_EXPR)
>> + new_node->maybe_create_reference (av->value, IPA_REF_ADDR, NULL);
>>
>> if (dump_file && (dump_flags & TDF_DETAILS))
>> {
>> diff --git a/gcc/symtab.c b/gcc/symtab.c
>> index 73168a8db09..562a4a2f6a6 100644
>> --- a/gcc/symtab.c
>> +++ b/gcc/symtab.c
>> @@ -598,8 +598,6 @@ symtab_node::maybe_create_reference (tree val, enum ipa_ref_use use_type,
>> gimple *stmt)
>> {
>> STRIP_NOPS (val);
>> - if (TREE_CODE (val) != ADDR_EXPR)
>> - return NULL;
>
> Perhaps maybe_create_reference should drop the use_type argument (it is used
> with IPA_REF_ADDR only anyway) and should do the parsing itself?
> I.e. if there is reference do IPA_REF_LOAD and if there is ADDR_EXPR do
> IPA_REF_ADDR. Why one can not have handled component refs in there?
>
> Honza
Ok, this is updated version that I've been testing. Added a reference to PR that
we just identified that is also caused by IPA CP and will be fixed by the patch.
Thanks,
Martin
>> val = get_base_var (val);
>> if (val && VAR_OR_FUNCTION_DECL_P (val))
>> {
>> --
>> 2.11.0
>>
>
[-- Attachment #2: 0001-Fix-IPA-CP-where-it-forgot-to-add-a-reference-in-cgr.patch --]
[-- Type: text/x-patch, Size: 3783 bytes --]
From f42c5ea2ce09ecbf02e472ce31add53189115d66 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Mon, 19 Dec 2016 11:03:34 +0100
Subject: [PATCH] Fix IPA CP where it forgot to add a reference in cgraph (PR
ipa/71190).
gcc/ChangeLog:
2017-01-19 Martin Liska <mliska@suse.cz>
PR ipa/71190
* cgraph.h (maybe_create_reference): Remove argument and
update comment.
* cgraphclones.c (cgraph_node::create_virtual_clone): Remove one
argument.
* ipa-cp.c (create_specialized_node): Likewise.
* symtab.c (symtab_node::maybe_create_reference): Handle
VAR_DECLs and ADDR_EXPRs and select ipa_ref_use type.
---
gcc/cgraph.h | 6 ++----
gcc/cgraphclones.c | 2 +-
gcc/ipa-cp.c | 2 +-
gcc/symtab.c | 24 +++++++++++++++---------
4 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/gcc/cgraph.h b/gcc/cgraph.h
index db2915c5751..5410a71176a 100644
--- a/gcc/cgraph.h
+++ b/gcc/cgraph.h
@@ -131,11 +131,9 @@ public:
enum ipa_ref_use use_type, gimple *stmt);
/* If VAL is a reference to a function or a variable, add a reference from
- this symtab_node to the corresponding symbol table node. USE_TYPE specify
- type of the use and STMT the statement (if it exists). Return the new
+ this symtab_node to the corresponding symbol table node. Return the new
reference or NULL if none was created. */
- ipa_ref *maybe_create_reference (tree val, enum ipa_ref_use use_type,
- gimple *stmt);
+ ipa_ref *maybe_create_reference (tree val, gimple *stmt);
/* Clone all references from symtab NODE to this symtab_node. */
void clone_references (symtab_node *node);
diff --git a/gcc/cgraphclones.c b/gcc/cgraphclones.c
index a17663519a9..c2337e84553 100644
--- a/gcc/cgraphclones.c
+++ b/gcc/cgraphclones.c
@@ -624,7 +624,7 @@ cgraph_node::create_virtual_clone (vec<cgraph_edge *> redirect_callers,
|| in_lto_p)
new_node->unique_name = true;
FOR_EACH_VEC_SAFE_ELT (tree_map, i, map)
- new_node->maybe_create_reference (map->new_tree, IPA_REF_ADDR, NULL);
+ new_node->maybe_create_reference (map->new_tree, NULL);
if (ipa_transforms_to_apply.exists ())
new_node->ipa_transforms_to_apply
diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c
index 9cc903769e8..aa3c9973a66 100644
--- a/gcc/ipa-cp.c
+++ b/gcc/ipa-cp.c
@@ -3786,7 +3786,7 @@ create_specialized_node (struct cgraph_node *node,
args_to_skip, "constprop");
ipa_set_node_agg_value_chain (new_node, aggvals);
for (av = aggvals; av; av = av->next)
- new_node->maybe_create_reference (av->value, IPA_REF_ADDR, NULL);
+ new_node->maybe_create_reference (av->value, NULL);
if (dump_file && (dump_flags & TDF_DETAILS))
{
diff --git a/gcc/symtab.c b/gcc/symtab.c
index 87120970d34..64abf32ae13 100644
--- a/gcc/symtab.c
+++ b/gcc/symtab.c
@@ -588,18 +588,24 @@ symtab_node::create_reference (symtab_node *referred_node,
return ref;
}
-/* If VAL is a reference to a function or a variable, add a reference from
- this symtab_node to the corresponding symbol table node. USE_TYPE specify
- type of the use and STMT the statement (if it exists). Return the new
- reference or NULL if none was created. */
-
ipa_ref *
-symtab_node::maybe_create_reference (tree val, enum ipa_ref_use use_type,
- gimple *stmt)
+symtab_node::maybe_create_reference (tree val, gimple *stmt)
{
STRIP_NOPS (val);
- if (TREE_CODE (val) != ADDR_EXPR)
- return NULL;
+ ipa_ref_use use_type;
+
+ switch (TREE_CODE (val))
+ {
+ case VAR_DECL:
+ use_type = IPA_REF_LOAD;
+ break;
+ case ADDR_EXPR:
+ use_type = IPA_REF_ADDR;
+ break;
+ default:
+ return NULL;
+ }
+
val = get_base_var (val);
if (val && VAR_OR_FUNCTION_DECL_P (val))
{
--
2.11.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] Fix IPA CP where it forgot to add a reference in cgraph
2017-01-19 15:09 ` Martin Liška
@ 2017-01-19 15:14 ` Jan Hubicka
2017-01-20 9:05 ` Martin Liška
0 siblings, 1 reply; 9+ messages in thread
From: Jan Hubicka @ 2017-01-19 15:14 UTC (permalink / raw)
To: Martin Liška; +Cc: Jan Hubicka, GCC Patches
> >> 2016-12-19 Martin Liska <mliska@suse.cz>
> >>
> >> * cgraphclones.c (cgraph_node::create_virtual_clone):
> >> Create either IPA_REF_LOAD of IPA_REF_READ depending on
> >> whether new_tree is a VAR_DECL or an ADDR_EXPR.
> >> * ipa-cp.c (create_specialized_node): Add reference just for
> >> ADDR_EXPRs.
> >> * symtab.c (symtab_node::maybe_create_reference): Remove guard
> >> as it's guarded in callers.
Path is OK
> ipa_ref *
> -symtab_node::maybe_create_reference (tree val, enum ipa_ref_use use_type,
> - gimple *stmt)
> +symtab_node::maybe_create_reference (tree val, gimple *stmt)
> {
> STRIP_NOPS (val);
> - if (TREE_CODE (val) != ADDR_EXPR)
> - return NULL;
> + ipa_ref_use use_type;
> +
> + switch (TREE_CODE (val))
> + {
> + case VAR_DECL:
> + use_type = IPA_REF_LOAD;
> + break;
> + case ADDR_EXPR:
> + use_type = IPA_REF_ADDR;
> + break;
> + default:
> + return NULL;
> + }
I would add assert into default that we don't get handled_component_ref here so we are sure
we don't miss any declarations (because the bug leads to quite esoteric issues, it is better
to be safe than sorry)
Honza
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] Fix IPA CP where it forgot to add a reference in cgraph
2017-01-19 15:14 ` Jan Hubicka
@ 2017-01-20 9:05 ` Martin Liška
0 siblings, 0 replies; 9+ messages in thread
From: Martin Liška @ 2017-01-20 9:05 UTC (permalink / raw)
To: Jan Hubicka; +Cc: GCC Patches
[-- Attachment #1: Type: text/plain, Size: 1329 bytes --]
On 01/19/2017 04:10 PM, Jan Hubicka wrote:
>>>> 2016-12-19 Martin Liska <mliska@suse.cz>
>>>>
>>>> * cgraphclones.c (cgraph_node::create_virtual_clone):
>>>> Create either IPA_REF_LOAD of IPA_REF_READ depending on
>>>> whether new_tree is a VAR_DECL or an ADDR_EXPR.
>>>> * ipa-cp.c (create_specialized_node): Add reference just for
>>>> ADDR_EXPRs.
>>>> * symtab.c (symtab_node::maybe_create_reference): Remove guard
>>>> as it's guarded in callers.
>
> Path is OK
>> ipa_ref *
>> -symtab_node::maybe_create_reference (tree val, enum ipa_ref_use use_type,
>> - gimple *stmt)
>> +symtab_node::maybe_create_reference (tree val, gimple *stmt)
>> {
>> STRIP_NOPS (val);
>> - if (TREE_CODE (val) != ADDR_EXPR)
>> - return NULL;
>> + ipa_ref_use use_type;
>> +
>> + switch (TREE_CODE (val))
>> + {
>> + case VAR_DECL:
>> + use_type = IPA_REF_LOAD;
>> + break;
>> + case ADDR_EXPR:
>> + use_type = IPA_REF_ADDR;
>> + break;
>> + default:
>> + return NULL;
>> + }
>
> I would add assert into default that we don't get handled_component_ref here so we are sure
> we don't miss any declarations (because the bug leads to quite esoteric issues, it is better
> to be safe than sorry)
>
> Honza
>
Done in patch I've just installed as r244687.
Thanks for help,
Martin
[-- Attachment #2: 0001-Fix-IPA-CP-where-it-forgot-to-add-a-reference-in-cgr.patch --]
[-- Type: text/x-patch, Size: 3832 bytes --]
From b0c002ba76312ba7cf38a41b1127ae8a55e89639 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Mon, 19 Dec 2016 11:03:34 +0100
Subject: [PATCH] Fix IPA CP where it forgot to add a reference in cgraph (PR
ipa/71190).
gcc/ChangeLog:
2017-01-19 Martin Liska <mliska@suse.cz>
PR ipa/71190
* cgraph.h (maybe_create_reference): Remove argument and
update comment.
* cgraphclones.c (cgraph_node::create_virtual_clone): Remove one
argument.
* ipa-cp.c (create_specialized_node): Likewise.
* symtab.c (symtab_node::maybe_create_reference): Handle
VAR_DECLs and ADDR_EXPRs and select ipa_ref_use type.
---
gcc/cgraph.h | 6 ++----
gcc/cgraphclones.c | 2 +-
gcc/ipa-cp.c | 2 +-
gcc/symtab.c | 25 ++++++++++++++++---------
4 files changed, 20 insertions(+), 15 deletions(-)
diff --git a/gcc/cgraph.h b/gcc/cgraph.h
index db2915c5751..5410a71176a 100644
--- a/gcc/cgraph.h
+++ b/gcc/cgraph.h
@@ -131,11 +131,9 @@ public:
enum ipa_ref_use use_type, gimple *stmt);
/* If VAL is a reference to a function or a variable, add a reference from
- this symtab_node to the corresponding symbol table node. USE_TYPE specify
- type of the use and STMT the statement (if it exists). Return the new
+ this symtab_node to the corresponding symbol table node. Return the new
reference or NULL if none was created. */
- ipa_ref *maybe_create_reference (tree val, enum ipa_ref_use use_type,
- gimple *stmt);
+ ipa_ref *maybe_create_reference (tree val, gimple *stmt);
/* Clone all references from symtab NODE to this symtab_node. */
void clone_references (symtab_node *node);
diff --git a/gcc/cgraphclones.c b/gcc/cgraphclones.c
index a17663519a9..c2337e84553 100644
--- a/gcc/cgraphclones.c
+++ b/gcc/cgraphclones.c
@@ -624,7 +624,7 @@ cgraph_node::create_virtual_clone (vec<cgraph_edge *> redirect_callers,
|| in_lto_p)
new_node->unique_name = true;
FOR_EACH_VEC_SAFE_ELT (tree_map, i, map)
- new_node->maybe_create_reference (map->new_tree, IPA_REF_ADDR, NULL);
+ new_node->maybe_create_reference (map->new_tree, NULL);
if (ipa_transforms_to_apply.exists ())
new_node->ipa_transforms_to_apply
diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c
index 9cc903769e8..aa3c9973a66 100644
--- a/gcc/ipa-cp.c
+++ b/gcc/ipa-cp.c
@@ -3786,7 +3786,7 @@ create_specialized_node (struct cgraph_node *node,
args_to_skip, "constprop");
ipa_set_node_agg_value_chain (new_node, aggvals);
for (av = aggvals; av; av = av->next)
- new_node->maybe_create_reference (av->value, IPA_REF_ADDR, NULL);
+ new_node->maybe_create_reference (av->value, NULL);
if (dump_file && (dump_flags & TDF_DETAILS))
{
diff --git a/gcc/symtab.c b/gcc/symtab.c
index 87120970d34..c21e7acf28c 100644
--- a/gcc/symtab.c
+++ b/gcc/symtab.c
@@ -588,18 +588,25 @@ symtab_node::create_reference (symtab_node *referred_node,
return ref;
}
-/* If VAL is a reference to a function or a variable, add a reference from
- this symtab_node to the corresponding symbol table node. USE_TYPE specify
- type of the use and STMT the statement (if it exists). Return the new
- reference or NULL if none was created. */
-
ipa_ref *
-symtab_node::maybe_create_reference (tree val, enum ipa_ref_use use_type,
- gimple *stmt)
+symtab_node::maybe_create_reference (tree val, gimple *stmt)
{
STRIP_NOPS (val);
- if (TREE_CODE (val) != ADDR_EXPR)
- return NULL;
+ ipa_ref_use use_type;
+
+ switch (TREE_CODE (val))
+ {
+ case VAR_DECL:
+ use_type = IPA_REF_LOAD;
+ break;
+ case ADDR_EXPR:
+ use_type = IPA_REF_ADDR;
+ break;
+ default:
+ gcc_assert (!handled_component_p (val));
+ return NULL;
+ }
+
val = get_base_var (val);
if (val && VAR_OR_FUNCTION_DECL_P (val))
{
--
2.11.0
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2017-01-20 8:45 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-19 10:17 [PATCH] Fix IPA CP where it forgot to add a reference in cgraph Martin Liška
2016-12-19 10:19 ` Jakub Jelinek
2016-12-20 10:22 ` Martin Jambor
2016-12-20 14:57 ` Martin Liška
2017-01-10 10:50 ` Martin Liška
2017-01-18 22:32 ` Jan Hubicka
2017-01-19 15:09 ` Martin Liška
2017-01-19 15:14 ` Jan Hubicka
2017-01-20 9:05 ` Martin Liška
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).