This is an archive of the discontinued LLVM Phabricator instance.

[mlir][Vector][Affine] Fix heap-use-after-free in vectorizer
ClosedPublic

Authored by dcaballe on Mar 10 2021, 6:49 PM.

Details

Summary

This patch fixes a heap-use-after-free introduced by the recent changes
in the vectorizer: https://reviews.llvm.org/rG95db7b4aeaad590f37720898e339a6d54313422f
The problem is due to the way candidate loops are visited. All candidate loops
are pattern-matched beforehand using the 'NestedMatch' utility. These matches may
intersect with each other so it may happen that we try to vectorize a loop that
was previously vectorized. The new vectorization algorithm replaces the original
loops that are vectorized with new loops and, therefore, any reference to the
original loops in the pre-computed matches becomes invalid.

This patch fixes the problem by classifying the candidate matches into buckets
before vectorization. Each bucket contains all the matches that intersect. The
vectorizer uses these buckets to make sure that we only vectorize *one* match from
each bucket, at most.

Diff Detail

Event Timeline

dcaballe created this revision.Mar 10 2021, 6:49 PM
dcaballe requested review of this revision.Mar 10 2021, 6:49 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 10 2021, 6:49 PM
ftynse accepted this revision.Mar 11 2021, 4:47 AM

Thanks for the fix! Don't forget to reland the patches I rolled back.

This revision is now accepted and ready to land.Mar 11 2021, 4:47 AM