From: Matthias Klose Date: Thu, 22 Nov 2007 15:34:03 +0000 (+0000) Subject: backport: re PR middle-end/34130 (the builtin abs() gives wrong result when used... X-Git-Tag: prereleases/gcc-4.2.3-rc1~118 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e72534af59f446593d4802ca4fcc2611a0154716;p=thirdparty%2Fgcc.git backport: re PR middle-end/34130 (the builtin abs() gives wrong result when used in some expression) 2007-11-22 Matthias Klose Backport from mainline: 2007-11-17 Richard Guenther 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 63f136354f02..9541b91049b5 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2007-11-22 Matthias Klose + + Backport from mainline: + 2007-11-17 Richard Guenther + + PR middle-end/34130 + * fold-const.c (extract_muldiv_1): Do not move negative + constants inside ABS_EXPR. + 2007-11-22 Richard Sandiford PR rtl-optimization/33848 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index b2a3fa6a3147..81b1d4f84cd8 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -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)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1aef4f96bd53..88df27b9d7d3 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2007-11-22 Matthias Klose + + Backport from mainline: + 2007-11-17 Richard Guenther + + PR middle-end/34130 + * gcc.c-torture/execute/pr34130.c: New testcase. + 2007-11-22 Richard Sandiford 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 index 000000000000..b528ff22b8a1 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr34130.c @@ -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; +}