Bug 63380 - [5 Regression] Wrong constant folding
Summary: [5 Regression] Wrong constant folding
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 5.0
: P3 normal
Target Milestone: 5.0
Assignee: Richard Biener
URL:
Keywords:
: 63381 (view as bug list)
Depends on:
Blocks:
 
Reported: 2014-09-26 09:45 UTC by Ishiura Lab Compiler Team
Modified: 2014-10-10 11:06 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2014-10-02 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ishiura Lab Compiler Team 2014-09-26 09:45:50 UTC
GCC 5.0.0 for x86_64 miscompiles the following code.

   $ cat test.c

    int a = 0, b = 1, c = 0, d = 1, e, f, g, h;
    int
    main ()
    {
      e = 1 >> d;
      f = ((31 / (1 > e)) || c) / 2;
      g = b || a;
      h = 31 / g;
      if (!h)
        __builtin_abort();
      return 0;
    }

   $ x86_64-unknown-linux-gnu-gcc-5.0.0 test.c -O2
   $ ./a.out
   Floating point exception (core dumped)

   $ x86_64-unknown-linux-gnu-gcc-5.0.0 -v
    Using built-in specs.
    COLLECT_GCC=x86_64-unknown-linux-gnu-gcc-5.0.0
    COLLECT_LTO_WRAPPER=/usr/local/x86_64-tools/gcc-
    5.0.0/libexec/gcc/x86_64-unknown-linux-gnu/5.0.0/lto-wrapper
    Target: x86_64-unknown-linux-gnu
    Configured with: /home/orange3/gcc-master/configure --
    prefix=/usr/local/x86_64-tools/gcc-5.0.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 5.0.0 20140922 (experimental) (GCC)
Comment 1 Marek Polacek 2014-10-02 15:01:33 UTC
Works with -fno-tree-vrp.  Seems to have started with r211904.
Comment 2 Richard Biener 2014-10-06 12:05:06 UTC
Mine.
Comment 3 Richard Biener 2014-10-08 14:58:12 UTC
Hmm.  We end up with

main ()
{
  int d.0_4;
  int e.1_5;
  int _7;
  int b.7_11;
  int a.8_12;

  <bb 2>:
  d.0_4 = d;
  e.1_5 = 1 >> d.0_4;
  e = e.1_5;
  _7 = 31 / 0;

in the end.  Which is caused by tail-merging (part of PRE) optimizing

  <bb 2>:
  d.0_4 = d;
  e.1_5 = 1 >> d.0_4;
  e = e.1_5;
  if (e.1_5 <= 0)
    goto <bb 10>;
  else
    goto <bb 3>;

  <bb 10>:
  goto <bb 4>;

  <bb 3>:
  _7 = 31 / 0;

  <bb 4>:

by removing bb 3 as having no side-effect appearantly (_7 is unused).  It
produces

  <bb 2>:
  d.0_4 = d;
  e.1_5 = 1 >> d.0_4;
  e = e.1_5;

  <bb 3>:
  _7 = 31 / 0;

  <bb 4>:

not sure how it ends up doing that (I suppose it has code to merge an
if diamond).
Comment 4 Richard Biener 2014-10-09 08:18:42 UTC
*** Bug 63381 has been marked as a duplicate of this bug. ***
Comment 5 Richard Biener 2014-10-09 12:45:39 UTC
Author: rguenth
Date: Thu Oct  9 12:45:07 2014
New Revision: 216038

URL: https://gcc.gnu.org/viewcvs?rev=216038&root=gcc&view=rev
Log:
2014-10-09  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/63380
	* tree-ssa-tail-merge.c (stmt_local_def): Exclude stmts that
	may trap.

	* gcc.dg/torture/pr63380-1.c: New testcase.
	* gcc.dg/torture/pr63380-2.c: Likewise.

Added:
    trunk/gcc/testsuite/gcc.dg/torture/pr63380-1.c
    trunk/gcc/testsuite/gcc.dg/torture/pr63380-2.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-tail-merge.c
Comment 6 Richard Biener 2014-10-09 12:45:53 UTC
Fixed.
Comment 7 Richard Biener 2014-10-10 11:06:11 UTC
Author: rguenth
Date: Fri Oct 10 11:05:39 2014
New Revision: 216066

URL: https://gcc.gnu.org/viewcvs?rev=216066&root=gcc&view=rev
Log:
2014-10-10  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/63380
	* tree-ssa-tail-merge.c (stmt_local_def): Exclude stmts that
	may trap.

	* gcc.dg/torture/pr63380-1.c: New testcase.
	* gcc.dg/torture/pr63380-2.c: Likewise.

Added:
    branches/gcc-4_9-branch/gcc/testsuite/gcc.dg/torture/pr63380-1.c
    branches/gcc-4_9-branch/gcc/testsuite/gcc.dg/torture/pr63380-2.c
Modified:
    branches/gcc-4_9-branch/gcc/ChangeLog
    branches/gcc-4_9-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_9-branch/gcc/tree-ssa-tail-merge.c