public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] tree-optimization/110669 - bogus matching of loop bitop
Date: Mon, 17 Jul 2023 08:19:40 +0000 (UTC)	[thread overview]
Message-ID: <20230717081940.OqSo02Hi5J-46JCiDxV5U8Q-hby-nO2PjANkvsN3LoI@z> (raw)

The matching code lacked a check that we end up with a PHI node
in the loop header.  This caused us to match a random PHI argument
now catched by the extra PHI_ARG_DEF_FROM_EDGE checking.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

	PR tree-optimization/110669
	* tree-scalar-evolution.cc (analyze_and_compute_bitop_with_inv_effect):
	Check we matched a header PHI.

	* gcc.dg/torture/pr110669.c: New testcase.
---
 gcc/testsuite/gcc.dg/torture/pr110669.c | 15 +++++++++++++++
 gcc/tree-scalar-evolution.cc            |  1 +
 2 files changed, 16 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr110669.c

diff --git a/gcc/testsuite/gcc.dg/torture/pr110669.c b/gcc/testsuite/gcc.dg/torture/pr110669.c
new file mode 100644
index 00000000000..b0a9ea448f4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr110669.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+
+int g_29, func_47_p_48, func_47_p_51_l_129;
+void func_47_p_51()
+{
+  for (;;)
+    {
+      func_47_p_51_l_129 = 0;
+      for (; func_47_p_51_l_129 <= 1; func_47_p_51_l_129 += 1)
+	{
+	  short *l_160 = (short *)(__UINTPTR_TYPE__)(func_47_p_48 || *l_160);
+	  *l_160 &= g_29;
+	}
+    }
+}
diff --git a/gcc/tree-scalar-evolution.cc b/gcc/tree-scalar-evolution.cc
index ba47a684f4b..2abe8fa0b90 100644
--- a/gcc/tree-scalar-evolution.cc
+++ b/gcc/tree-scalar-evolution.cc
@@ -3674,6 +3674,7 @@ analyze_and_compute_bitop_with_inv_effect (class loop* loop, tree phidef,
   if (TREE_CODE (match_op[1]) != SSA_NAME
       || !expr_invariant_in_loop_p (loop, match_op[0])
       || !(header_phi = dyn_cast <gphi *> (SSA_NAME_DEF_STMT (match_op[1])))
+      || gimple_bb (header_phi) != loop->header
       || gimple_phi_num_args (header_phi) != 2)
     return NULL_TREE;
 
-- 
2.35.3

                 reply	other threads:[~2023-07-17  8:19 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=20230717081940.OqSo02Hi5J-46JCiDxV5U8Q-hby-nO2PjANkvsN3LoI@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).