This is an archive of the discontinued LLVM Phabricator instance.

[LV] Fix analyzeInterleaving when -pass-remarks enabled
ClosedPublic

Authored by mtrofin on Feb 7 2018, 11:53 PM.

Details

Summary

If -pass-remarks=loop-vectorize, atomic ops will be seen by
analyzeInterleaving(), even though canVectorizeMemory() == false. This
is because we are requesting extra analysis instead of bailing out.

In such a case, we end up with a Group in both Load- and StoreGroups,
and then we'll try to access freed memory when traversing LoadGroups after having had released the Group when iterating over StoreGroups.

The fix is to include mayWriteToMemory() when validating that two
instructions are the same kind of memory operation.

Diff Detail

Event Timeline

mtrofin created this revision.Feb 7 2018, 11:53 PM
mtrofin edited the summary of this revision. (Show Details)Feb 7 2018, 11:58 PM
mtrofin added reviewers: mssimpso, davidxl.
davidxl added inline comments.Feb 8 2018, 9:20 AM
lib/Transforms/Vectorize/LoopVectorize.cpp
5929

s/exclussive/exclusive/

5933

Add a test case?

hsaito added a subscriber: hsaito.Feb 8 2018, 9:49 AM
hsaito added inline comments.
lib/Transforms/Vectorize/LoopVectorize.cpp
5931–5932

The root-cause of this problem is the fact that Interleaved Access Analysis is invoked as part of legality check ---- most likely because the original developer did not want to pass one extra arg to CostModel, etc., decided to keep InterleaveInfo in Legality class, and reviewers did not object to it. I'm currently working on a change set to address this architectural problem (i.e., optimization/cost model related work done in legal) by moving interleave access analysis outside of Legality.

Having said that, tightening "same kind of memory operation" check is a good thing to have even after the above mentioned refactoring is done.

mtrofin updated this revision to Diff 133465.Feb 8 2018, 11:43 AM
mtrofin marked 2 inline comments as done.

Added test.

mtrofin updated this revision to Diff 133466.Feb 8 2018, 11:45 AM

Removed blank line.

mtrofin added inline comments.Feb 8 2018, 11:46 AM
lib/Transforms/Vectorize/LoopVectorize.cpp
5931–5932

Thank you for the insight!

Ping - Thanks!

davidxl accepted this revision.Feb 9 2018, 9:11 AM

lgtm

This revision is now accepted and ready to land.Feb 9 2018, 9:11 AM
This revision was automatically updated to reflect the committed changes.