This is an archive of the discontinued LLVM Phabricator instance.

Process gep (phi ptr1, ptr2) in SROA
ClosedPublic

Authored by rampitec on Apr 30 2020, 5:02 PM.

Diff Detail

Event Timeline

rampitec created this revision.Apr 30 2020, 5:02 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 30 2020, 5:02 PM
rampitec updated this revision to Diff 261516.May 1 2020, 12:19 PM

Fixed iterator logic.

rampitec updated this revision to Diff 262230.May 5 2020, 2:50 PM

Added stores to some tests to prevent undef output.

rampitec updated this revision to Diff 262712.May 7 2020, 11:47 AM

Found an endless loop with gep (phi gep, ...). Fixed.

rampitec updated this revision to Diff 262788.May 7 2020, 5:02 PM

Found yet another breakage, when the block to insert new GEP is a EHPad. Fixed.

In fact that becomes overly complicated when an incoming value is not an instruction, so limited patch to work with instructions only. This covers most of the cases anyway and handling of anything else could be a separate change.

PSDB passed.

rampitec updated this revision to Diff 264125.May 14 2020, 4:26 PM

Extracted folding into a separate function.

rampitec updated this revision to Diff 264268.May 15 2020, 9:53 AM

Added a non-inbound GEP test.

rampitec updated this revision to Diff 264958.May 19 2020, 10:29 AM

Added check for constant indexes and test.

Ping! @chandlerc do you mind to take a look? Thanks in advance!

rampitec updated this revision to Diff 266313.May 26 2020, 1:16 PM

Rebased.
Ping!

arsenm added inline comments.May 29 2020, 9:13 AM
llvm/lib/Transforms/Scalar/SROA.cpp
3542

any_of and invert?

3543–3546

dyn_cast instead of isa && cast?

3569–3570

dyn_cast instead of isa && cast

rampitec updated this revision to Diff 267299.May 29 2020, 10:46 AM
rampitec marked 3 inline comments as done.

Addressed review comments.

arsenm accepted this revision.May 29 2020, 11:52 AM

LGTM with nit

llvm/lib/Transforms/Scalar/SROA.cpp
3544

I instead of in for the isas

This revision is now accepted and ready to land.May 29 2020, 11:52 AM
rampitec updated this revision to Diff 267323.May 29 2020, 12:01 PM
rampitec marked an inline comment as done.

Replaced In with I in isas.

arsenm accepted this revision.May 29 2020, 12:01 PM
This revision was automatically updated to reflect the committed changes.

It has resulted in some failures, I have reverted it for now.

rampitec updated this revision to Diff 267415.May 29 2020, 5:00 PM

Reopening after revert. There were two bugs:

  1. PHI can only be recreated in the same BB for incoming block logic to work, so check PHI and GEP are in the same block.
  2. That was not right to call visit() from a visitor itself, that resulted in endless loop. Each folding separately (select and PHI) works, but not together. If we have a phi (select) the endless loop happens. Switched to enqueueUsers(). That is also only needed to call it on a newly created PHI or select, as the only users of newly created GEPs are the same PHI or select and the only action expected is enqueueUsers().
rampitec reopened this revision.May 29 2020, 5:01 PM
This revision is now accepted and ready to land.May 29 2020, 5:01 PM
arsenm accepted this revision.May 29 2020, 5:48 PM
rampitec updated this revision to Diff 267443.May 30 2020, 12:28 AM

Slightly updated test to avoid autogenerated check namings instability between Windows and Linux.

This revision was automatically updated to reflect the committed changes.

Hi!

I wrote
https://bugs.llvm.org/show_bug.cgi?id=46280
for a crash that started happening with this commit.

Hi!

I wrote
https://bugs.llvm.org/show_bug.cgi?id=46280
for a crash that started happening with this commit.

Thanks! Here is the fix: D81674

Hi!

I wrote
https://bugs.llvm.org/show_bug.cgi?id=46280
for a crash that started happening with this commit.

Thanks! Here is the fix: D81674

Great! Thanks!

Hi!

https://bugs.llvm.org/show_bug.cgi?id=47945 started happening with this patch.

D89978 fixes it.