This is an archive of the discontinued LLVM Phabricator instance.

[LV] Support sinking recipe in replicate region after another region.
ClosedPublic

Authored by fhahn on Jun 2 2021, 5:10 AM.

Details

Summary

This patch handles sinking a replicate region after another replicate
region. In that case, we can connect the sink region after the target
region. This properly handles the case for which an assertion has been
added in 337d7652823f.

Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=34842.

Diff Detail

Event Timeline

fhahn created this revision.Jun 2 2021, 5:10 AM
fhahn requested review of this revision.Jun 2 2021, 5:10 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 2 2021, 5:10 AM
fhahn updated this revision to Diff 350838.Jun 9 2021, 3:05 AM

Rebase & ping :)

Ayal added a comment.Jun 10 2021, 6:47 AM

Minor comments and suggestions. This should compete the handling of sinking a recipe after another, thanks!

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
9176

These asserts are better placed inside the lambda?

9179

// If the recipe >> // The recipe

"recpliate"

9185

same asserts...

9198

// If the target >> // The target

9208

Set SinkRegion and TargetRegion once at the outset?

9211

Have this simplest and most common (!SinkRegion && !TargetRegion) case early-exit first?
Followed by the next simple (!SinkRegion && TargetRegion) case; both move the Sink recipe via Sink->move*();
Last deal with SinkRegion by first disconnecting it and then placing it between an AfterBlock and its single successor, where AfterBlock is produced by splitting the Target block if !TargetRegion.

9220

same assert...

9228

This part of disconnecting SinkRegion could be done once for both TargetRegion and !TargetRegion cases.

llvm/test/Transforms/LoopVectorize/first-order-recurrence-sink-replicate-region.ll
380

%rem and %rem.div both need to sink after Previous = %recur.next (which is invariant...), and do so by first having %rem move after Previous and then having %rem.div move after %rem, where this last move is the one that moves a replicated region after another, right?

fhahn updated this revision to Diff 351654.Jun 12 2021, 6:12 AM
fhahn marked an inline comment as done.

Thanks for all the comments Ayal! I updated the code and removed some redundancies as suggested.

fhahn marked 4 inline comments as done.Jun 12 2021, 6:13 AM
fhahn added inline comments.
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
9176

I moved the SESE one. The other one would be a bit more work, because currently the lambda does not have access to Target's/Sink's parents. A general helper to check for replicate regions in the future may be helpful.

9211

I restructured the code to handle the simplest case first, then SinkRegion and then TargetRegion.

Ayal added inline comments.Jun 16 2021, 1:26 PM
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
9176

Lambda can check if R->getParent() has size 1, right? This should be asserted for both sink and target.

9256

Handle the "SinkRegion && !TargetRegion" case here, splitting TargetBlock etc., instead of last below?

9258

Handle this relatively simple "!SinkRegion && TargetRegion" case 2nd, after the simplest !SinkRegion && !TargetRegion? (I.e., can check first if (!SinkRegion), etc.)

fhahn updated this revision to Diff 352729.Jun 17 2021, 7:52 AM
fhahn marked an inline comment as done.

Restructure checks as suggested and moved the assertion to lambda, thanks!

fhahn marked 4 inline comments as done.Jun 17 2021, 7:55 AM
fhahn added inline comments.
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
9176

Yes, I moved the assertion,

9256

Done, thanks!

9258

I restructured the code, it should be a bit more compact now.

fhahn marked 2 inline comments as done.Jun 23 2021, 7:26 AM

ping :)

Ayal accepted this revision.Jun 23 2021, 11:03 AM

Looks good to me, thanks for accommodating the changes!
Adding a minor error message suggestion.

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
9170

"parent of R must be a replicator with a single recipe" >>
"A recipe in an original replicator region must be the only recipe in its block"?
("original" - because this does not hold for merged replicator regions).

This revision is now accepted and ready to land.Jun 23 2021, 11:03 AM
fhahn added a comment.Jun 24 2021, 5:57 AM

Thanks!

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
9170

Sounds good, I'll update the message when committing!