From 4dfb8a2a60a582b0a1cab65f34d706cf961c9d20 Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>
Date: Sun, 9 Oct 2016 13:18:53 +0200
Subject: [PATCH] re PR tree-optimization/77901 (ICE in
 tree-sse-reassoc,c:2881)

	PR tree-optimization/77901
	* tree-ssa-reassoc.c (optimize_range_tests_var_bound): Only optimize
	if ranges[i].exp is SSA_NAME when looking for >= and only when
	ranges[i].exp is NULL or SSA_NAME when looking for the other
	comparison.

	* gcc.c-torture/compile/pr77901.c: New test.

From-SVN: r240899
---
 gcc/ChangeLog                                 |  8 ++++++++
 gcc/testsuite/ChangeLog                       |  5 +++++
 gcc/testsuite/gcc.c-torture/compile/pr77901.c | 10 ++++++++++
 gcc/tree-ssa-reassoc.c                        |  6 +++++-
 4 files changed, 28 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr77901.c

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 9659fbf7f5d1..02a286806ee7 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+2016-10-09  Jakub Jelinek  <jakub@redhat.com>
+
+	PR tree-optimization/77901
+	* tree-ssa-reassoc.c (optimize_range_tests_var_bound): Only optimize
+	if ranges[i].exp is SSA_NAME when looking for >= and only when
+	ranges[i].exp is NULL or SSA_NAME when looking for the other
+	comparison.
+
 2016-10-09  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>
 
 	* ipa-cp.c (ipcp_alignment_lattice): Remove.
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 4e69c4dddf59..ec2825978a3b 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2016-10-09  Jakub Jelinek  <jakub@redhat.com>
+
+	PR tree-optimization/77901
+	* gcc.c-torture/compile/pr77901.c: New test.
+
 2016-10-09  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>
 
 	* gcc.dg/ipa/propalign-1.c: Adjust scan-ipa-dump.
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr77901.c b/gcc/testsuite/gcc.c-torture/compile/pr77901.c
new file mode 100644
index 000000000000..5c3936af65ad
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr77901.c
@@ -0,0 +1,10 @@
+/* PR tree-optimization/77901 */
+
+void bar (void);
+
+void
+foo (int *x, long *y)
+{
+  if (*y && *x != 10 && *x != 12 && *y >= 0)
+    bar ();
+}
diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c
index c5b36ef2cede..76663654815b 100644
--- a/gcc/tree-ssa-reassoc.c
+++ b/gcc/tree-ssa-reassoc.c
@@ -2846,7 +2846,9 @@ optimize_range_tests_var_bound (enum tree_code opcode, int first, int length,
 
   for (i = first; i < length; i++)
     {
-      if (ranges[i].exp == NULL_TREE || !ranges[i].in_p)
+      if (ranges[i].exp == NULL_TREE
+	  || TREE_CODE (ranges[i].exp) != SSA_NAME
+	  || !ranges[i].in_p)
 	continue;
 
       tree type = TREE_TYPE (ranges[i].exp);
@@ -2878,6 +2880,8 @@ optimize_range_tests_var_bound (enum tree_code opcode, int first, int length,
       tree rhs1, rhs2;
       if (ranges[i].exp)
 	{
+	  if (TREE_CODE (ranges[i].exp) != SSA_NAME)
+	    continue;
 	  stmt = SSA_NAME_DEF_STMT (ranges[i].exp);
 	  if (!is_gimple_assign (stmt))
 	    continue;
-- 
GitLab