tree-optimization/108387 - ICE with VN handling of x << C as x * (1<<C)
authorRichard Biener <rguenther@suse.de>
Fri, 13 Jan 2023 07:37:24 +0000 (08:37 +0100)
committerRichard Biener <rguenther@suse.de>
Fri, 13 Jan 2023 08:40:01 +0000 (09:40 +0100)
The following fixes unexpected simplification of x << C as
x * (1<<C) to a constant.

PR tree-optimization/108387
* tree-ssa-sccvn.cc (visit_nary_op): Check for SSA_NAME
value before inserting expression into the tables.

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

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

diff --git a/gcc/testsuite/gcc.dg/pr108387.c b/gcc/testsuite/gcc.dg/pr108387.c
new file mode 100644 (file)
index 0000000..114186b
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-tree-ccp" } */
+
+void bar2 (unsigned char, unsigned char);
+
+void
+foo1 (char c)
+{
+  unsigned char t = c;
+  t *= 2;
+  unsigned char t1 = t << 7;
+  bar2 (t, t1);
+}
index a01022b..0dba3f3 100644 (file)
@@ -5405,7 +5405,8 @@ visit_nary_op (tree lhs, gassign *stmt)
              if (result)
                {
                  bool changed = set_ssa_val_to (lhs, result);
-                 vn_nary_op_insert_stmt (stmt, result);
+                 if (TREE_CODE (result) == SSA_NAME)
+                   vn_nary_op_insert_stmt (stmt, result);
                  return changed;
                }
            }