This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Don't accidentally match deinterleave masks as interleaves
ClosedPublic

Authored by luke on Mar 15 2023, 4:10 PM.

Details

Summary

Consider a shuffle mask of <0, 2>:
This is one of two deinterleave masks to deinterleave a vector of 4
elements with factor 2.
Unfortunately, this is also technically an interleave mask, where
two subvectors of length 1 at indexes 0 and 2 will be interleaved.
This is because a mask can interleave non-contiguous subvectors:
e.g. <0, 6, 4, 1, 7, 5> on a vector of size 8:

<0 1 2 3 4 5 6 7> indices
 ^ ^     ^ ^ ^ ^
 0 0     2 2 1 1  deinterleaved subvector

This means that deinterleaving shuffles can accidentally be costed as
interleaves.
And it's incorrect in the context of interleaves, because the
only interleave shuffles we model at the moment are single permutation
shuffles, i.e. we are interleaving the first vector below and ignoring
the second:

shufflevector <2 x i32> %v0, <2 x i32> poison, <2 x i32> <i32 0, i32 2>

A mask of <0, 2> interleaves across both vectors.

The fix here is to set NumInputElts correctly: We were setting it to
twice the mask length, i.e. using both input vectors. But in fact we're
actually only using the first vector here, and isInterleaveMask actually
already has logic to ensure that the mask indices stay within the bounds
of the input vectors.

This lacks a test case due to how we're unable to test deinterleave
shuffles (because they are length changing), but is covered in the tests
in D145155

Diff Detail

Event Timeline

luke created this revision.Mar 15 2023, 4:10 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 15 2023, 4:10 PM
luke requested review of this revision.Mar 15 2023, 4:10 PM
luke edited the summary of this revision. (Show Details)Mar 15 2023, 4:25 PM
reames accepted this revision.Mar 16 2023, 7:33 AM

LGTM

This revision is now accepted and ready to land.Mar 16 2023, 7:33 AM
This revision was landed with ongoing or failed builds.Mar 16 2023, 8:49 AM
This revision was automatically updated to reflect the committed changes.