Hi Martin,

On 25/07/16 18:56, Martin Liška wrote:
Hi.

As other calls of get_ops is guarded with TREE_CODE (x) == SSA_NAME, I guess the
same should be done for the call that causes the ICE.

Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.

Ready to be installed?
Martin


0001-Call-get_ops-just-for-SSA_NAMEs-PR-tree-optimization.patch


From 9dd5cc00eb3c271fad91fede6a9b06df356e001f Mon Sep 17 00:00:00 2001
From: marxin <mli...@suse.cz>
Date: Mon, 25 Jul 2016 09:19:54 +0200
Subject: [PATCH] Call get_ops just for SSA_NAMEs (PR tree-optimization/71987)

gcc/ChangeLog:

2016-07-25  Martin Liska  <mli...@suse.cz>

        PR tree-optimization/71987
        * tree-ssa-reassoc.c (maybe_optimize_range_tests): Call get_ops
        just for SSA_NAMEs.

gcc/testsuite/ChangeLog:

2016-07-25  Martin Liska  <mli...@suse.cz>

        * gcc.dg/torture/pr71987.c: New test.
---
 gcc/testsuite/gcc.dg/torture/pr71987.c | 21 +++++++++++++++++++++
 gcc/tree-ssa-reassoc.c                 | 10 ++++++----
 2 files changed, 27 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr71987.c

diff --git a/gcc/testsuite/gcc.dg/torture/pr71987.c 
b/gcc/testsuite/gcc.dg/torture/pr71987.c
new file mode 100644
index 0000000..87d5938
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr71987.c
@@ -0,0 +1,21 @@
+/* PR tree-optimization/71987 */
+
+int a, b, *c, *d;
+
+short fn1 (int p1)
+{
+  return a ? p1 : a;
+}
+
+void fn2 ()
+{
+  int e, *f = &e;
+  b = fn1 (d != &e);
+  c = f;
+}
+
+int main ()
+{
+  fn2 ();
+  return 0;
+}
diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c
index ece2d08..dfaf7d8 100644
--- a/gcc/tree-ssa-reassoc.c
+++ b/gcc/tree-ssa-reassoc.c
@@ -3519,7 +3519,8 @@ maybe_optimize_range_tests (gimple *stmt)
             (or &, corresponding to 1/0 in the phi arguments,
             push into ops the individual range test arguments
             of the bitwise or resp. and, recursively.  */
-         if (!get_ops (rhs, code, &ops,
+         if (TREE_CODE (rhs) == SSA_NAME
+             && !get_ops (rhs, code, &ops,
                        loop_containing_stmt (stmt))
              && (TREE_CODE_CLASS (gimple_assign_rhs_code (stmt))
                  != tcc_comparison)
@@ -3537,11 +3538,12 @@ maybe_optimize_range_tests (gimple *stmt)
              bb_ent.last_idx++;
              bb_ent.op = rhs;
            }
-         else if (is_gimple_assign (stmt)
+         else if (TREE_CODE (lhs) == SSA_NAME
+                  && is_gimple_assign (stmt)
                   && (TREE_CODE_CLASS (gimple_assign_rhs_code (stmt))
                       == tcc_comparison)
-                  &&!get_ops (lhs, code, &ops,
-                              loop_containing_stmt (stmt))
+                  && !get_ops (lhs, code, &ops,
+                               loop_containing_stmt (stmt))
                   && has_single_use (lhs))
            {
              operand_entry *oe = operand_entry_pool.allocate ();

Sorry about the breakage. Since final_range_test_p allows either lhs or rhs to be SSA_NAME (for the different cases it accepts), we should indeed check for TREE_CODE being SSA_NAME. Unfortunately it didn't trigger in my testing. Lets wait for the maintainers conformation.

Thanks for working on this,
Kugan

Reply via email to