User account creation filtered due to spam.

Bug 26258 - [4.1/4.2 Regression] Wrong alias information for struct addresses in PHIs
Summary: [4.1/4.2 Regression] Wrong alias information for struct addresses in PHIs
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.1.0
: P1 normal
Target Milestone: 4.1.0
Assignee: Not yet assigned to anyone
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: alias, patch, wrong-code
Depends on:
Blocks:
 
Reported: 2006-02-13 15:20 UTC by Richard Biener
Modified: 2006-02-14 09:59 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-02-13 16:25:48


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Biener 2006-02-13 15:20:51 UTC
Compiling with -O2 the following creates invalid virtual operands after
SRA:

struct Foo { int a; int b; };

Foo foo(Foo p, bool ret_first)
{
  Foo first = p;
  Foo last = p;
  return ret_first ? first : last;
}

  # iftmp.0D.1761_1 = PHI <&firstD.1740(1), &lastD.1757(0)>;
<L2>:;
  #   VUSE <SFT.6D.1783_24>;
  #   VUSE <SFT.8D.1785_26>;
  SR.26D.1803_27 = iftmp.0D.1761_1->bD.1735;
  #   VUSE <SFT.6D.1783_24>;
  #   VUSE <SFT.8D.1785_26>;
  SR.25D.1802_28 = iftmp.0D.1761_1->aD.1734;

the access to ->b should VUSE SFTs 5 and 7.
Comment 1 Andrew Pinski 2006-02-13 15:24:48 UTC
C testcase works correctly.
Comment 2 Richard Biener 2006-02-13 15:31:46 UTC
C testcase that fails (the PHI <&first, &last> is the important part):

typedef struct { int a; int b; } Foo;

Foo foo(Foo p, _Bool ret_first)
{
  Foo first = p;
  Foo last = p;
  Foo *q;
  q = ret_first ? &first : &last;
  return *q;
}
Comment 3 Andrew Pinski 2006-02-13 15:32:48 UTC
You can invoke the wrong aliasing before SRA:
typedef struct Foo { int a; int b; }Foo;

Foo foo(Foo first, Foo last, bool ret_first)
{
  Foo t;
  Foo *t1 = (ret_first ? &first : &last);
  t.a = t1->a;
  t.b = t1->b;
  return t;
}
Comment 4 Andrew Pinski 2006-02-13 15:37:29 UTC
Testcase for the mainline:
typedef struct Foo { int a; int b; }Foo;

Foo foo(Foo first, Foo last, bool ret_first)
{
  Foo t;
  Foo *t1 = (ret_first ? &first : &last);
  first.a = 2;
  last.b = 3;
  t.a = t1->a;
  t.b = t1->b;
  t.a += first.a;
  t.b += last.b;
  return t;
}
Comment 5 Andrew Pinski 2006-02-13 15:42:45 UTC
For the testcase in comment #4:
Points-to analysis

Constraints:
t1_1 = &first
t1_1 = &last

Solving graph:

Points-to sets
t1_1 = { first last }

Pointed-to sets for pointers in foo

t1_1, name memory tag: NMT.17, is dereferenced, points-to vars: { SFT.4 SFT.6 }


----

t1_1 is wrong in "Pointed-to sets for pointers in foo".  maybe we forget to add all the SFT's or something.
Comment 6 Andrew Pinski 2006-02-13 15:44:28 UTC
Actually contstraints is wrong.
in the first aliasing pass before proping into the addresses into PHI's:
iftmp.0_25 = &first
iftmp.0_25 = &first.b
iftmp.0_24 = &last
iftmp.0_24 = &last.b
Comment 7 Richard Biener 2006-02-13 16:25:48 UTC
I have a patch.
Comment 8 Mark Mitchell 2006-02-14 09:08:32 UTC
Sadly, this is a P1; a nasty optimization bug, on code without extensions, probably architecture independent, and did not exist in previous releases.
Comment 9 Richard Biener 2006-02-14 09:54:10 UTC
Subject: Bug 26258

Author: rguenth
Date: Tue Feb 14 09:54:07 2006
New Revision: 110962

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=110962
Log:
2006-02-14  Richard Guenther  <rguenther@suse.de>

        PR tree-optimization/26258
	* tree-ssa-structalias.c (find_func_aliases): Handle aggregates
	in PHI argument processing.

        * gcc.dg/torture/pr26258.c: New testcase.

Added:
    branches/gcc-4_1-branch/gcc/testsuite/gcc.dg/torture/pr26258.c
Modified:
    branches/gcc-4_1-branch/gcc/ChangeLog
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_1-branch/gcc/tree-ssa-structalias.c

Comment 10 Richard Biener 2006-02-14 09:59:01 UTC
Subject: Bug 26258

Author: rguenth
Date: Tue Feb 14 09:58:57 2006
New Revision: 110963

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=110963
Log:
2006-02-14  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/26258
	* tree-ssa-structalias.c (find_func_aliases): Handle aggregates
	in PHI argument processing.

	* gcc.dg/torture/pr26258.c: New testcase.

Added:
    trunk/gcc/testsuite/gcc.dg/torture/pr26258.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-structalias.c

Comment 11 Richard Biener 2006-02-14 09:59:50 UTC
Fixed.