which pass for optimizing access to a global struct?

Hi!

which pass do you recommend to optimize access to a global
struct? for example:

struct
{
int a;
int b;
} global;

void foo(int x)
{
     global.a = x;
     int y = global.a; // should be replaced by int y = x;
}

I guess it's one of the alias passes but which one to choose?
Thanks,
-Jochen

Hi Jochen,

which pass do you recommend to optimize access to a global
struct? for example:

struct
{
int a;
int b;
} global;

void foo(int x)
{
      global.a = x;
      int y = global.a; // should be replaced by int y = x;
}

the global value numbering (gvn) pass can do this, as can the instruction
combiner (-instcombine). Maybe there are some others too.

Ciao, Duncan.