Page MenuHomePhabricator

[GlobalOpt] recognize dead struct fields and propagate values
Needs RevisionPublic

Authored by chrib on May 14 2019, 10:36 AM.



Allow struct fields SRA and dead stores. This works by considering fields accesses from getElementPtr to be considered as a possible pointer root that can be cleaned up.
We check that the variable can be SRA by recursively checking the sub expressions with the new isSafeSubSROAGEP function.

basically this allows the array in following C code to be optimized out

struct Expr {

int a[2];
int b;


static struct Expr e;

int foo (int i)

e.b = 2;
e.a[i] = 1;
return e.b;


Diff Detail


Event Timeline

chrib created this revision.May 14 2019, 10:36 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 14 2019, 10:36 AM
chrib updated this revision to Diff 199480.May 14 2019, 10:43 AM
  • Fix comment
chrib edited the summary of this revision. (Show Details)May 14 2019, 11:05 AM
chrib retitled this revision from Improve GlobalOpt to recognize dead fields and propagate values to [GlobalOpt] recognize dead struct fields and propagate values.May 15 2019, 6:11 AM
jmolloy accepted this revision.Mon, May 20, 7:18 AM

I think I've convinced myself that this is correct. LGTM.

This revision is now accepted and ready to land.Mon, May 20, 7:18 AM
This revision was automatically updated to reflect the committed changes.
efriedma reopened this revision.Thu, May 23, 6:06 PM
efriedma added a subscriber: efriedma.

Reverted in r361581.

It regresses (represented by the testcase test/Transforms/GlobalOpt/globalsra-multigep.ll). Please be more careful in the future when you're changing an existing testcase, especially one with a comment that specifically says the transform you're trying to do is not valid.

This revision is now accepted and ready to land.Thu, May 23, 6:06 PM
efriedma requested changes to this revision.Thu, May 23, 6:06 PM
This revision now requires changes to proceed.Thu, May 23, 6:06 PM
chrib added a comment.Thu, May 23, 9:42 PM

looking at it. reverting in the meantime is fine