This is an archive of the discontinued LLVM Phabricator instance.

[LoopVectorize] Classify pointer induction updates as scalar only if they have one use
ClosedPublic

Authored by kmclaughlin on Oct 7 2021, 3:05 AM.

Details

Summary

collectLoopScalars collects pointer induction updates in ScalarPtrs, assuming
that the instruction will be scalar after vectorization. This may crash later
in VPReplicateRecipe::execute() if there there is another user of the instruction
other than the Phi node which needs to be widened.

This changes collectLoopScalars so that if there are any other users of
Update other than a Phi node, it is not added to ScalarPtrs.

Diff Detail

Event Timeline

kmclaughlin created this revision.Oct 7 2021, 3:05 AM
kmclaughlin requested review of this revision.Oct 7 2021, 3:05 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 7 2021, 3:05 AM

This looks like a sensible fix to me. I just had a couple of minor comments ...

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

Hi @kmclaughlin, I think it's probably better to use isa<PHINode> here instead of dyn_cast<PHINode>.

llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-gep.ll
121

Maybe it's worth simplifying the test a little by killing off the CHECK lines before and after the vector.body just to make it easier to read?

kmclaughlin marked 2 inline comments as done.
  • Replaced use of dyn_cast<PHINode> in collectLoopScalars with isa<PHINode>
  • Reduced the CHECK lines before & after vector.body for the new test added to sve-widen-gep.ll
david-arm accepted this revision.Oct 8 2021, 12:45 AM

LGTM. Thanks for making the changes!

This revision is now accepted and ready to land.Oct 8 2021, 12:45 AM
fhahn added a comment.Oct 8 2021, 12:48 AM

I think it would be good to update the title to better reflect the change here. From the title it sounds like a change in VPReplicateRecipe::execute() , but it actually adjusts how pointers are classified which as a side-effect fixes a crash.

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

nit: 'llvm:: should not be needed. Can you also add comment here to explain the reasoning?

Also, no need to capture everything in the lambda.

llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-gep.ll
166

just return void?

fhahn added inline comments.Oct 8 2021, 12:53 AM
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
5137

Hm, with this change we might miss some cases where the uses of Update are still scalar. Would it be better to only return early here if the only user of the update instruction is the pointer phi and let the code below handle the other cases?

kmclaughlin marked 3 inline comments as done.
kmclaughlin retitled this revision from [LoopVectorize] Fix crash in VPReplicateRecipe::execute() for scalable vectors to [LoopVectorize] Classify pointer induction updates as scalar only if they have one use.
kmclaughlin edited the summary of this revision. (Show Details)
  • Return early from collectLoopScalars if Update has one use. Removed line to insert Update into PossibleNonScalarPtrs if this is not the case to instead let the code below the if (isScalarPtrInduction... block handle other cases.
  • Return void from @pointer_induction test

LGTM! It looks like you've addressed @fhahn's comments.

fhahn accepted this revision.Oct 11 2021, 7:29 AM

LGTM, thanks for the update. I added a few more tiny suggestions to slightly improve readability of the test case that would be good to include.

llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-gep.ll
151

nit: could just use a i8* %start argument instead of [64 x i8]?

152

nit: unused pointer?

156

nit: might be good to drop the .sroa prefix, perhaps just something like %ptr.phi or something and then %ptr.phi.next instead of %incdec.ptr.

This revision was landed with ongoing or failed builds.Oct 12 2021, 5:33 AM
This revision was automatically updated to reflect the committed changes.
kmclaughlin marked 3 inline comments as done.