This is an archive of the discontinued LLVM Phabricator instance.

[SLPVectorizer] Fix crash in vectorizeChainsInBlock for scalable vector.
ClosedPublic

Authored by CarolineConcatto on Jun 23 2021, 12:26 PM.

Details

Summary

The function vectorizeChainsInBlock does not support scalable vector,
because function like canReuseExtract and isCommutative in the code
path assert with scalable vectors.

This patch avoids vectorizing blocks that have instructions with scalable vector
or when the block uses operands from outside the block that are
scalable vector.

Diff Detail

Event Timeline

CarolineConcatto requested review of this revision.Jun 23 2021, 12:26 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 23 2021, 12:26 PM
CarolineConcatto edited the summary of this revision. (Show Details)Jun 24 2021, 12:26 AM
CarolineConcatto edited the summary of this revision. (Show Details)Jun 24 2021, 12:33 AM

I think it is better to change buildTree_rec function and check that if S.getOpcode() == Instruction::ExtractElement && cast<ExtractElementInst>(S.getMainOp())->getVectorOperandType()->isScalalableVectorType() then make it a gather node. Also, need to update getEntryCost function to filter out such extractelements from isGatherShuffledEntry function call and consider them as just simple gathers.

Matt added a subscriber: Matt.Jun 24 2021, 11:11 AM
  • Remove the generic approach for scalable vector
  • Use gather node for extract instructions with scalable vector

@ABataev I try to follow your suggestion.
I could not find a test that could fail without a extract instruction.
So I followed your suggestion.
The previous one implemented was more generic.
What is done in getEntryCost is what you had in mind for the cost when it is an extract instruction?

ABataev added inline comments.Jun 30 2021, 9:07 AM
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
2681

cast<ExtractElementInst>(S.OpValue)->getVectorOperandType()

3751–3753

I would just add a check here && !isa<ScalableVectorType>(cast<ExtractElementInst>(E->getMainOp())->getVectorOperandType()) and drop changes in lines 3754-3760

3761

No need to call it again, it is called already in line 3721

-Remove redundant code in getEntryCost

CarolineConcatto marked 3 inline comments as done.Jun 30 2021, 9:42 AM

Thank you @ABataev.
I've changes to the correct way to avoid extract with scalable, as you suggested, in the cost.

This revision is now accepted and ready to land.Jun 30 2021, 9:45 AM