From 93dfac24adf650e093d21f71193072626595a37d Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Fri, 22 Apr 2011 20:52:48 +0200 Subject: [PATCH] re PR tree-optimization/48717 (integer wrong code bug) PR tree-optimization/48717 * tree-ssa-forwprop.c (associate_plusminus): For A + ~A and ~A + A optimizations use build_int_cst_type instead of build_int_cst. * gcc.c-torture/execute/pr48717.c: New test. From-SVN: r172868 --- gcc/ChangeLog | 6 +++++ gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/gcc.c-torture/execute/pr48717.c | 26 +++++++++++++++++++ gcc/tree-ssa-forwprop.c | 4 +-- 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr48717.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d57499df001..a30a78cb0cd 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2011-04-22 Jakub Jelinek + + PR tree-optimization/48717 + * tree-ssa-forwprop.c (associate_plusminus): For A + ~A and + ~A + A optimizations use build_int_cst_type instead of build_int_cst. + 2011-04-22 Uros Bizjak PR target/48723 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d3383a55532..639886aadcd 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2011-04-22 Jakub Jelinek + + PR tree-optimization/48717 + * gcc.c-torture/execute/pr48717.c: New test. + 2011-04-22 Uros Bizjak PR target/48723 diff --git a/gcc/testsuite/gcc.c-torture/execute/pr48717.c b/gcc/testsuite/gcc.c-torture/execute/pr48717.c new file mode 100644 index 00000000000..a746374a26d --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr48717.c @@ -0,0 +1,26 @@ +/* PR tree-optimization/48717 */ + +extern void abort (void); + +int v = 1, w; + +unsigned short +foo (unsigned short x, unsigned short y) +{ + return x + y; +} + +void +bar (void) +{ + v = foo (~w, w); +} + +int +main () +{ + bar (); + if (v != (unsigned short) -1) + abort (); + return 0; +} diff --git a/gcc/tree-ssa-forwprop.c b/gcc/tree-ssa-forwprop.c index aaed6cb689e..f26c47eab4e 100644 --- a/gcc/tree-ssa-forwprop.c +++ b/gcc/tree-ssa-forwprop.c @@ -1815,7 +1815,7 @@ associate_plusminus (gimple stmt) { /* ~A + A -> -1. */ code = INTEGER_CST; - rhs1 = build_int_cst (TREE_TYPE (rhs2), -1); + rhs1 = build_int_cst_type (TREE_TYPE (rhs2), -1); rhs2 = NULL_TREE; gimple_assign_set_rhs_with_ops (&gsi, code, rhs1, NULL_TREE); gcc_assert (gsi_stmt (gsi) == stmt); @@ -1915,7 +1915,7 @@ associate_plusminus (gimple stmt) { /* A + ~A -> -1. */ code = INTEGER_CST; - rhs1 = build_int_cst (TREE_TYPE (rhs1), -1); + rhs1 = build_int_cst_type (TREE_TYPE (rhs1), -1); rhs2 = NULL_TREE; gimple_assign_set_rhs_with_ops (&gsi, code, rhs1, NULL_TREE); gcc_assert (gsi_stmt (gsi) == stmt); -- 2.30.2