This is an archive of the discontinued LLVM Phabricator instance.

[DAGCombiner] simplify shuffle of shuffle
ClosedPublic

Authored by spatel on Mar 28 2019, 2:36 PM.

Details

Summary

After investigating the examples from D59777 targeting an SSE4.1 machine, it looks like a very different problem due to how we map illegal types (256-bit in these cases).

We're missing a shuffle simplification that maps elements of a vector back to a shuffled operand. We have a more general version of this transform in DAGCombiner::visitVECTOR_SHUFFLE(), but that generality means it is limited to patterns with a one-use constraint, and the examples here have 2 uses. We don't need any uses or legality limitations for a simplification (no new value is created).

It looks like we miss this pattern in IR too.

In one of the zext examples here, we have shuffle masks like this:

Shuf0 = vector_shuffle<0,u,3,7,0,u,3,7>
Shuf = vector_shuffle<4,u,6,7,u,u,u,u>

...so that's moving the high half of the 1st vector into the low half. But the high half of the 1st vector is already identical to the low half.

Diff Detail

Repository
rL LLVM

Event Timeline

spatel created this revision.Mar 28 2019, 2:36 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 28 2019, 2:36 PM
RKSimon accepted this revision.Mar 29 2019, 5:09 AM

LGTM

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
17952 ↗(On Diff #192715)

e = Mask.size()?

17956 ↗(On Diff #192715)

Maybe assert that 0 <= Mask[i] && Mask[i] < e ?

17963 ↗(On Diff #192715)

Just return Shuf->getOperand(0) ?

This revision is now accepted and ready to land.Mar 29 2019, 5:09 AM
spatel marked 3 inline comments as done.Mar 29 2019, 6:55 AM
This revision was automatically updated to reflect the committed changes.