[PATCH][X86] Optimize shifting of result of a vector-compare

Adam Nemet anemet at apple.com
Fri Feb 21 15:12:20 PST 2014


On Feb 20, 2014, at 8:13 PM, Adam Nemet <anemet at apple.com> wrote:

> On Feb 18, 2014, at 4:44 PM, Adam Nemet <anemet at apple.com> wrote:
> 
>> This change is motivated by the benchmark in SingleSource/Benchmarks/Misc/lowercase.c.
>> 
>>            pcmpgtw %xmm3, %xmm2
>>            pand    %xmm7, %xmm2      // xmm7 is <1, 1, 1, 1, 1, 1, 1, 1>
>>            psllw   $5, %xmm2
>> 
>> PCMP* sets its result to all ones or zeros so we can AND with the shifted mask rather than masking and shifting separately.
>> 
>> The patch adds this transformation to the DAGCombiner:
>> 
>>  (shl (and (setcc:i8v16 ...) N01C) N1C) -> (and (setcc:i8v16 ...) N01C<<N1C)
>> 
>> This is a similar transformation that is already done for sign-extending the result of setcc for targets where boolean values are either zero or all-ones.
>> 
>> If the patch looks good, please apply.
> 
> Quentin pointed out offline that a BuildVector is not necessarily constant.  This new version adds some extra checks to guarantee that.  Retested on x86_64-apple-darwin.

Even BuildVectors that return true in isConstant can have undef elements. In this case constant-folding returns NULL so my new assert triggers.  Function bar in the test case is an example.

In this new version, I bail if constant-folding failed, i.e. when the const vector has an undef element.

Retested as before.

Adam

-------------- next part --------------
A non-text attachment was scrubbed...
Name: redundant-psll-4.patch
Type: application/octet-stream
Size: 2465 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140221/63d124ec/attachment.obj>


More information about the llvm-commits mailing list