public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] tree-optimization/108387 - ICE with VN handling of x << C as x * (1<<C)
@ 2023-01-13  9:47 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2023-01-13  9:47 UTC (permalink / raw)
  To: gcc-patches

The following fixes unexpected simplification of x << C as
x * (1<<C) to a constant.

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

	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 | 13 +++++++++++++
 gcc/tree-ssa-sccvn.cc           |  3 ++-
 2 files changed, 15 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr108387.c

diff --git a/gcc/testsuite/gcc.dg/pr108387.c b/gcc/testsuite/gcc.dg/pr108387.c
new file mode 100644
index 00000000000..114186b6c5d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr108387.c
@@ -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);
+}
diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc
index a01022b0d12..0dba3f39aa0 100644
--- a/gcc/tree-ssa-sccvn.cc
+++ b/gcc/tree-ssa-sccvn.cc
@@ -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;
 		}
 	    }
-- 
2.35.3

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-01-13  9:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-13  9:47 [PATCH] tree-optimization/108387 - ICE with VN handling of x << C as x * (1<<C) Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).