public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] tree-optimization/108819 - niter analysis ICE with unexpected constant
@ 2023-02-20  7:43 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2023-02-20  7:43 UTC (permalink / raw)
  To: gcc-patches

The following makes sure we do not ICE on unfolded stmts like
_1 = 1 & 1.

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

	PR tree-optimization/108819
	* tree-ssa-loop-niter.cc (number_of_iterations_cltz): Check
	we have an SSA name as iv_2 as expected.

	* gcc.dg/pr108819.c: New testcase.
---
 gcc/testsuite/gcc.dg/pr108819.c | 14 ++++++++++++++
 gcc/tree-ssa-loop-niter.cc      |  6 ++++--
 2 files changed, 18 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr108819.c

diff --git a/gcc/testsuite/gcc.dg/pr108819.c b/gcc/testsuite/gcc.dg/pr108819.c
new file mode 100644
index 00000000000..a651f819908
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr108819.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fno-tree-ccp -fno-tree-forwprop" } */
+
+int a, b;
+int main() {
+  int d = 1;
+  for (; b; b++)
+    if (a < 1)
+      while (d <= a && a <= 0UL) {
+        int *e = &d;
+        *e = 0;
+      }
+  return 0;
+}
diff --git a/gcc/tree-ssa-loop-niter.cc b/gcc/tree-ssa-loop-niter.cc
index 581bf5d067b..1ce5e736ce3 100644
--- a/gcc/tree-ssa-loop-niter.cc
+++ b/gcc/tree-ssa-loop-niter.cc
@@ -2354,7 +2354,8 @@ number_of_iterations_cltz (loop_p loop, edge exit,
       gimple *and_stmt = SSA_NAME_DEF_STMT (gimple_cond_lhs (cond_stmt));
       if (!is_gimple_assign (and_stmt)
 	  || gimple_assign_rhs_code (and_stmt) != BIT_AND_EXPR
-	  || !integer_pow2p (gimple_assign_rhs2 (and_stmt)))
+	  || !integer_pow2p (gimple_assign_rhs2 (and_stmt))
+	  || TREE_CODE (gimple_assign_rhs1 (and_stmt)) != SSA_NAME)
 	return false;
 
       checked_bit = tree_log2 (gimple_assign_rhs2 (and_stmt));
@@ -2382,7 +2383,8 @@ number_of_iterations_cltz (loop_p loop, edge exit,
 	     precision.  */
 	  iv_2 = gimple_assign_rhs1 (test_value_stmt);
 	  tree rhs_type = TREE_TYPE (iv_2);
-	  if (TREE_CODE (rhs_type) != INTEGER_TYPE
+	  if (TREE_CODE (iv_2) != SSA_NAME
+	      || TREE_CODE (rhs_type) != INTEGER_TYPE
 	      || (TYPE_PRECISION (rhs_type)
 		  != TYPE_PRECISION (test_value_type)))
 	    return false;
-- 
2.35.3

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-20 10:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-20  7:43 [PATCH] tree-optimization/108819 - niter analysis ICE with unexpected constant Richard Biener

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).