* [PATCH] Handle addresses of more constants in IPA-CP
@ 2023-11-11 12:11 Eric Botcazou
2023-11-11 18:32 ` Jeff Law
2024-11-14 12:48 ` [PATCH] ipa-cp: Fix constant dumping Martin Jambor
0 siblings, 2 replies; 4+ messages in thread
From: Eric Botcazou @ 2023-11-11 12:11 UTC (permalink / raw)
To: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 988 bytes --]
Hi,
IPA-CP can currently handle addresses of scalar constants (CONST_DECL) so this
extends that to addresses of constants in the pool (DECL_IN_CONSTANT_POOL).
Again this is helpful for so-called fat pointers in Ada, i.e. objects that are
semantically pointers but represented by structures made up of two pointers.
This also moves the unused function print_ipcp_constant_value from ipa-cp.cc
to ipa-prop.cc and renames it.
I have an LTO testcase for which this makes a difference, but it's large so
not really suitable for the testsuite.
Bootstrapped/regtested on x86-64/Linux, OK for the mainline?
2023-11-11 Eric Botcazou <ebotcazou@adacore.com>
* ipa-cp.cc (print_ipcp_constant_value): Move to...
(values_equal_for_ipcp_p): Deal with VAR_DECLs from the
constant pool.
* ipa-prop.cc (ipa_print_constant_value): ...here. Likewise.
(ipa_print_node_jump_functions_for_edge): Call the function
ipa_print_constant_value to print IPA_JF_CONST elements.
--
Eric Botcazou
[-- Attachment #2: p.diff --]
[-- Type: text/x-patch, Size: 3489 bytes --]
diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc
index 788157ebd55..34fae065454 100644
--- a/gcc/ipa-cp.cc
+++ b/gcc/ipa-cp.cc
@@ -478,31 +478,21 @@ values_equal_for_ipcp_p (tree x, tree y)
if (TREE_CODE (x) == ADDR_EXPR
&& TREE_CODE (y) == ADDR_EXPR
- && TREE_CODE (TREE_OPERAND (x, 0)) == CONST_DECL
- && TREE_CODE (TREE_OPERAND (y, 0)) == CONST_DECL)
- return operand_equal_p (DECL_INITIAL (TREE_OPERAND (x, 0)),
- DECL_INITIAL (TREE_OPERAND (y, 0)), 0);
+ && (TREE_CODE (TREE_OPERAND (x, 0)) == CONST_DECL
+ || (TREE_CODE (TREE_OPERAND (x, 0)) == VAR_DECL
+ && DECL_IN_CONSTANT_POOL (TREE_OPERAND (x, 0))))
+ && (TREE_CODE (TREE_OPERAND (y, 0)) == CONST_DECL
+ || (TREE_CODE (TREE_OPERAND (y, 0)) == VAR_DECL
+ && DECL_IN_CONSTANT_POOL (TREE_OPERAND (y, 0)))))
+ return TREE_OPERAND (x, 0) == TREE_OPERAND (y, 0)
+ || operand_equal_p (DECL_INITIAL (TREE_OPERAND (x, 0)),
+ DECL_INITIAL (TREE_OPERAND (y, 0)), 0);
else
return operand_equal_p (x, y, 0);
}
/* Print V which is extracted from a value in a lattice to F. */
-static void
-print_ipcp_constant_value (FILE * f, tree v)
-{
- if (TREE_CODE (v) == ADDR_EXPR
- && TREE_CODE (TREE_OPERAND (v, 0)) == CONST_DECL)
- {
- fprintf (f, "& ");
- print_generic_expr (f, DECL_INITIAL (TREE_OPERAND (v, 0)));
- }
- else
- print_generic_expr (f, v);
-}
-
-/* Print V which is extracted from a value in a lattice to F. */
-
static void
print_ipcp_constant_value (FILE * f, ipa_polymorphic_call_context v)
{
diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc
index 827bdb691ba..7de2b788185 100644
--- a/gcc/ipa-prop.cc
+++ b/gcc/ipa-prop.cc
@@ -365,6 +365,24 @@ ipa_initialize_node_params (struct cgraph_node *node)
ipa_populate_param_decls (node, *info->descriptors);
}
+/* Print VAL which is extracted from a jump function to F. */
+
+static void
+ipa_print_constant_value (FILE *f, tree val)
+{
+ print_generic_expr (f, val);
+
+ /* This is in keeping with values_equal_for_ipcp_p. */
+ if (TREE_CODE (val) == ADDR_EXPR
+ && (TREE_CODE (TREE_OPERAND (val, 0)) == CONST_DECL
+ || (TREE_CODE (TREE_OPERAND (val, 0)) == VAR_DECL
+ && DECL_IN_CONSTANT_POOL (TREE_OPERAND (val, 0)))))
+ {
+ fputs (" -> ", f);
+ print_generic_expr (f, DECL_INITIAL (TREE_OPERAND (val, 0)));
+ }
+}
+
/* Print the jump functions associated with call graph edge CS to file F. */
static void
@@ -386,15 +404,8 @@ ipa_print_node_jump_functions_for_edge (FILE *f, struct cgraph_edge *cs)
fprintf (f, "UNKNOWN\n");
else if (type == IPA_JF_CONST)
{
- tree val = jump_func->value.constant.value;
fprintf (f, "CONST: ");
- print_generic_expr (f, val);
- if (TREE_CODE (val) == ADDR_EXPR
- && TREE_CODE (TREE_OPERAND (val, 0)) == CONST_DECL)
- {
- fprintf (f, " -> ");
- print_generic_expr (f, DECL_INITIAL (TREE_OPERAND (val, 0)));
- }
+ ipa_print_constant_value (f, jump_func->value.constant.value);
fprintf (f, "\n");
}
else if (type == IPA_JF_PASS_THROUGH)
@@ -468,7 +479,7 @@ ipa_print_node_jump_functions_for_edge (FILE *f, struct cgraph_edge *cs)
else if (item->jftype == IPA_JF_CONST)
{
fprintf (f, "CONST: ");
- print_generic_expr (f, item->value.constant);
+ ipa_print_constant_value (f, item->value.constant);
}
else if (item->jftype == IPA_JF_UNKNOWN)
fprintf (f, "UNKNOWN: " HOST_WIDE_INT_PRINT_DEC " bits",
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Handle addresses of more constants in IPA-CP
2023-11-11 12:11 [PATCH] Handle addresses of more constants in IPA-CP Eric Botcazou
@ 2023-11-11 18:32 ` Jeff Law
2024-11-14 12:48 ` [PATCH] ipa-cp: Fix constant dumping Martin Jambor
1 sibling, 0 replies; 4+ messages in thread
From: Jeff Law @ 2023-11-11 18:32 UTC (permalink / raw)
To: Eric Botcazou, gcc-patches
On 11/11/23 05:11, Eric Botcazou wrote:
> Hi,
>
> IPA-CP can currently handle addresses of scalar constants (CONST_DECL) so this
> extends that to addresses of constants in the pool (DECL_IN_CONSTANT_POOL).
> Again this is helpful for so-called fat pointers in Ada, i.e. objects that are
> semantically pointers but represented by structures made up of two pointers.
>
> This also moves the unused function print_ipcp_constant_value from ipa-cp.cc
> to ipa-prop.cc and renames it.
>
> I have an LTO testcase for which this makes a difference, but it's large so
> not really suitable for the testsuite.
>
> Bootstrapped/regtested on x86-64/Linux, OK for the mainline?
>
>
> 2023-11-11 Eric Botcazou <ebotcazou@adacore.com>
>
> * ipa-cp.cc (print_ipcp_constant_value): Move to...
> (values_equal_for_ipcp_p): Deal with VAR_DECLs from the
> constant pool.
> * ipa-prop.cc (ipa_print_constant_value): ...here. Likewise.
> (ipa_print_node_jump_functions_for_edge): Call the function
> ipa_print_constant_value to print IPA_JF_CONST elements.
>
OK
jeff
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] ipa-cp: Fix constant dumping
2023-11-11 12:11 [PATCH] Handle addresses of more constants in IPA-CP Eric Botcazou
2023-11-11 18:32 ` Jeff Law
@ 2024-11-14 12:48 ` Martin Jambor
2024-11-14 13:07 ` Eric Botcazou
1 sibling, 1 reply; 4+ messages in thread
From: Martin Jambor @ 2024-11-14 12:48 UTC (permalink / raw)
To: Eric Botcazou, gcc-patches; +Cc: Jan Hubicka, Josef Melcr
Hello,
On Sat, Nov 11 2023, Eric Botcazou wrote:
> Hi,
>
> IPA-CP can currently handle addresses of scalar constants (CONST_DECL) so this
> extends that to addresses of constants in the pool (DECL_IN_CONSTANT_POOL).
> Again this is helpful for so-called fat pointers in Ada, i.e. objects that are
> semantically pointers but represented by structures made up of two pointers.
>
> This also moves the unused function print_ipcp_constant_value from ipa-cp.cc
> to ipa-prop.cc and renames it.
unfortunately, in C++ it is not enough to verify that the source still
builds with a function removed to conclude that the function is unused.
After this patch, dumping of IPA-CP scalar constant lattices is broken
because we attempt to print them with (what was) an
print_ipcp_constant_value overload for polymorphic contexts which are
constructible from trees, so the source compiles, but of course are not
what we want.
I'm about to commit the following patch as obvious (after it has passed
bootstrap and testing on x86_64-linux which is currently underway) and
also backport it to the gcc-14 branch.
Thanks,
Martin
>
> I have an LTO testcase for which this makes a difference, but it's large so
> not really suitable for the testsuite.
>
> Bootstrapped/regtested on x86-64/Linux, OK for the mainline?
>
>
> 2023-11-11 Eric Botcazou <ebotcazou@adacore.com>
>
> * ipa-cp.cc (print_ipcp_constant_value): Move to...
> (values_equal_for_ipcp_p): Deal with VAR_DECLs from the
> constant pool.
> * ipa-prop.cc (ipa_print_constant_value): ...here. Likewise.
> (ipa_print_node_jump_functions_for_edge): Call the function
> ipa_print_constant_value to print IPA_JF_CONST elements.
>
---------- 8< -------------------- 8< -------------------- 8< ----------
Commit gcc-14-5368-ge0787da2633 removed an overloaded variant of
function print_ipcp_constant_value for tree constants. That did not
break build because the other overloaded variant for polymorphic
contexts-has a parameter which is constructible from a tree, but it
prints polymorphic contexts, not tree constants, so we in dumps we got
things like:
param [0]: VARIABLE
ctxs: VARIABLE
Bits: value = 0x0, mask = 0xfffffffffffffffc
[prange] struct S * [1, +INF] MASK 0xfffffffffffffffc VALUE 0x0
ref offset 0: nothing known [scc: 1, from: 1(1.000000)] [loc_time: 0, loc_size: 0, prop_time: 0, prop_size: 0]
ref offset 32: nothing known [scc: 2, from: 1(1.000000)] [loc_time: 0, loc_size: 0, prop_time: 0, prop_size: 0]
ref offset 64: nothing known [scc: 3, from: 1(1.000000)] [loc_time: 0, loc_size: 0, prop_time: 0, prop_size: 0]
instead of:
param [0]: VARIABLE
ctxs: VARIABLE
Bits: value = 0x0, mask = 0xfffffffffffffffc
[prange] struct S * [1, +INF] MASK 0xfffffffffffffffc VALUE 0x0
ref offset 0: 1 [scc: 1, from: 1(1.000000)] [loc_time: 0, loc_size: 0, prop_time: 0, prop_size: 0]
ref offset 32: 64 [scc: 2, from: 1(1.000000)] [loc_time: 0, loc_size: 0, prop_time: 0, prop_size: 0]
ref offset 64: 32 [scc: 3, from: 1(1.000000)] [loc_time: 0, loc_size: 0, prop_time: 0, prop_size: 0]
This commit re-adds the needed overloaded variant though it uses the
printing function added in the aforementioned commit instead of
printing it itself.
gcc/ChangeLog:
2024-11-13 Martin Jambor <mjambor@suse.cz>
* ipa-prop.h (ipa_print_constant_value): Declare.
* ipa-prop.cc (ipa_print_constant_value): Make public.
* ipa-cp.cc (print_ipcp_constant_value): Re-add this overloaded
function for printing tree constants.
gcc/testsuite/ChangeLog:
2024-11-14 Martin Jambor <mjambor@suse.cz>
* gcc.dg/ipa/ipcp-agg-1.c: Add a scan dump for a constant value in
the latice dump.
---
gcc/ipa-cp.cc | 12 +++++++++++-
gcc/ipa-prop.cc | 2 +-
gcc/ipa-prop.h | 1 +
gcc/testsuite/gcc.dg/ipa/ipcp-agg-1.c | 1 +
4 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc
index 212d9ccbbfe..fb65ec0c6a6 100644
--- a/gcc/ipa-cp.cc
+++ b/gcc/ipa-cp.cc
@@ -225,7 +225,17 @@ values_equal_for_ipcp_p (tree x, tree y)
return operand_equal_p (x, y, 0);
}
-/* Print V which is extracted from a value in a lattice to F. */
+/* Print V which is extracted from a value in a lattice to F. This overloaded
+ function is used to print tree constants. */
+
+static void
+print_ipcp_constant_value (FILE * f, tree v)
+{
+ ipa_print_constant_value (f, v);
+}
+
+/* Print V which is extracted from a value in a lattice to F. This overloaded
+ function is used to print constant polymorphic call contexts. */
static void
print_ipcp_constant_value (FILE * f, ipa_polymorphic_call_context v)
diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc
index 599181d0a94..fd18f847e46 100644
--- a/gcc/ipa-prop.cc
+++ b/gcc/ipa-prop.cc
@@ -413,7 +413,7 @@ ipa_initialize_node_params (struct cgraph_node *node)
/* Print VAL which is extracted from a jump function to F. */
-static void
+void
ipa_print_constant_value (FILE *f, tree val)
{
print_generic_expr (f, val);
diff --git a/gcc/ipa-prop.h b/gcc/ipa-prop.h
index 7a05c169c42..a9ef3fe3aa6 100644
--- a/gcc/ipa-prop.h
+++ b/gcc/ipa-prop.h
@@ -1179,6 +1179,7 @@ ipcp_get_transformation_summary (cgraph_node *node)
/* Function formal parameters related computations. */
void ipa_initialize_node_params (struct cgraph_node *node);
+void ipa_print_constant_value (FILE *f, tree val);
bool ipa_propagate_indirect_call_infos (struct cgraph_edge *cs,
vec<cgraph_edge *> *new_edges);
diff --git a/gcc/testsuite/gcc.dg/ipa/ipcp-agg-1.c b/gcc/testsuite/gcc.dg/ipa/ipcp-agg-1.c
index 8cfc18799fa..15f6286e54b 100644
--- a/gcc/testsuite/gcc.dg/ipa/ipcp-agg-1.c
+++ b/gcc/testsuite/gcc.dg/ipa/ipcp-agg-1.c
@@ -30,6 +30,7 @@ entry (void)
foo (&s);
}
+/* { dg-final { scan-ipa-dump "ref offset\[^\n\r\]*: 64\[^\n\r\]*scc:" "cp" } } */
/* { dg-final { scan-ipa-dump "Creating a specialized node of foo.*for all known contexts" "cp" } } */
/* { dg-final { scan-ipa-dump-times "Aggregate replacements:" 2 "cp" } } */
/* { dg-final { scan-tree-dump-not "->c;" "optimized" } } */
--
2.47.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ipa-cp: Fix constant dumping
2024-11-14 12:48 ` [PATCH] ipa-cp: Fix constant dumping Martin Jambor
@ 2024-11-14 13:07 ` Eric Botcazou
0 siblings, 0 replies; 4+ messages in thread
From: Eric Botcazou @ 2024-11-14 13:07 UTC (permalink / raw)
To: Martin Jambor; +Cc: gcc-patches, Jan Hubicka, Josef Melcr
> unfortunately, in C++ it is not enough to verify that the source still
> builds with a function removed to conclude that the function is unused.
> After this patch, dumping of IPA-CP scalar constant lattices is broken
> because we attempt to print them with (what was) an
> print_ipcp_constant_value overload for polymorphic contexts which are
> constructible from trees, so the source compiles, but of course are not
> what we want.
Another misfeature of C++ indeed! Thanks for fixing the problem.
--
Eric Botcazou
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-11-14 13:07 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-11 12:11 [PATCH] Handle addresses of more constants in IPA-CP Eric Botcazou
2023-11-11 18:32 ` Jeff Law
2024-11-14 12:48 ` [PATCH] ipa-cp: Fix constant dumping Martin Jambor
2024-11-14 13:07 ` Eric Botcazou
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).