]> gcc.gnu.org Git - gcc.git/commitdiff
re PR tree-optimization/56250 (Wrong constant folding on unsigned int)
authorJakub Jelinek <jakub@redhat.com>
Fri, 8 Feb 2013 15:06:26 +0000 (16:06 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 8 Feb 2013 15:06:26 +0000 (16:06 +0100)
PR tree-optimization/56250
* fold-const.c (extract_muldiv_1) <case NEGATE_EXPR>: Don't optimize
if type is unsigned and code isn't MULT_EXPR.

* gcc.c-torture/execute/pr56250.c: New test.

From-SVN: r195888

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/pr56250.c [new file with mode: 0644]

index 55e90b4abdfaa8dd00e37a30183f60ea32a9c23d..4c6bfba83213f9e4f7f9ca5d9214beb73c237b65 100644 (file)
@@ -1,3 +1,9 @@
+2013-02-08  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/56250
+       * fold-const.c (extract_muldiv_1) <case NEGATE_EXPR>: Don't optimize
+       if type is unsigned and code isn't MULT_EXPR.
+
 2013-02-08  Georg-Johann Lay  <avr@gjlay.de>
 
        PR tree-optimization/56064
index 93f38cbbf2161d3c4e18541ccb66fa98cfe57265..5acb4ad005944fb7bc3e53d48118fe2ec40fa608 100644 (file)
@@ -5695,6 +5695,11 @@ extract_muldiv_1 (tree t, tree c, enum tree_code code, tree wide_type,
         break;
       /* FALLTHROUGH */
     case NEGATE_EXPR:
+      /* For division and modulus, type can't be unsigned, as e.g.
+        (-(x / 2U)) / 2U isn't equal to -((x / 2U) / 2U) for x >= 2.
+        For signed types, even with wrapping overflow, this is fine.  */
+      if (code != MULT_EXPR && TYPE_UNSIGNED (type))
+       break;
       if ((t1 = extract_muldiv (op0, c, code, wide_type, strict_overflow_p))
          != 0)
        return fold_build1 (tcode, ctype, fold_convert (ctype, t1));
index 31f0bf2844f6bd21b96489af7de3cbcd2d9dd373..ae21e6b9cd0dca2cdd7645af794984585f205540 100644 (file)
@@ -1,3 +1,8 @@
+2013-02-08  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/56250
+       * gcc.c-torture/execute/pr56250.c: New test.
+
 2013-02-08  Georg-Johann Lay  <avr@gjlay.de>
 
        PR tree-optimization/56064
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr56250.c b/gcc/testsuite/gcc.c-torture/execute/pr56250.c
new file mode 100644 (file)
index 0000000..8da36f8
--- /dev/null
@@ -0,0 +1,13 @@
+/* PR tree-optimization/56250 */
+
+extern void abort (void);
+
+int
+main ()
+{
+  unsigned int x = 2;
+  unsigned int y = (0U - x / 2) / 2;
+  if (-1U / x != y)
+    abort ();
+  return 0;
+}
This page took 0.098738 seconds and 5 git commands to generate.