Bug 90869 - Non-disambiguated memory accesses
Summary: Non-disambiguated memory accesses
Status: ASSIGNED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 10.0
: P3 enhancement
Target Milestone: ---
Assignee: Jan Hubicka
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-06-13 11:21 UTC by Jan Hubicka
Modified: 2021-05-04 12:31 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2020-01-28 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Hubicka 2019-06-13 11:21:49 UTC
Hi,
in the following testcases we should be able to disambiguate accesses:
struct a
{
  int ia;
  struct b
  {
    int ib;
    struct c
    {
      int ic;
    } c[2];
  } b[5];
} a;

test (int i,int j)
{
  struct c *bptr=&a.b[i].c[1];
  struct c *cptr=&a.b[j].c[2];
  bptr->ic=1;
  cptr->ic=2;
  return bptr->ic;
}

and

struct data {int data,data2;} *ptr;
int *ptr2;
struct a {struct data a;}; 
struct b {struct a a[10];} *bptr;
test (int i)
{
  struct a *aptr = &bptr->a[i];
  aptr->a.data=0;
  ptr->data2=1;
  return aptr->a.data;
}

(this one works with clang but does not because of way we fold address calculations)

and

typedef int (*fnptr) ();

__attribute__ ((used))
int *a,**aptr=&a;

__attribute__ ((used))
struct b {int *a;} *bptr,b;

static void
inline_me_late (int argc)
{
  if (argc == -1)
    *bptr = b;
}

int
main (int argc)
{
  a = 0;
  inline_me_late (argc);
  if (!__builtin_constant_p (a == 0))
    __builtin_abort ();
  return 0;
}

compiled with -O3 -flto -fno-early-inlining
Comment 1 Jan Hubicka 2019-06-13 11:41:01 UTC
Another testcase. Here we should disambiguate both cases while we do only second
struct a {int a1; int a2;};
struct b:a {};

struct b bvar,*bptr2;
int
test(void)
{
  struct a *bptr = &bvar;
  bptr->a2=0;
  bptr2->a1=1;
  return bptr->a2;
}
int
test2(void)
{
  struct b *bptr = &bvar;
  bptr->a2=0;
  bptr2->a1=1;
  return bptr->a2;
}
Comment 2 Jan Hubicka 2019-06-13 15:01:13 UTC
Author: hubicka
Date: Thu Jun 13 15:00:41 2019
New Revision: 272247

URL: https://gcc.gnu.org/viewcvs?rev=272247&root=gcc&view=rev
Log:
	PR tree-optimize/90869
	* tree-ssa-alias.c (indirect_ref_may_alias_decl_p): Watch for view
	converts in MEM_REF referencing decl rather than view converts
	from decl type to MEM_REF type.

	* g++.dg/tree-ssa/alias-access-path-1.C: New testcase.


Added:
    trunk/gcc/testsuite/g++.dg/tree-ssa/alias-access-path-1.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-alias.c
Comment 3 Martin Liška 2020-01-28 11:55:13 UTC
@Honza: Can we close this?
Comment 4 Jan Hubicka 2020-02-24 10:29:30 UTC
No, we disambiguate the first testcase but not the others.