This is an archive of the discontinued LLVM Phabricator instance.

[IR][CostModel] A scalable vector shuffle can't be an identity or reverse shuffle.
ClosedPublic

Authored by craig.topper on Apr 28 2022, 9:55 PM.

Details

Summary

Even if the minimum number of elements is 1 and the length doesn't change,
we don't know what vscale is so we can't classify it as identity mask. Instead it
is a zero element splat.

For reverse, we shouldn't classify it as a reverse unless there are at least 2 elements
in the mask. This applies to both fixed and scalable vectors. For fixed vectors, a single
element would be an identity shuffle. For scalable vector it's a zero elt splat.

Diff Detail

Event Timeline

craig.topper created this revision.Apr 28 2022, 9:55 PM
craig.topper requested review of this revision.Apr 28 2022, 9:55 PM
sdesmalen accepted this revision.Apr 29 2022, 1:48 AM
sdesmalen added inline comments.
llvm/include/llvm/IR/Instructions.h
2151–2153

nit: not an issue with your patch, but reading this comment made me think that a splatvector actually adheres to the criteria listed here:

  • it chooses all elements from exactly one source vector without lane crossings (it always chooses element 0)
  • it doesn't change the number of elements from it's input vectors. (true for <vscale x K x i32> shufflevector <vscale x K x i32> %ins, <vscale x K x i32> undef, <vscale x K x i32> zeroinitializer)

It should actually say "Return true if this shuffle chooses successive elements". Could you maybe update the wording as part of this patch?

llvm/test/Analysis/CostModel/RISCV/rvv-shuffle.ll
8

Has the cost-model not yet been implemented for RVV that these costs are all Invalid?

This revision is now accepted and ready to land.Apr 29 2022, 1:48 AM
craig.topper added inline comments.Apr 29 2022, 9:08 AM
llvm/include/llvm/IR/Instructions.h
2151–2153

I think "without lane crossing" meant the individual elements don't change their position. isSelect() also says "without lane crossing"

llvm/test/Analysis/CostModel/RISCV/rvv-shuffle.ll
8

This issue was found while the cost model was being added. It was committed after I uploaded this patch showing a cost of 0. When I rebase this patch it will change from 0 to non-zero.

Block select and reverse as well.

craig.topper requested review of this revision.Apr 29 2022, 9:43 AM
craig.topper retitled this revision from [IR][CostModel] A scalable vector shuffle can't be an identity shuffle. to [IR][CostModel] A scalable vector shuffle can't be an identity, select, or reverse shuffle..
craig.topper edited the summary of this revision. (Show Details)

Maybe select is ok, and it's only reverse that also needs to be fixed. I'm checking now.

Modify how reverse is blocked. Do it based on the number of elements in the mask.

craig.topper retitled this revision from [IR][CostModel] A scalable vector shuffle can't be an identity, select, or reverse shuffle. to [IR][CostModel] A scalable vector shuffle can't be an identity or reverse shuffle..Apr 29 2022, 10:00 AM
craig.topper edited the summary of this revision. (Show Details)
liaolucy accepted this revision.May 9 2022, 6:30 PM

LGTM, thanks

This revision is now accepted and ready to land.May 9 2022, 6:30 PM
This revision was landed with ongoing or failed builds.May 9 2022, 9:47 PM
This revision was automatically updated to reflect the committed changes.