[llvm] r286233 - [VectorLegalizer] Expansion of CTLZ using CTPOP when possible
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 8 12:21:06 PST 2016
> On 8 Nov 2016, at 19:50, Friedman, Eli <efriedma at codeaurora.org> wrote:
>
> On 11/8/2016 6:10 AM, Simon Pilgrim via llvm-commits wrote:
>> Author: rksimon
>> Date: Tue Nov 8 08:10:28 2016
>> New Revision: 286233
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=286233&view=rev
>> Log:
>> [VectorLegalizer] Expansion of CTLZ using CTPOP when possible
>>
>> This patch avoids scalarization of CTLZ by instead expanding to use CTPOP (ref: "Hacker's Delight") when the necessary operations are available.
>>
>> This also adds the necessary cost models for X86 SSE2 targets (the main beneficiary) to ensure vectorization only happens when its useful.
>>
>> Differential Revision: https://reviews.llvm.org/D25910
>>
>> Modified: llvm/trunk/test/CodeGen/X86/vec_ctbits.ll
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/vec_ctbits.ll?rev=286233&r1=286232&r2=286233&view=diff
>> ==============================================================================
>> --- llvm/trunk/test/CodeGen/X86/vec_ctbits.ll (original)
>> +++ llvm/trunk/test/CodeGen/X86/vec_ctbits.ll Tue Nov 8 08:10:28 2016
>> @@ -36,17 +36,42 @@ define <2 x i64> @footz(<2 x i64> %a) no
>> define <2 x i64> @foolz(<2 x i64> %a) nounwind {
>> ; CHECK-LABEL: foolz:
>> ; CHECK: # BB#0:
>> -; CHECK-NEXT: movd %xmm0, %rax
>> -; CHECK-NEXT: bsrq %rax, %rax
>> -; CHECK-NEXT: xorq $63, %rax
>> -; CHECK-NEXT: movd %rax, %xmm1
>> -; CHECK-NEXT: pshufd {{.*#+}} xmm0 = xmm0[2,3,0,1]
>> -; CHECK-NEXT: movd %xmm0, %rax
>> -; CHECK-NEXT: bsrq %rax, %rax
>> -; CHECK-NEXT: xorq $63, %rax
>> -; CHECK-NEXT: movd %rax, %xmm0
>> -; CHECK-NEXT: punpcklqdq {{.*#+}} xmm1 = xmm1[0],xmm0[0]
>> +; CHECK-NEXT: movdqa %xmm0, %xmm1
>> +; CHECK-NEXT: psrlq $1, %xmm1
>> +; CHECK-NEXT: por %xmm0, %xmm1
>> +; CHECK-NEXT: movdqa %xmm1, %xmm0
>> +; CHECK-NEXT: psrlq $2, %xmm0
>> +; CHECK-NEXT: por %xmm1, %xmm0
>> +; CHECK-NEXT: movdqa %xmm0, %xmm1
>> +; CHECK-NEXT: psrlq $4, %xmm1
>> +; CHECK-NEXT: por %xmm0, %xmm1
>> +; CHECK-NEXT: movdqa %xmm1, %xmm0
>> +; CHECK-NEXT: psrlq $8, %xmm0
>> +; CHECK-NEXT: por %xmm1, %xmm0
>> +; CHECK-NEXT: movdqa %xmm0, %xmm1
>> +; CHECK-NEXT: psrlq $16, %xmm1
>> +; CHECK-NEXT: por %xmm0, %xmm1
>> ; CHECK-NEXT: movdqa %xmm1, %xmm0
>> +; CHECK-NEXT: psrlq $32, %xmm0
>> +; CHECK-NEXT: por %xmm1, %xmm0
>> +; CHECK-NEXT: pcmpeqd %xmm1, %xmm1
>> +; CHECK-NEXT: pxor %xmm0, %xmm1
>> +; CHECK-NEXT: movdqa %xmm1, %xmm0
>> +; CHECK-NEXT: psrlq $1, %xmm0
>> +; CHECK-NEXT: pand {{.*}}(%rip), %xmm0
>> +; CHECK-NEXT: psubq %xmm0, %xmm1
>> +; CHECK-NEXT: movdqa {{.*#+}} xmm0 = [3689348814741910323,3689348814741910323]
>> +; CHECK-NEXT: movdqa %xmm1, %xmm2
>> +; CHECK-NEXT: pand %xmm0, %xmm2
>> +; CHECK-NEXT: psrlq $2, %xmm1
>> +; CHECK-NEXT: pand %xmm0, %xmm1
>> +; CHECK-NEXT: paddq %xmm2, %xmm1
>> +; CHECK-NEXT: movdqa %xmm1, %xmm2
>> +; CHECK-NEXT: psrlq $4, %xmm2
>> +; CHECK-NEXT: paddq %xmm1, %xmm2
>> +; CHECK-NEXT: pand {{.*}}(%rip), %xmm2
>> +; CHECK-NEXT: pxor %xmm0, %xmm0
>> +; CHECK-NEXT: psadbw %xmm2, %xmm0
>> ; CHECK-NEXT: retq
>
> This is going from 10 instructions to 35; it doesn't seem like an improvement.
The point is that this is now handled by the cost model, so we only get vectorized code when its really useful. If llc gets a request for ctlz <2 x i64> then it won’t second guess what was decided by an earlier pass.
More information about the llvm-commits
mailing list