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.
--- /dev/null
+/* { 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);
+}
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;
}
}