First Last Prev Next    No search results available      Search page      Enter new bug
Bug#: 34130
Product:  
Component:  
Status: RESOLVED
Resolution: FIXED
Assigned To: Not yet assigned to anyone <unassigned@gcc.gnu.org>
Host:
Reported against  
Priority:  
Severity:  
Target Milestone:  
 
 
Target:
Reporter: Pengcheng Zou <pengchengzou@gmail.com>
Add CC:
CC:
Remove selected CCs
Build:
URL:
Summary:
Keywords:
Known to work:
Known to fail:

Attachment Description Type Created Size Actions
Create a New Attachment (proposed patch, testcase, etc.) View All

Bug 34130 depends on: Show dependency tree
Show dependency graph
Bug 34130 blocks:

Additional Comments:






View Bug Activity   |   Format For Printing   |   Clone This Bug


Description:   Last confirmed: 2007-11-17 12:46 Opened: 2007-11-17 01:21
tried the following code on both gcc 4.1 and gcc  3.2,:
----------------------------------------------------
        int result, i;

        i = 0;
        result = -2*abs(i-2);
        printf("result = %d\n", result);
----------------------------------------------------

the result is 4, while the correct result should be '-4;'. 

if use '-fno-builtin' flag to use the glibc's abs() implementation, then the
result is correct (-4). also, if the expression is changed something like
'0-2*abs(i-2)', then the result is also correct.

so, it seems there is some problem with the builtin abs() function. simply look
at the assembly result, it seems gcc thinks A*abs(B) is the same as abs(A*B).

'gcc -v' result

Using built-in specs.
Target: i686-pc-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-libgcj-multifile --disable-libmudflap
--enable-languages=c,c++,java,fortran --disable-libgcj --with-cpu=generic
--host=i686-pc-linux
Thread model: posix
gcc version 4.2.1

------- Comment #1 From Richard Guenther 2007-11-17 12:46 -------
Confirmed.

int foo(int i)
{
  return -2*__builtin_abs(i-2);
}

get's folded to

 return ABS_EXPR <(2 - i) * 2>;

doh.

------- Comment #2 From Richard Guenther 2007-11-17 12:46 -------
Mine.

------- Comment #3 From Richard Guenther 2007-11-17 14:22 -------
Subject: Bug 34130

Author: rguenth
Date: Sat Nov 17 14:22:42 2007
New Revision: 130258

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130258
Log:
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.

        * gcc.c-torture/execute/pr34130.c: New testcase.

Added:
    trunk/gcc/testsuite/gcc.c-torture/execute/pr34130.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/fold-const.c
    trunk/gcc/testsuite/ChangeLog

------- Comment #4 From Richard Guenther 2007-11-17 14:23 -------
Fixed on the trunk.

------- Comment #5 From Matthias Klose 2007-11-22 15:34 -------
Subject: Bug 34130

Author: doko
Date: Thu Nov 22 15:34:03 2007
New Revision: 130352

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130352
Log:
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.

Added:
    branches/gcc-4_2-branch/gcc/testsuite/gcc.c-torture/execute/pr34130.c
      - copied unchanged from r130258,
trunk/gcc/testsuite/gcc.c-torture/execute/pr34130.c
Modified:
    branches/gcc-4_2-branch/gcc/ChangeLog
    branches/gcc-4_2-branch/gcc/fold-const.c
    branches/gcc-4_2-branch/gcc/testsuite/ChangeLog

------- Comment #6 From Matthias Klose 2007-11-29 00:33 -------
Subject: Bug 34130

Author: doko
Date: Thu Nov 29 00:32:58 2007
New Revision: 130507

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130507
Log:
gcc/
2007-11-29  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.

gcc/testsuite/

2007-11-29  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.

Added:
    branches/gcc-4_1-branch/gcc/testsuite/gcc.c-torture/execute/pr34130.c
      - copied unchanged from r130352,
branches/gcc-4_2-branch/gcc/testsuite/gcc.c-torture/execute/pr34130.c
Modified:
    branches/gcc-4_1-branch/gcc/ChangeLog
    branches/gcc-4_1-branch/gcc/fold-const.c
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog

------- Comment #7 From Serge Belyshev 2007-12-16 18:08 -------
Fixed on active branches.

First Last Prev Next    No search results available      Search page      Enter new bug