]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR middle-end/34130 (the builtin abs() gives wrong result when used...
authorMatthias Klose <doko@ubuntu.com>
Thu, 22 Nov 2007 15:34:03 +0000 (15:34 +0000)
committerMatthias Klose <doko@gcc.gnu.org>
Thu, 22 Nov 2007 15:34:03 +0000 (15:34 +0000)
2007-11-22  Matthias Klose  <doko@ubuntu.com>

        Backport from mainline:
        2007-11-17  Richard Guenther  <rguenther@suse.de>

        PR middle-end/34130
        * fold-const.c (extract_muldiv_1): Do not move negative
        constants inside ABS_EXPR.

        PR middle-end/34130
        * gcc.c-torture/execute/pr34130.c: New testcase.

From-SVN: r130352

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

index 63f136354f02d2623c8f725453c86de7d372c7ae..9541b91049b5e622c5df77312eeb29d9ca559078 100644 (file)
@@ -1,3 +1,12 @@
+2007-11-22  Matthias Klose  <doko@ubuntu.com>
+
+       Backport from mainline:
+       2007-11-17  Richard Guenther  <rguenther@suse.de>
+
+       PR middle-end/34130
+       * fold-const.c (extract_muldiv_1): Do not move negative
+       constants inside ABS_EXPR.
+
 2007-11-22  Richard Sandiford  <rsandifo@nildram.co.uk>
 
        PR rtl-optimization/33848
index b2a3fa6a314798d26fbd79c8a025ba8d31828155..81b1d4f84cd86bed5a75d70602535ff6b545a757 100644 (file)
@@ -5660,6 +5660,9 @@ extract_muldiv_1 (tree t, tree c, enum tree_code code, tree wide_type,
             }
           break;
         }
+      /* If the constant is negative, we cannot simplify this.  */
+      if (tree_int_cst_sgn (c) == -1)
+        break;
       /* FALLTHROUGH */
     case NEGATE_EXPR:
       if ((t1 = extract_muldiv (op0, c, code, wide_type, strict_overflow_p))
index 1aef4f96bd53ee06f43de0aa2e96a39798f74ef4..88df27b9d7d301c7f86178a40a2717621fb45546 100644 (file)
@@ -1,3 +1,11 @@
+2007-11-22  Matthias Klose  <doko@ubuntu.com>
+
+       Backport from mainline:
+       2007-11-17  Richard Guenther  <rguenther@suse.de>
+
+       PR middle-end/34130
+       * gcc.c-torture/execute/pr34130.c: New testcase.
+
 2007-11-22  Richard Sandiford  <rsandifo@nildram.co.uk>
 
        PR rtl-optimization/33848
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr34130.c b/gcc/testsuite/gcc.c-torture/execute/pr34130.c
new file mode 100644 (file)
index 0000000..b528ff2
--- /dev/null
@@ -0,0 +1,12 @@
+extern void abort (void);
+int foo (int i)
+{
+  return -2 * __builtin_abs(i - 2);
+}
+int main()
+{
+  if (foo(1) != -2
+      || foo(3) != -2)
+    abort ();
+  return 0;
+}