re PR tree-optimization/48717 (integer wrong code bug)
authorJakub Jelinek <jakub@redhat.com>
Fri, 22 Apr 2011 18:52:48 +0000 (20:52 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 22 Apr 2011 18:52:48 +0000 (20:52 +0200)
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
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/pr48717.c [new file with mode: 0644]
gcc/tree-ssa-forwprop.c

index d57499df0010561b92b868cf1a0ab775e60c4d82..a30a78cb0cd7cc53f674730223df5546b61aa25e 100644 (file)
@@ -1,3 +1,9 @@
+2011-04-22  Jakub Jelinek  <jakub@redhat.com>
+
+       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  <ubizjak@gmail.com>
 
        PR target/48723
index d3383a55532f0a72c24e475037dfb7cd0dc249a2..639886aadcd6fb49296d44bc242991f08e6bc49e 100644 (file)
@@ -1,3 +1,8 @@
+2011-04-22  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/48717
+       * gcc.c-torture/execute/pr48717.c: New test.
+
 2011-04-22  Uros Bizjak  <ubizjak@gmail.com>
 
        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 (file)
index 0000000..a746374
--- /dev/null
@@ -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;
+}
index aaed6cb689e17bba27163d1ff2043b7a44c858a6..f26c47eab4e9b1e34c666eb773b3ba2345537a87 100644 (file)
@@ -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);