This is an archive of the discontinued LLVM Phabricator instance.

X86 ISel: Basic support for variable-index vector permutations
ClosedPublic

Authored by zvi on Oct 20 2017, 8:39 AM.

Details

Summary

Try to lower a BUILD_VECTOR composed of extract-extract chains that can be
reasoned to be a permutation of a vector by indices in a non-constant vector.

We saw this pattern created by ISPC, which resolts to creating it due to the
requirement that shufflevector's mask operand be a *constant* vector.
I didn't check this but we could possibly use this pattern for lowering the X86 permute
C-instrinsics instead of llvm.x86 instrinsics.

This change can be followed by more improvements:

  1. Handle vectors with undef elements.
  2. Utilize pshufb and zero-mask-blending to support more effiecient construction of vectors with constant-0 elements.
  3. Use smaller-element vectors of same width, and "interpolate" the indices, when no native operation available.

Diff Detail

Repository
rL LLVM

Event Timeline

zvi created this revision.Oct 20 2017, 8:39 AM
RKSimon edited edge metadata.Oct 30 2017, 5:08 AM

Why no float/double support?

zvi updated this revision to Diff 120887.Oct 30 2017, 2:20 PM

Add support for floating-point types.

RKSimon added inline comments.Nov 1 2017, 12:08 PM
lib/Target/X86/X86ISelLowering.cpp
7719 ↗(On Diff #120887)

efficient

7726 ↗(On Diff #120887)

(style) Full stops at the end of comments.

7777 ↗(On Diff #120887)

Is it worth putting all this code above the switch statement? As soon as you want to start adding more cases you're going to have to know more details of the source vectors/indices to determine whether the subtarget supports them.

7788 ↗(On Diff #120887)

You can probably pull the '0th idx' code above into the for loop quite easily, it'd also make future support for UNDEF/ZERO elements easier.

zvi updated this revision to Diff 121398.Nov 2 2017, 3:37 PM

Follow Simon's suggestion to pull the oth index scan into the loop.
Fix typo + style defects.

RKSimon accepted this revision.Nov 5 2017, 5:00 AM

LGTM with one minor comment

lib/Target/X86/X86ISelLowering.cpp
7802 ↗(On Diff #121398)

Probably clearer to just do something like:

SDValue ExtrIndices = ExtractedIndex.getOperand(0);
if (V && V != ExtrIndices)
  return SDValue();
V = ExtrIndices;
This revision is now accepted and ready to land.Nov 5 2017, 5:00 AM
zvi updated this revision to Diff 121688.Nov 6 2017, 12:25 AM

Last minute changes in the spirit of Simon's suggestion

This revision was automatically updated to reflect the committed changes.