This is an archive of the discontinued LLVM Phabricator instance.

[DAGCombine] Permit combining of shuffle of equivalent splat BUILD_VECTORs
ClosedPublic

Authored by RKSimon on Oct 9 2017, 11:16 AM.

Details

Summary

combineShuffleOfScalars is very conservative about shuffled BUILD_VECTOsR that can be combined together.

I'd like to add one additional case - if both BUILD_VECTORs represent splats of the same scalar value but with different UNDEF elements, then we should create a single splat BUILD_VECTOR, sharing only the common UNDEF elements.

Diff Detail

Repository
rL LLVM

Event Timeline

RKSimon created this revision.Oct 9 2017, 11:16 AM
spatel added inline comments.Oct 12 2017, 9:48 AM
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
15492–15493 ↗(On Diff #118239)

Is this more conservative than necessary? If the shuffle mask is choosing an undef lane from either input, then the output would still be undef?

RKSimon added inline comments.Oct 12 2017, 11:42 AM
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
15492–15493 ↗(On Diff #118239)

Agreed, I started trying to integrate this into the existing code below but I gave up as it was getting very convoluted. I'll update the code so that it just finds a single splat value.

andreadb added inline comments.Oct 12 2017, 11:44 AM
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
15467–15470 ↗(On Diff #118239)

This comment can be updated.
Your change would allow duplicate non-constant values in the resulting build vector if shuffle operands are both splat of the same value.

15494–15500 ↗(On Diff #118239)

Instead of conservatively merging common undef elements, have you considered the possibility of reusing the loop at line 15512?

You can use the code from your patch at lines [15494,15500] to match your particular shuffle(splat,splat) pattern.
Then you can slightly modify the check at line 15532 , so that the restriction on non-constant duplicate values is not applied to your particular case.

RKSimon updated this revision to Diff 119352.Oct 17 2017, 10:58 AM
RKSimon added a reviewer: andreadb.
RKSimon removed a subscriber: andreadb.

Updated to reuse more of the existing BUILD_VECTOR code.

andreadb accepted this revision.Oct 23 2017, 6:16 AM

LGTM.
Thanks Simon!

This revision is now accepted and ready to land.Oct 23 2017, 6:16 AM
This revision was automatically updated to reflect the committed changes.