Bug 20121 - Aliasing lameness results in missing common subexpressions
Summary: Aliasing lameness results in missing common subexpressions
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.0.0
: P2 enhancement
Target Milestone: 4.2.0
Assignee: Not yet assigned to anyone
URL:
Keywords: alias, missed-optimization
Depends on: 13761
Blocks:
  Show dependency treegraph
 
Reported: 2005-02-21 14:46 UTC by Jeffrey A. Law
Modified: 2006-02-16 21:25 UTC (History)
3 users (show)

See Also:
Host: Any
Target: Any
Build: Any
Known to work:
Known to fail:
Last reconfirmed: 2005-12-24 20:32:33


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jeffrey A. Law 2005-02-21 14:46:29 UTC
Our aliasing code is failing pretty badly in disambiguating memory addresses,
which in turn can lead to missing opportunities to remove memory operations.

Here's an exmaple taken from GCC itself (find_unreachable_blocks):

typedef unsigned int size_t;
extern void *xmalloc (size_t) __attribute__ ((__malloc__));
struct edge_def
{
  struct basic_block_def *dest;
  int flags;
};
typedef struct edge_def *edge;
struct basic_block_def
{
  int flags;
};
typedef struct basic_block_def *basic_block;
extern int n_basic_blocks;
extern edge frob ();
void
find_unreachable_blocks (int frobit)
{
  basic_block *tos, *worklist, bb;
  tos = worklist = xmalloc (sizeof (basic_block) * n_basic_blocks);
  edge e = frob();
  if (!(e->dest->flags & 4))
    {
      e->dest->flags |= 4;
      *tos++ = e->dest;
    }
}


The store into e->dest->flags does not affect e or e->dest.  Thus we only need
to load e->dest once.  Unfortunately, we load it twice.

I'll be checking this testcase into the testsuite (xfailed appropriately).
Comment 1 Andrew Pinski 2005-02-21 14:54:39 UTC
Confirmed, CCing Daniel because he is working on structure aliasing right now.
Comment 2 Andrew Pinski 2005-02-21 15:00:06 UTC
This is basically PR 13761 almong other bugs.
Comment 3 Andrew Pinski 2006-02-16 21:25:35 UTC
Fixed by Daniel's patches.
We get now:

<bb 2>:
  D.1542 = xmalloc ((long unsigned int) n_basic_blocks * 4);
  e = frob ();
  D.1544 = e->dest;
  D.1545 = D.1544->flags;
  if ((D.1545 & 4) == 0) goto <L0>; else goto <L1>;

<L0>:;
  D.1544->flags = D.1545 | 4;
  *(struct basic_block_def * *) D.1542 = D.1544;

<L1>:;
  return;