[PATCH] Fix ccp evaluate_stmt for tcc_comparison assignments (PR tree-optimization/47140)
Jakub Jelinek
jakub@redhat.com
Sat Jan 1 18:22:00 GMT 2011
Hi!
For tcc_comparison binary assignments the lhs type is often different
from the type of the comparison operands, so when we bit_value_binop with
rhs1's type instead of lhs' type, the type of the constant might be
incorrect.
Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?
2011-01-01 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/47140
* tree-ssa-ccp.c (evaluate_stmt): For binary assignments, use
TREE_TYPE (lhs) instead of TREE_TYPE (rhs1) as second argument
to bit_value_binop.
* gcc.c-torture/compile/pr47140.c: New test.
--- gcc/tree-ssa-ccp.c.jj 2010-12-16 10:55:33.000000000 +0100
+++ gcc/tree-ssa-ccp.c 2011-01-01 16:12:57.000000000 +0100
@@ -2156,9 +2156,10 @@ evaluate_stmt (gimple stmt)
if (INTEGRAL_TYPE_P (TREE_TYPE (rhs1))
|| POINTER_TYPE_P (TREE_TYPE (rhs1)))
{
+ tree lhs = gimple_assign_lhs (stmt);
tree rhs2 = gimple_assign_rhs2 (stmt);
val = bit_value_binop (subcode,
- TREE_TYPE (rhs1), rhs1, rhs2);
+ TREE_TYPE (lhs), rhs1, rhs2);
}
break;
--- gcc/testsuite/gcc.c-torture/compile/pr47140.c.jj 2011-01-01 16:18:47.000000000 +0100
+++ gcc/testsuite/gcc.c-torture/compile/pr47140.c 2011-01-01 16:19:32.000000000 +0100
@@ -0,0 +1,25 @@
+/* PR tree-optimization/47140 */
+
+static inline int
+foo (int x, short y)
+{
+ return y == 0 ? x : x + y;
+}
+
+static inline unsigned short
+bar (unsigned short x, unsigned char y)
+{
+ return x - y;
+}
+
+int w;
+
+int baz (void);
+
+int
+test (void)
+{
+ int i;
+ for (i = 0; i < 50; i++)
+ w += foo ((unsigned char) (1 + baz ()) >= bar (0, 1), 0);
+}
Jakub
More information about the Gcc-patches
mailing list