This is an archive of the discontinued LLVM Phabricator instance.

[X86, AVX] recognize shufflevector with zero input as a vperm2 (PR22984)
ClosedPublic

Authored by spatel on Mar 23 2015, 1:29 PM.

Details

Summary

vperm2x128 instructions have the special ability (aka free hardware capability) to shuffle zero values into a vector.

This patch recognizes that type of shuffle and generates the appropriate control byte.

Note: I have a follow-on patch to convert vperm2 intrinsics with zero masks into generic shuffles. That should close the loop on this special-purpose x86 permute.

https://llvm.org/bugs/show_bug.cgi?id=22984

Diff Detail

Repository
rL LLVM

Event Timeline

spatel updated this revision to Diff 22511.Mar 23 2015, 1:29 PM
spatel retitled this revision from to [X86, AVX] recognize shufflevector with zero input as a vperm2 (PR22984).
spatel updated this object.
spatel edited the test plan for this revision. (Show Details)
spatel added reviewers: mkuper, andreadb, RKSimon, chandlerc.
spatel added a subscriber: Unknown Object (MLST).

Forgot to mention - the codegen difference looks like this:

vxorps	        %ymm1, %ymm1, %ymm1
vinsertf128	$1, %xmm0, %ymm1, %ymm0

becomes:

vperm2f128      $40, %ymm0, %ymm0, %ymm0

Or this:

vxorps	        %ymm1, %ymm1, %ymm1
vperm2f128      $33, %ymm1, %ymm0, %ymm0

becomes:

vperm2f128      $129, %ymm0, %ymm0, %ymm0

I didn't include negative test cases because I think those are thoroughly covered by existing tests for vinsertf128, vblend, and vperm2f128.

spatel added inline comments.Mar 24 2015, 10:54 AM
lib/Target/X86/X86ISelLowering.cpp
9081 ↗(On Diff #22511)

Note: This mask {0, 1, 6, 7} is a v4x64 blend, but we've already tried "lowerVectorShuffleAsBlend()" above. Therefore, this check is redundant, and I've removed it. There was no change in the regression tests after removing this check.

andreadb edited edge metadata.Mar 24 2015, 10:59 AM

Hi Sanjay,

The patch LGTM. Thanks!

lib/Target/X86/X86ISelLowering.cpp
9081 ↗(On Diff #22511)

Thanks for clarifying it. That was my only concern about this patch.

andreadb accepted this revision.Mar 24 2015, 10:59 AM
andreadb edited edge metadata.
This revision is now accepted and ready to land.Mar 24 2015, 10:59 AM
This revision was automatically updated to reflect the committed changes.