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

Richard.

2018-08-28  Richard Biener  <rguent...@suse.de>

        PR tree-optimization/87124
        * tree-ssa-sccvn.c (vn_lookup_simplify_result): Guard against
        constants before looking up avail.

        * g++.dg/torture/pr87124.C: New testcase.

Index: gcc/tree-ssa-sccvn.c
===================================================================
--- gcc/tree-ssa-sccvn.c        (revision 263917)
+++ gcc/tree-ssa-sccvn.c        (working copy)
@@ -5667,7 +5667,7 @@ vn_lookup_simplify_result (gimple_match_
                                       res_op->type, ops, &vnresult);
   /* If this is used from expression simplification make sure to
      return an available expression.  */
-  if (res && mprts_hook && rpo_avail)
+  if (res && TREE_CODE (res) == SSA_NAME && mprts_hook && rpo_avail)
     res = rpo_avail->eliminate_avail (vn_context_bb, res);
   return res;
 }
Index: gcc/testsuite/g++.dg/torture/pr87124.C
===================================================================
--- gcc/testsuite/g++.dg/torture/pr87124.C      (nonexistent)
+++ gcc/testsuite/g++.dg/torture/pr87124.C      (working copy)
@@ -0,0 +1,12 @@
+// { dg-do compile }
+
+class A {
+    void m_fn1();
+};
+
+void A::m_fn1()
+{
+  A *a = this;
+  for (int i; i && a;)
+    a = 0;
+}

Reply via email to