Bug 28003 - [4.2 Regression] optimizer bug
Summary: [4.2 Regression] optimizer bug
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.2.0
: P1 critical
Target Milestone: 4.2.0
Assignee: Not yet assigned to anyone
URL:
Keywords: alias, monitored, wrong-code
Depends on:
Blocks: 28727
  Show dependency treegraph
 
Reported: 2006-06-12 19:27 UTC by Ralf W. Grosse-Kunstleve
Modified: 2006-08-22 14:05 UTC (History)
6 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-08-09 14:39:55


Attachments
short reproducer (1.29 KB, text/plain)
2006-06-12 19:28 UTC, Ralf W. Grosse-Kunstleve
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ralf W. Grosse-Kunstleve 2006-06-12 19:27:07 UTC
I will attach a small reproducer.

/* Reproducer for optimizer bug in gcc svn trunk revision 114570
   (as checked out 2006_06_12_0834 PDT)

   To produce correct output:
     g++ -Wall -O0 gcc_trunk_2006_06_12_0834_fc5_x86_64.cpp
     ./a.out

   To see the bug:
     g++ -Wall -O1 gcc_trunk_2006_06_12_0834_fc5_x86_64.cpp
     ./a.out

   Note the difference in the last line of the output:
       Correct: 1 0 0
     Incorrect: 0 0 0

   The output is also incorrect for -O2 and -O3.

   The last line of the output is correct if compiled with:
     g++ -Wall -O1 -DBAD_WORKAROUND gcc_trunk_2006_06_12_0834_fc5_x86_64.cpp
     ./a.out

   Platform:
     Fedora Core release 5 (Bordeaux)
     Linux rosie.lbl.gov 2.6.15-1.2054_FC5 #1 SMP Tue Mar 14 15:48:20 EST 2006 x
86_64 x86_64 x86_64 GNU/Linux

     % g++ -v
     Using built-in specs.
     Target: x86_64-unknown-linux-gnu
     Configured with: /net/rosie/scratch1/rwgk/gcc_trunk/configure --prefix=/usr
/local_cci/gcc_trunk_2006_06_12_0834_fc5_x86_64 --enable-languages=c,c++
     Thread model: posix
     gcc version 4.2.0 20060612 (experimental)
 */
Comment 1 Ralf W. Grosse-Kunstleve 2006-06-12 19:28:44 UTC
Created attachment 11656 [details]
short reproducer
Comment 2 Andrew Pinski 2006-06-13 04:41:08 UTC
Hmm, we get after dce, just:
  reduced_cell_two_folds[26] = {};

And DCE removes:
  this_616 = &reduced_cell_two_folds[26].u;
....
  #   SMT.68_1055 = V_MAY_DEF <SMT.68_1054>;
  this_616->elems[0] = 1;
  #   SMT.68_1056 = V_MAY_DEF <SMT.68_1055>;
  this_616->elems[1] = 0;
  #   SMT.68_1057 = V_MAY_DEF <SMT.68_1056>;
  this_616->elems[2] = 0;
...
  this_621 = &reduced_cell_two_folds[26].h;
...
  #   SMT.68_1058 = V_MAY_DEF <SMT.68_1057>;
  this_621->elems[0] = 2;
  #   SMT.68_1059 = V_MAY_DEF <SMT.68_1058>;
  this_621->elems[1] = 1;
  #   SMT.68_1060 = V_MAY_DEF <SMT.68_1059>;
  this_621->elems[2] = 1;


Which does not make sense.  Nothing is special in alias shows what is going wrong.
Comment 3 Volker Reichelt 2006-06-13 13:11:58 UTC
Confirmed.

Shorter testcase (should return 0, but returns 1):

====================================================================
struct A
{
  int i, j[9];
  A() : i(1) { j[0]=j[1]=j[2]=j[3]=j[4]=j[5]=j[6]=j[7]=j[8]=0; }
};

struct B
{
  A a;
};

