[PATCH] [X86][SSE] Vectorized i8 and i16 shift operators

Simon Pilgrim llvm-dev at redking.me.uk
Mon May 4 08:44:55 PDT 2015


Hi qcolombet, delena, andreadb,

This patch ensures that SHL/SRL/SRA shifts for i8 and i16 vectors avoid scalarization. It builds on the existing i8 SHL vectorized implementation of moving the shift bits up to the sign bit position and separating the 4, 2 & 1 bit shifts with several improvements:

1 - SSE41 targets can use (v)pblendvb directly with the sign bit instead of performing a comparison to feed into a VSELECT node.
2 - pre-SSE41 targets were masking + comparing with an 0x80 constant - we avoid this by using the fact that a set sign bit means a negative integer which can be compared against zero to then feed into VSELECT, avoiding the need for a constant mask (zero generation is much cheaper).
3 - SRA i8 needs to be unpacked to the upper byte of a i16 so that the i16 psraw instruction can be correctly used for sign extension - we have to do more work than for SHL/SRL but perf tests indicate that this is still beneficial.

The i16 implementation is similar but simpler than for i8 - we have to do 8, 4, 2 & 1 bit shifts but less shift masking is involved. SSE41 use of (v)pblendvb requires that the i16 shift amount is splatted to both bytes however.

I've updated the vectorization costs as best as I understand them. I'd like to know whether I should be providing SSE41 and AVX1 cost tables as well as these both deviate from the SSE2 version (use of (v)pblendvb and vex-encoded independent destination registers) - there appears to be very little testing of anything other than SSE2 so some advice would be helpful here.

Tested on SSE2, SSE41 and AVX machines.

REPOSITORY
  rL LLVM

http://reviews.llvm.org/D9474

Files:
  lib/Target/X86/X86ISelLowering.cpp
  lib/Target/X86/X86TargetTransformInfo.cpp
  test/Analysis/CostModel/X86/testshiftashr.ll
  test/Analysis/CostModel/X86/testshiftlshr.ll
  test/Analysis/CostModel/X86/testshiftshl.ll
  test/CodeGen/X86/2011-12-15-vec_shift.ll
  test/CodeGen/X86/avx2-vector-shifts.ll
  test/CodeGen/X86/vec_shift8.ll

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D9474.24883.patch
Type: text/x-patch
Size: 63620 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150504/c46aa43d/attachment.bin>


More information about the llvm-commits mailing list