User account creation filtered due to spam.

Bug 57829 - Wrong constant folding
Summary: Wrong constant folding
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 4.9.0
: P3 normal
Target Milestone: 4.7.4
Assignee: Jakub Jelinek
URL:
Keywords:
: 29589 (view as bug list)
Depends on:
Blocks:
 
Reported: 2013-07-05 12:32 UTC by Ishiura Lab Compiler Team
Modified: 2013-12-26 23:13 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-07-05 00:00:00


Attachments
gcc49-pr57829.patch (710 bytes, patch)
2013-07-05 14:43 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ishiura Lab Compiler Team 2013-07-05 12:32:15 UTC
GCC 4.7.2 - 4.9.0 for i686 and x86_64 miscompiles the following code.

    $ cat error.c

    int main (void)
    {
      volatile int k = 1;
      int t = 2 | ( ( k - 1) >> 31 );
      if (t != 2) __builtin_abort();
      return 0;
    }

    $ x86_64-unknown-linux-gnu-gcc-4.9.0 error.c -O1
    $ ./a.out
    Aborted (core dumped)

    $ x86_64-unknown-linux-gnu-gcc-4.9.0 -v
    Using built-in specs.
    COLLECT_GCC=x86_64-unknown-linux-gnu-gcc-4.9.0
    COLLECT_LTO_WRAPPER=/usr/local/x86_64-tools/gcc-4.9.0/libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/lto-wrapper
    Target: x86_64-unknown-linux-gnu
    Configured with: /home/hassy/gcc/configure
--prefix=/usr/local/x86_64-tools/gcc-4.9.0/
--with-gmp=/usr/local/gmp-5.1.1/ --with-mpfr=/usr/local/mpfr-3.1.2/
--with-mpc=/usr/local/mpc-1.0.1/ --disable-multilib --disable-nls
--enable-languages=c
    Thread model: posix
    gcc version 4.9.0 20130704 (experimental) (GCC)

The status of the other versions are as follows:

    (x86_64)
    GCC-4.7.2 Error
    GCC-4.8.2 (prerelease) OK
    GCC-4.9.0 (experimental) Error

    (i686)
    GCC-4.7.2 Error
    GCC-4.8.2 (prerelease) Error
    GCC-4.9.0 (experimental) Error
Comment 1 Mikael Pettersson 2013-07-05 13:13:28 UTC
If I change it to return the computed value of t, I get wrong code for every single gcc version from 4.9 down to 3.2.3 on both x86_64 and sparc64.  For

    int main (void)
    {
      volatile int k = 1;
      int t = 2 | ( ( k - 1) >> 31 );
      return t;
    }

gcc-4.9 generates

main:
        movl    $1, -4(%rsp)
        movl    -4(%rsp), %eax
        leal    -1(%rax), %eax
        sarl    $31, %eax
        ret

which completely loses all references to the "2 |" part.
Comment 2 Marc Glisse 2013-07-05 14:04:57 UTC
|2 disappears during combine.
Comment 3 Jakub Jelinek 2013-07-05 14:43:44 UTC
Created attachment 30463 [details]
gcc49-pr57829.patch

Sounds very old bug, svn blame shows r7224.
Comment 4 Jakub Jelinek 2013-07-08 08:51:27 UTC
Author: jakub
Date: Mon Jul  8 08:11:08 2013
New Revision: 200768

URL: http://gcc.gnu.org/viewcvs?rev=200768&root=gcc&view=rev
Log:
	PR rtl-optimization/57829
	* simplify-rtx.c (simplify_binary_operation_1) <case IOR>: Ensure that
	mask bits outside of mode are just sign-extension from mode to HWI.

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

Added:
    trunk/gcc/testsuite/gcc.c-torture/execute/pr57829.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/simplify-rtx.c
    trunk/gcc/testsuite/ChangeLog

Author: jakub
Date: Mon Jul  8 08:15:01 2013
New Revision: 200770

URL: http://gcc.gnu.org/viewcvs?rev=200770&root=gcc&view=rev
Log:
	PR rtl-optimization/57829
	* simplify-rtx.c (simplify_binary_operation_1) <case IOR>: Ensure that
	mask bits outside of mode are just sign-extension from mode to HWI.

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

Added:
    branches/gcc-4_8-branch/gcc/testsuite/gcc.c-torture/execute/pr57829.c
Modified:
    branches/gcc-4_8-branch/gcc/ChangeLog
    branches/gcc-4_8-branch/gcc/simplify-rtx.c
    branches/gcc-4_8-branch/gcc/testsuite/ChangeLog

Author: jakub
Date: Mon Jul  8 08:17:35 2013
New Revision: 200773

URL: http://gcc.gnu.org/viewcvs?rev=200773&root=gcc&view=rev
Log:
	PR rtl-optimization/57829
	* simplify-rtx.c (simplify_binary_operation_1) <case IOR>: Ensure that
	mask bits outside of mode are just sign-extension from mode to HWI.

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

Added:
    branches/gcc-4_7-branch/gcc/testsuite/gcc.c-torture/execute/pr57829.c
Modified:
    branches/gcc-4_7-branch/gcc/ChangeLog
    branches/gcc-4_7-branch/gcc/simplify-rtx.c
    branches/gcc-4_7-branch/gcc/testsuite/ChangeLog
Comment 5 Steven Bosscher 2013-12-26 23:13:23 UTC
*** Bug 29589 has been marked as a duplicate of this bug. ***