[PATCH][X86] Teach the backend how to lower vector shift left into multiply rather than scalarizing it.

Andrea Di Biagio andrea.dibiagio at gmail.com
Thu Feb 6 15:11:29 PST 2014


Hi Jim and Nadav,

thanks for the feedback!

On Thu, Feb 6, 2014 at 10:33 PM, Nadav Rotem <nrotem at apple.com> wrote:
> Please remember to update the x86 cost model in  X86TTI::getArithmeticInstrCost.  In this function you should be able to check if the LHS is a constant.

Ok, I will update the cost model.

> On Feb 6, 2014, at 2:26 PM, Jim Grosbach <grosbach at apple.com> wrote:
>
>> Hi Andrea,
>>
>> This is a very nice improvement, but should do a bit more, I believe.
>>
>> AVX2 adds 256-bit wide vector versions of these instructions, so if AVX2 is available, the same transformation should be applied to v16i16 and v8i32 shifts. Worth looking to see if AVX512 extends
>>
>> The test cases should check that when compiling for AVX, the VEX prefixed form of the instructions are generated instead of the SSE versions.
>>

Sure, I will send a new version of the patch that also improves AVX2
code generation in the case of v16i16 and v8i32. I'll also have a look
at AVX512 to identify cases that can also be improved.

On my previous email I forgot to mention that this patch would also
fix bug 18478 (http://llvm.org/bugs/show_bug.cgi?id=18478)

Thanks again for your time.
Andrea

>
>>> Hi,
>>>
>>> This patch teaches the backend how to efficiently lower a packed
>>> vector shift left into a packed vector multiply if the vector of shift
>>> counts is known to be constant (i.e. a constant build_vector).
>>>
>>> Instead of expanding a packed shift into a sequence of scalar shifts,
>>> the backend should try (when possible) to convert the vector shift
>>> into a vector multiply.
>>>
>>> Before this patch, a shift of a MVT::v8i16 vector by a build_vector of
>>> constants was always scalarized into a long sequence of "vector
>>> extracts + scalar shifts + vector insert".
>>> With this patch, if there is SSE2 support, we emit a single vector multiply.
>>>
>>> The new x86 test 'vec_shift6.ll' contains some examples of code that
>>> are affected by this patch.
>>>
>>> Please let me know if ok to submit.
>>>
>>> Thanks,
>>> Andrea Di Biagio
>>> SN Systems - Sony Computer Entertainment Group
>>> <patch.diff>_______________________________________________
>>> llvm-commits mailing list
>>> llvm-commits at cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>
>



More information about the llvm-commits mailing list