This is an archive of the discontinued LLVM Phabricator instance.

[LV] ExtractValue instruction costs
ClosedPublic

Authored by SjoerdMeijer on Nov 30 2020, 6:12 AM.

Details

Summary

Instruction ExtractValue wasn't handled in LoopVectorizationCostModel::getInstructionCost(). As a result, it was modeled as a mul which may not be really accurate. Since it typically takes 1 instruction to extract a value from a vector we now model this with a cost of 1.

This is a follow-up of D92208, that required changing this regression test.

Diff Detail

Event Timeline

SjoerdMeijer created this revision.Nov 30 2020, 6:12 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 30 2020, 6:12 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
SjoerdMeijer requested review of this revision.Nov 30 2020, 6:12 AM
fhahn added inline comments.Nov 30 2020, 6:21 AM
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
6858

Better to use TTI.getVectorInstrCost? And perhaps also handle InsertValue?

SjoerdMeijer added inline comments.Nov 30 2020, 6:30 AM
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
6858

Yeah, cheers, will look/do that.

Decided to use TTI.getInstructionCost because getVectorInstrCost doesn't work here; it's an aggregate type, not really a vector.
That means the cost for a ExtractValue will be Free now, which I think is actually more accurate (than 1, and also the original 4).
I haven't added InsertValue yet, because that is e.g. not supported by getInstructionCost as it seems a little bit of a different beast.

Decided to use TTI.getInstructionCost because getVectorInstrCost doesn't work here; it's an aggregate type, not really a vector.
That means the cost for a ExtractValue will be Free now, which I think is actually more accurate (than 1, and also the original 4).
I haven't added InsertValue yet, because that is e.g. not supported by getInstructionCost as it seems a little bit of a different beast.

SGTM, I was thinking about *insertelement*... Sorry about that.

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

Should this also handle InsertValue for completeness?

SjoerdMeijer added inline comments.Nov 30 2020, 11:43 AM
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
6858

That doesn't seem to be supported by getInstructionCost, which means it returns -1 for InsertValue, which is probably not what we want. So, I think InsertValue needs a bit looking into, which probably best done separately? Although don't mind doing it part of this....

fhahn accepted this revision.Nov 30 2020, 11:54 AM

LGTM, we should be able to rely on TTI for the cost. Also handling InsertValue as a follow-up would be great!

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

oh yes, just saw that. Probably best to do it separately.

This revision is now accepted and ready to land.Nov 30 2020, 11:54 AM

Thanks, and I will look into InsertValue too. That may take a few days, but will certainly do that.

This revision was automatically updated to reflect the committed changes.