Bug 57083 - [4.8/4.9 Regression] Wrong constant folding
Summary: [4.8/4.9 Regression] Wrong constant folding
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.8.1
: P3 normal
Target Milestone: 4.8.1
Assignee: Jakub Jelinek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-04-26 14:14 UTC by Ishiura Lab Compiler Team
Modified: 2013-04-29 08:34 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-04-26 00:00:00


Attachments
gcc49-pr57083.patch (563 bytes, patch)
2013-04-26 16:14 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-04-26 14:14:49 UTC
GCC 4.8.1 prerelease (x86_64 for both linux and darwin12) miscompiles
the following code with optimize option "-O1 -ftree-vrp."


  $ cat error.c

  /* UINT_MAX == 4294967295 */
  short x = 1;
  int y = 0;

  int main (void)
  {
    unsigned t = ( 2147450881U - (unsigned) x ) << ( y == 0 );
    if ( t != 4294901760U ) { __builtin_abort(); }
    return 0;
  }

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


There was no problem with GCC 4.7.3.  

-----

$ x86_64-unknown-linux-gnu-gcc-4.8.1 -v
Target: x86_64-unknown-linux-gnu
Configured with: /home/hassy/gcc/configure
--prefix=/usr/local/x86_64-tools/gcc-4.8.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.8.1 20130422 (prerelease) (GCC)

$ gcc-mp-4.8 -v
Using built-in specs.
COLLECT_GCC=gcc-mp-4.8
COLLECT_LTO_WRAPPER=/opt/local/libexec/gcc/x86_64-apple-darwin12/4.8.1/lto-wrapper
Target: x86_64-apple-darwin12
Configured with: ../gcc-4.8-20130411/configure --prefix=/opt/local --build=x86_64-apple-darwin12 --enable-languages=c,c++,objc,obj-c++,lto,fortran,java --libdir=/opt/local/lib/gcc48 --includedir=/opt/local/include/gcc48 --infodir=/opt/local/share/info --mandir=/opt/local/share/man --datarootdir=/opt/local/share/gcc-4.8 --with-local-prefix=/opt/local --with-system-zlib --disable-nls --program-suffix=-mp-4.8 --with-gxx-include-dir=/opt/local/include/gcc48/c++/ --with-gmp=/opt/local --with-mpfr=/opt/local --with-mpc=/opt/local --with-ppl=/opt/local --with-cloog=/opt/local --enable-cloog-backend=isl --disable-cloog-version-check --enable-stage1-checking --disable-multilib --enable-lto --enable-libstdcxx-time --with-as=/opt/local/bin/as --with-ld=/opt/local/bin/ld --with-ar=/opt/local/bin/ar --with-bugurl=https://trac.macports.org/newticket --with-pkgversion='MacPorts gcc48 4.8-20130411_0'
Thread model: posix
gcc version 4.8.1 20130411 (prerelease) (MacPorts gcc48 4.8-20130411_0)
Comment 1 Jakub Jelinek 2013-04-26 14:48:26 UTC
Started with http://gcc.gnu.org/r191057 , looking into it.
Comment 2 Jakub Jelinek 2013-04-26 16:14:35 UTC
Created attachment 29948 [details]
gcc49-pr57083.patch

Untested fix.  llshift method always sign-extends the double_int, so we need to zero extend it manually.  Thanks for the report.
Comment 3 Jakub Jelinek 2013-04-29 08:34:32 UTC
Author: jakub
Date: Mon Apr 29 07:55:09 2013
New Revision: 198388

URL: http://gcc.gnu.org/viewcvs?rev=198388&root=gcc&view=rev
Log:
	PR tree-optimization/57083
	* tree-vrp.c (extract_range_from_binary_expr_1): For LSHIFT_EXPR with
	non-singleton shift count range, zero extend low_bound for uns case.

	* gcc.dg/torture/pr57083.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/torture/pr57083.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-vrp.c

Author: jakub
Date: Mon Apr 29 07:57:02 2013
New Revision: 198389

URL: http://gcc.gnu.org/viewcvs?rev=198389&root=gcc&view=rev
Log:
	PR tree-optimization/57083
	* tree-vrp.c (extract_range_from_binary_expr_1): For LSHIFT_EXPR with
	non-singleton shift count range, zero extend low_bound for uns case.

	* gcc.dg/torture/pr57083.c: New test.

Added:
    branches/gcc-4_8-branch/gcc/testsuite/gcc.dg/torture/pr57083.c
Modified:
    branches/gcc-4_8-branch/gcc/ChangeLog
    branches/gcc-4_8-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_8-branch/gcc/tree-vrp.c