B b[] =
{
  {}, {}, {}, {}, {}, {}, {}, {}, {}, {},
  {}, {}, {}, {}, {}, {}, {}, {}, {}, {},
  {}, {}, {}, {}, {}
};

int main()
{
  return 1 - b[sizeof(b)/sizeof(B) - 1].a.i;
}
====================================================================
Comment 4 Daniel Berlin 2006-06-13 13:29:15 UTC
Subject: Re:  [4.2 Regression] optimizer bug

pinskia at gcc dot gnu dot org wrote:
> ------- Comment #2 from pinskia at gcc dot gnu dot org  2006-06-13 04:41 -------
> Hmm, we get after dce, just:
>   reduced_cell_two_folds[26] = {};
> 
> And DCE removes:
>   this_616 = &reduced_cell_two_folds[26].u;
> ....
>   #   SMT.68_1055 = V_MAY_DEF <SMT.68_1054>;
>   this_616->elems[0] = 1;
>   #   SMT.68_1056 = V_MAY_DEF <SMT.68_1055>;
>   this_616->elems[1] = 0;
>   #   SMT.68_1057 = V_MAY_DEF <SMT.68_1056>;
>   this_616->elems[2] = 0;
> ...
>   this_621 = &reduced_cell_two_folds[26].h;
> ...
>   #   SMT.68_1058 = V_MAY_DEF <SMT.68_1057>;
>   this_621->elems[0] = 2;
>   #   SMT.68_1059 = V_MAY_DEF <SMT.68_1058>;
>   this_621->elems[1] = 1;
>   #   SMT.68_1060 = V_MAY_DEF <SMT.68_1059>;
>   this_621->elems[2] = 1;
> 
> 
> Which does not make sense.  Nothing is special in alias shows what is going
> wrong.
> 
> 

The only thing i can think of is that SMT.68 is not marked global.
Is it?


Comment 5 Andrew Pinski 2006-06-13 14:26:35 UTC
(In reply to comment #4)
> The only thing i can think of is that SMT.68 is not marked global.
> Is it?

Some how I missed that before:
SMT.68, UID 2839, struct reduced_cell_two_fold_info, is aliased, is addressable
Comment 6 Daniel Berlin 2006-06-13 17:15:50 UTC
So it should have been marked global, and should alias the global var, but apparently the global var doesn't pop into it's alias set
Comment 7 Andrew Pinski 2006-06-29 19:47:20 UTC
This is target independent.
Comment 8 Steven Bosscher 2006-07-20 21:29:13 UTC
Could this be a dup of the now-fixed Bug 28410 ?
Comment 9 Volker Reichelt 2006-07-21 10:17:58 UTC
> Could this be a dup of the now-fixed Bug 28410 ?

No, because this one is still present.
(Or the fix in PR 28410 is incomplete.)
Comment 10 Janis Johnson 2006-08-08 15:51:21 UTC
A regression hunt on powerpc-linux identified the following patch where the testcase from comment #3 starts failing:

    http://gcc.gnu.org/viewcvs?view=rev&rev=109938

    r109938 | dberlin | 2006-01-19 01:42:48 +0000 (Thu, 19 Jan 2006)
Comment 11 Daniel Berlin 2006-08-21 02:16:56 UTC
This is impressive.
We add b as a may alias to the SMT, then it disappears from the list before call clobbering!
Comment 12 Daniel Berlin 2006-08-22 14:04:27 UTC
Subject: Bug 28003

Author: dberlin
Date: Tue Aug 22 14:04:16 2006
New Revision: 116323

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=116323
Log:
2006-08-22  Daniel Berlin  <dberlin@dberlin.org>

	PR tree-optimization/28003
	* tree-ssa-alias.c (compute_may_aliases): Compute call clobbered
	before grouping aliases.


Added:
    trunk/gcc/testsuite/g++.dg/tree-ssa/pr28003.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/tree-ssa-alias.c

Comment 13 Daniel Berlin 2006-08-22 14:05:01 UTC
Fixed
Comment 14 Daniel Berlin 2006-08-22 14:05:16 UTC
Fixed