User account creation filtered due to spam.

Bug 47365 - [4.5/4.6 Regression] wrong code with -O -ftree-pre
Summary: [4.5/4.6 Regression] wrong code with -O -ftree-pre
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.5.3
: P3 normal
Target Milestone: 4.5.3
Assignee: Richard Biener
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2011-01-19 22:26 UTC by Zdenek Sojka
Modified: 2011-01-21 14:06 UTC (History)
1 user (show)

See Also:
Host: x86_64-pc-linux-gnu
Target: x86_64-pc-linux-gnu
Build:
Known to work: 4.4.6
Known to fail: 4.5.3, 4.6.0
Last reconfirmed: 2011-01-20 10:50:43


Attachments
reduced testcase (202 bytes, text/plain)
2011-01-19 22:26 UTC, Zdenek Sojka
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Zdenek Sojka 2011-01-19 22:26:36 UTC
Created attachment 23035 [details]
reduced testcase

Reported by Vegard Nossum at IRC.

Output:
$ gcc-4.5 -O -ftree-pre testcase.c
$ ./a.out 
Aborted

In the testcase.c.092t.pre dump, there is:
...
<bb 2>:
  D.2739_4 = b.a[0].i;
  i.0_5 = i;
  if (D.2739_4 != i.0_5)
    goto <bb 3>;
  else
    goto <bb 4>;

<bb 3>:
  b.a[0] = b.a[1];
  b.a[1].i = D.2739_4;
  pretmp.3_6 = b.a[1].i;
  goto <bb 6>;

<bb 4>:
...
<bb 9>:

<bb 6>:
  # prephitmp.4_8 = PHI <D.2739_4(9), pretmp.3_6(3)>
  D.2739_9 = prephitmp.4_8;
  D.2739_9 = prephitmp.4_8;
  if (D.2739_9 == 0)
    goto <bb 7>;
...

Problematic line is
  pretmp.3_6 = b.a[1].i;
which reads the new value of "b.a[1].i". It should either happen one line earlier, or it should read "b.a[0].i".

It seems that the fact "b.a[0] = b.a[1]" overwrites "b.a[0].i" is ignored.

Of couse I can be wrong.

Tested revisions:
r169006 - OK
4.5 r168785 - fail
4.4 r168785 - OK
Comment 1 Richard Biener 2011-01-20 10:50:43 UTC
Confirmed and mine.
Comment 2 Richard Biener 2011-01-20 12:01:23 UTC
What happens is that when translating D.2739_9 = b.a[0].i; from bb6 to
bb3 value-numbering does look through the aggregate copy b.a[0] = b.a[1];
continuing to look for b.a[1].i and finding D.2737_7 = b.a[1].i; from bb4
(which is ok - the consumer has to check availability).  Thus
b.a[1].i ends up in antic-out (not a problem) with a new value-number,
it doesn't end up in antic-in of bb3.

b.a[0].i is partially redundant in bb6, D.2739_4 is correctly found as
the available expression for it via bb6.  But when we translate
b.a[0].i to bb3 again during insertion we again obtain b.a[1].i
(because it's also still in the phi-translation cache).  It is
obviously not available here so we insert it.  Oops.

We don't prune invalid translations during insertion - that's the
basic problem.  We'd expect to find a leader as the translated
expression has a SCCVN value-number.

The problem is latent on trunk.
Comment 3 Zdenek Sojka 2011-01-21 00:06:51 UTC
(In reply to comment #2)
> The problem is latent on trunk.

Updating the summary to show in the 4.6 regression list.
Comment 4 Richard Biener 2011-01-21 14:02:45 UTC
Author: rguenth
Date: Fri Jan 21 14:02:41 2011
New Revision: 169089

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=169089
Log:
2011-01-21  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/47365
	* tree-ssa-sccvn.h (vn_lookup_kind): Declare.
	(vn_reference_lookup_pieces): Adjust.
	(vn_reference_lookup): Likewise.
	* tree-ssa-sccvn.c (vn_walk_kind): New static global.
	(vn_reference_lookup_3): Only look through kills if in
	VN_WALKREWRITE mode.
	(vn_reference_lookup_pieces): Adjust.
	(vn_reference_lookup): Likewise.
	(visit_reference_op_load): Likewise.
	(visit_reference_op_store): Likewise.
	* tree-ssa-pre.c (phi_translate_1): Use VN_WALK mode.
	(compute_avail): Likewise.
	(eliminate): Likewise.

	* gcc.dg/torture/pr47365.c: New testcase.
	* gcc.dg/tree-ssa/pr47392.c: Likewise.

Added:
    trunk/gcc/testsuite/gcc.dg/torture/pr47365.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/pr47392.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-pre.c
    trunk/gcc/tree-ssa-sccvn.c
    trunk/gcc/tree-ssa-sccvn.h
Comment 5 Richard Biener 2011-01-21 14:05:03 UTC
Author: rguenth
Date: Fri Jan 21 14:05:00 2011
New Revision: 169090

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=169090
Log:
2011-01-21  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/47365
	* tree-ssa-sccvn.h (vn_lookup_kind): Declare.
	(vn_reference_lookup_pieces): Adjust.
	(vn_reference_lookup): Likewise.
	* tree-ssa-sccvn.c (vn_walk_kind): New static global.
	(vn_reference_lookup_3): Only look through kills if in
	VN_WALKREWRITE mode.
	(vn_reference_lookup_pieces): Adjust.
	(vn_reference_lookup): Likewise.
	(visit_reference_op_load): Likewise.
	(visit_reference_op_store): Likewise.
	* tree-ssa-pre.c (phi_translate_1): Use VN_WALK mode.
	(compute_avail): Likewise.
	(eliminate): Likewise.

	* gcc.dg/torture/pr47365.c: New testcase.
	* gcc.dg/tree-ssa/pr47392.c: Likewise.

Added:
    branches/gcc-4_5-branch/gcc/testsuite/gcc.dg/torture/pr47365.c
    branches/gcc-4_5-branch/gcc/testsuite/gcc.dg/tree-ssa/pr47392.c
Modified:
    branches/gcc-4_5-branch/gcc/ChangeLog
    branches/gcc-4_5-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_5-branch/gcc/tree-ssa-pre.c
    branches/gcc-4_5-branch/gcc/tree-ssa-sccvn.c
    branches/gcc-4_5-branch/gcc/tree-ssa-sccvn.h
Comment 6 Richard Biener 2011-01-21 14:06:55 UTC
Fixed.