* [PATCH] ipa/109607 - properly gimplify conversions introduced by IPA param manipulation
@ 2023-04-27 7:24 Richard Biener
0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2023-04-27 7:24 UTC (permalink / raw)
To: gcc-patches; +Cc: Martin Jambor
The following addresses IPA param manipulation (through IPA SRA)
replacing
BIT_FIELD_REF <*this_8(D), 8, 56>
with
BIT_FIELD_REF <VIEW_CONVERT_EXPR<const struct profile_count>(ISRA.814), 8, 56>
which is supposed to be invalid GIMPLE (ISRA.814 is a register).
There's currently insufficient checking in place to catch this in the
IL verifier but I am working on that as part of fixing PR109594.
The solution for the particular testcase I am running into this is
to split the conversion to a separate stmt. Generally the modification
phase is set up for this but the extra_stmts sequence isn't passed
around everywhere. The following passes it to modify_expression
from modify_assignment when rewriting the RHS.
Bootstrapped and tested on x86_64-unknown-linux-gnu.
OK for trunk?
Thanks,
Richard.
PR ipa/109607
* ipa-param-manipulation.h
(ipa_param_body_adjustments::modify_expression): Add extra_stmts
argument.
* ipa-param-manipulation.cc
(ipa_param_body_adjustments::modify_expression): Likewise.
When we need a conversion and the replacement is a register
split the conversion out.
(ipa_param_body_adjustments::modify_assignment): Pass
extra_stmts to RHS modify_expression.
* g++.dg/torture/pr109607.C: New testcase.
---
gcc/ipa-param-manipulation.cc | 10 ++++++++--
gcc/ipa-param-manipulation.h | 2 +-
gcc/testsuite/g++.dg/torture/pr109607.C | 13 +++++++++++++
3 files changed, 22 insertions(+), 3 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/torture/pr109607.C
diff --git a/gcc/ipa-param-manipulation.cc b/gcc/ipa-param-manipulation.cc
index 42488ee09c3..33dcab9c33c 100644
--- a/gcc/ipa-param-manipulation.cc
+++ b/gcc/ipa-param-manipulation.cc
@@ -1825,7 +1825,8 @@ ipa_param_body_adjustments::replace_removed_params_ssa_names (tree old_name,
necessary conversions. */
bool
-ipa_param_body_adjustments::modify_expression (tree *expr_p, bool convert)
+ipa_param_body_adjustments::modify_expression (tree *expr_p, bool convert,
+ gimple_seq *extra_stmts)
{
tree expr = *expr_p;
@@ -1860,6 +1861,11 @@ ipa_param_body_adjustments::modify_expression (tree *expr_p, bool convert)
gcc_checking_assert (tree_to_shwi (TYPE_SIZE (TREE_TYPE (expr)))
== tree_to_shwi (TYPE_SIZE (TREE_TYPE (repl))));
tree vce = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (expr), repl);
+ if (is_gimple_reg (repl))
+ {
+ gcc_assert (extra_stmts);
+ vce = force_gimple_operand (vce, extra_stmts, true, NULL_TREE);
+ }
*expr_p = vce;
}
else
@@ -1887,7 +1893,7 @@ ipa_param_body_adjustments::modify_assignment (gimple *stmt,
lhs_p = gimple_assign_lhs_ptr (stmt);
any = modify_expression (lhs_p, false);
- any |= modify_expression (rhs_p, false);
+ any |= modify_expression (rhs_p, false, extra_stmts);
if (any
&& !useless_type_conversion_p (TREE_TYPE (*lhs_p), TREE_TYPE (*rhs_p)))
{
diff --git a/gcc/ipa-param-manipulation.h b/gcc/ipa-param-manipulation.h
index 9cc957ae7bb..9798eedf0b6 100644
--- a/gcc/ipa-param-manipulation.h
+++ b/gcc/ipa-param-manipulation.h
@@ -373,7 +373,7 @@ private:
unsigned unit_offset);
ipa_param_body_replacement *lookup_first_base_replacement (tree base);
tree replace_removed_params_ssa_names (tree old_name, gimple *stmt);
- bool modify_expression (tree *expr_p, bool convert);
+ bool modify_expression (tree *expr_p, bool convert, gimple_seq * = nullptr);
bool modify_assignment (gimple *stmt, gimple_seq *extra_stmts);
bool modify_call_stmt (gcall **stmt_p, gimple *orig_stmt);
bool modify_cfun_body ();
diff --git a/gcc/testsuite/g++.dg/torture/pr109607.C b/gcc/testsuite/g++.dg/torture/pr109607.C
new file mode 100644
index 00000000000..f7e2a7457af
--- /dev/null
+++ b/gcc/testsuite/g++.dg/torture/pr109607.C
@@ -0,0 +1,13 @@
+// { dg-do compile }
+// { dg-require-effective-target lp64 }
+
+enum profile_quality { GUESSED_LOCAL };
+struct profile_count {
+ long m_val : 61;
+ profile_quality m_quality : 3;
+ bool verify() {
+ m_quality ? __builtin_abort (), 0 : 0;
+ return m_val == GUESSED_LOCAL;
+ }
+} count;
+void verify_flow_info() { count.verify(); }
--
2.35.3
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] ipa/109607 - properly gimplify conversions introduced by IPA param manipulation
[not found] <notmuch-sha1-303b2e15d6e6379f358f76d79baab4438f9eddca>
@ 2023-04-27 9:49 ` Martin Jambor
0 siblings, 0 replies; 2+ messages in thread
From: Martin Jambor @ 2023-04-27 9:49 UTC (permalink / raw)
To: Richard Biener; +Cc: GCC Patches
Hi,
On Thu, Apr 27 2023, Richard Biener wrote:
> The following addresses IPA param manipulation (through IPA SRA)
> replacing
>
> BIT_FIELD_REF <*this_8(D), 8, 56>
>
> with
>
> BIT_FIELD_REF <VIEW_CONVERT_EXPR<const struct profile_count>(ISRA.814), 8, 56>
>
> which is supposed to be invalid GIMPLE (ISRA.814 is a register).
> There's currently insufficient checking in place to catch this in the
> IL verifier but I am working on that as part of fixing PR109594.
>
> The solution for the particular testcase I am running into this is
> to split the conversion to a separate stmt. Generally the modification
> phase is set up for this but the extra_stmts sequence isn't passed
> around everywhere. The following passes it to modify_expression
> from modify_assignment when rewriting the RHS.
>
> Bootstrapped and tested on x86_64-unknown-linux-gnu.
>
> OK for trunk?
Yes, thank you!
Martin
>
> Thanks,
> Richard.
>
> PR ipa/109607
> * ipa-param-manipulation.h
> (ipa_param_body_adjustments::modify_expression): Add extra_stmts
> argument.
> * ipa-param-manipulation.cc
> (ipa_param_body_adjustments::modify_expression): Likewise.
> When we need a conversion and the replacement is a register
> split the conversion out.
> (ipa_param_body_adjustments::modify_assignment): Pass
> extra_stmts to RHS modify_expression.
>
> * g++.dg/torture/pr109607.C: New testcase.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-04-27 9:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-27 7:24 [PATCH] ipa/109607 - properly gimplify conversions introduced by IPA param manipulation Richard Biener
[not found] <notmuch-sha1-303b2e15d6e6379f358f76d79baab4438f9eddca>
2023-04-27 9:49 ` Martin Jambor
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).