From: Richard Biener <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] tree-optimization/112444 - avoid bougs PHI value-numbering
Date: Thu, 9 Nov 2023 10:50:48 +0000 (UTC) [thread overview]
Message-ID: <20231109105048.araJmsf7aNg4cNBLtFUeGLav0FGA7F5_c3KIsDLTkhQ@z> (raw)
With .DEFERRED_INIT ssa_undefined_value_p () can return true for
values we did not visit (because they proved unreachable) but
are not .VN_TOP. Avoid using those as value which, because they
are not visited, are assumed to be defined outside of the region.
Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.
PR tree-optimization/112444
* tree-ssa-sccvn.cc (visit_phi): Avoid using not visited
defs as undefined vals.
* gcc.dg/torture/pr112444.c: New testcase.
---
gcc/testsuite/gcc.dg/torture/pr112444.c | 65 +++++++++++++++++++++++++
gcc/tree-ssa-sccvn.cc | 16 +++++-
2 files changed, 79 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/torture/pr112444.c
diff --git a/gcc/testsuite/gcc.dg/torture/pr112444.c b/gcc/testsuite/gcc.dg/torture/pr112444.c
new file mode 100644
index 00000000000..61c7ec9b22e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr112444.c
@@ -0,0 +1,65 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-ftrivial-auto-var-init=zero" } */
+
+int qmi_message_pbm_get_all_capabilities_output_capability_basic_information_get_printable_message_offset,
+ qmi_message_pbm_get_all_capabilities_output_capability_basic_information_get_printable_message_init_offset,
+ qmi_message_pbm_get_all_capabilities_output_capability_basic_information_get_printable_message_error,
+ qmi_message_pbm_get_all_capabilities_output_capability_basic_information_get_printable_message_phonebooks_i;
+
+int g_string_new(), g_string_append_len(), qmi_message_tlv_read_guint8();
+
+void qmi_message_pbm_get_all_capabilities_output_capability_basic_information_get_printable_message() {
+ int printable = g_string_new();
+ for (;;) {
+ {
+ if (__builtin_expect(({
+ int _g_boolean_var_4;
+ if (printable)
+ _g_boolean_var_4 = 1;
+ else
+ _g_boolean_var_4 = 0;
+ _g_boolean_var_4;
+ }),
+ 0))
+ g_string_append_len();
+ }
+ unsigned char tmp;
+ qmi_message_tlv_read_guint8(
+ qmi_message_pbm_get_all_capabilities_output_capability_basic_information_get_printable_message_init_offset,
+ qmi_message_pbm_get_all_capabilities_output_capability_basic_information_get_printable_message_offset,
+ tmp,
+ qmi_message_pbm_get_all_capabilities_output_capability_basic_information_get_printable_message_error);
+ {
+ {
+ if (__builtin_expect(({
+ int _g_boolean_var_4;
+ if (printable)
+ _g_boolean_var_4 = 1;
+ else
+ _g_boolean_var_4 = 0;
+ _g_boolean_var_4;
+ }),
+ 0))
+ g_string_append_len();
+ }
+ }
+ for (
+ ;
+ qmi_message_pbm_get_all_capabilities_output_capability_basic_information_get_printable_message_phonebooks_i;) {
+ unsigned char tmp;
+ qmi_message_tlv_read_guint8(&tmp);
+ {
+ if (__builtin_expect(({
+ int _g_boolean_var_4;
+ if (printable)
+ _g_boolean_var_4 = 1;
+ else
+ _g_boolean_var_4 = 0;
+ _g_boolean_var_4;
+ }),
+ 0))
+ g_string_append_len();
+ }
+ }
+ }
+}
diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc
index 0b2c10dcc1a..11537fa3e0b 100644
--- a/gcc/tree-ssa-sccvn.cc
+++ b/gcc/tree-ssa-sccvn.cc
@@ -5911,6 +5911,7 @@ static bool
visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p)
{
tree result, sameval = VN_TOP, seen_undef = NULL_TREE;
+ bool seen_undef_visited = false;
tree backedge_val = NULL_TREE;
bool seen_non_backedge = false;
tree sameval_base = NULL_TREE;
@@ -5941,10 +5942,12 @@ visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p)
if (def == PHI_RESULT (phi))
continue;
++n_executable;
+ bool visited = true;
if (TREE_CODE (def) == SSA_NAME)
{
+ tree val = SSA_VAL (def, &visited);
if (!backedges_varying_p || !(e->flags & EDGE_DFS_BACK))
- def = SSA_VAL (def);
+ def = val;
if (e->flags & EDGE_DFS_BACK)
backedge_val = def;
}
@@ -5956,7 +5959,16 @@ visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p)
else if (TREE_CODE (def) == SSA_NAME
&& ! virtual_operand_p (def)
&& ssa_undefined_value_p (def, false))
- seen_undef = def;
+ {
+ if (!seen_undef
+ /* Avoid having not visited undefined defs if we also have
+ a visited one. */
+ || (!seen_undef_visited && visited))
+ {
+ seen_undef = def;
+ seen_undef_visited = visited;
+ }
+ }
else if (sameval == VN_TOP)
{
sameval = def;
--
2.35.3
reply other threads:[~2023-11-09 10:50 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231109105048.araJmsf7aNg4cNBLtFUeGLav0FGA7F5_c3KIsDLTkhQ@z \
--to=rguenther@suse.de \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).