]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/118895 - ICE during PRE
authorRichard Biener <rguenther@suse.de>
Mon, 17 Feb 2025 10:40:01 +0000 (11:40 +0100)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 17 Feb 2025 13:41:25 +0000 (14:41 +0100)
When we simplify a NARY during PHI translation we have to make sure
to not inject not available operands into it given that might violate
the valueization hook constraints and we'd pick up invalid
context-sensitive data in further simplification or as in this case
later ICE when we try to insert the expression.

PR tree-optimization/118895
* tree-ssa-sccvn.cc (vn_nary_build_or_lookup_1): Only allow
CSE if we can verify the result is available.

* gcc.dg/pr118895.c: New testcase.

gcc/testsuite/gcc.dg/pr118895.c [new file with mode: 0644]
gcc/tree-ssa-sccvn.cc

diff --git a/gcc/testsuite/gcc.dg/pr118895.c b/gcc/testsuite/gcc.dg/pr118895.c
new file mode 100644 (file)
index 0000000..ca61d2c
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+unsigned long a;
+void fn1()
+{
+  unsigned long e = a;
+  int c = e;
+  int d = c < 100 ? c : 0;
+  if (d + (int)e & 608)
+    while (e & 608)
+      e <<= 1;
+}
index 8bb45780a9814d1e391dde024a9227d26b0b8625..146840664e2ea0a81f169c805dab63cd2be507bc 100644 (file)
@@ -366,6 +366,10 @@ static vn_ssa_aux_t last_pushed_avail;
    correct.  */
 static vn_tables_t valid_info;
 
+/* Global RPO state for access from hooks.  */
+static class eliminate_dom_walker *rpo_avail;
+basic_block vn_context_bb;
+
 
 /* Valueization hook for simplify_replace_tree.  Valueize NAME if it is
    an SSA name, otherwise just return it.  */
@@ -2501,7 +2505,10 @@ vn_nary_build_or_lookup_1 (gimple_match_op *res_op, bool insert,
   bool res = false;
   if (i == res_op->num_ops)
     {
-      mprts_hook = vn_lookup_simplify_result;
+      /* Do not leak not available operands into the simplified expression
+        when called from PRE context.  */
+      if (rpo_avail)
+       mprts_hook = vn_lookup_simplify_result;
       res = res_op->resimplify (NULL, vn_valueize);
       mprts_hook = NULL;
     }
@@ -2684,10 +2691,6 @@ public:
   vn_avail *m_avail_freelist;
 };
 
-/* Global RPO state for access from hooks.  */
-static eliminate_dom_walker *rpo_avail;
-basic_block vn_context_bb;
-
 /* Return true if BASE1 and BASE2 can be adjusted so they have the
    same address and adjust *OFFSET1 and *OFFSET2 accordingly.
    Otherwise return false.  */