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/110766 - missing PHI location check
Date: Mon, 24 Jul 2023 09:50:21 +0200 (CEST)	[thread overview]
Message-ID: <20230724075021.A2D6C138E8@imap2.suse-dmz.suse.de> (raw)

The following adds a missing PHI location check before querying
the loop latch PHI arg from it.

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

	PR tree-optimization/110766
	* tree-scalar-evolution.cc
	(analyze_and_compute_bitwise_induction_effect): Check the PHI
	is defined in the loop header.

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

diff --git a/gcc/testsuite/gcc.dg/torture/pr110766.c b/gcc/testsuite/gcc.dg/torture/pr110766.c
new file mode 100644
index 00000000000..97dcacf1e00
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr110766.c
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+
+int a, b, c, e;
+short d, f;
+int g(int h) { return h > a ? h : h << a; }
+int main() {
+  while (e) {
+    b = 0;
+    for (; b < 3; b++)
+      if (c) {
+        e = g(1);
+        f = e | d;
+      }
+    d = 0;
+  }
+  return 0;
+}
diff --git a/gcc/tree-scalar-evolution.cc b/gcc/tree-scalar-evolution.cc
index 2abe8fa0b90..3fb6951e608 100644
--- a/gcc/tree-scalar-evolution.cc
+++ b/gcc/tree-scalar-evolution.cc
@@ -3519,6 +3519,7 @@ analyze_and_compute_bitwise_induction_effect (class loop* loop,
   if (!gimple_bitwise_induction_p (phidef, &match_op[0], NULL)
       || TREE_CODE (match_op[2]) != SSA_NAME
       || !(header_phi = dyn_cast <gphi *> (SSA_NAME_DEF_STMT (match_op[2])))
+      || gimple_bb (header_phi) != loop->header
       || gimple_phi_num_args (header_phi) != 2)
     return NULL_TREE;
 
-- 
2.35.3

                 reply	other threads:[~2023-07-24  7: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=20230724075021.A2D6C138E8@imap2.suse-dmz.suse.de \
    --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).