[llvm-bugs] [Bug 44917] New: extractelement on <8 x i2> uses xmm which is unnecessary complicated
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Feb 14 12:42:04 PST 2020
https://bugs.llvm.org/show_bug.cgi?id=44917
Bug ID: 44917
Summary: extractelement on <8 x i2> uses xmm which is
unnecessary complicated
Product: libraries
Version: 9.0
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: Backend: X86
Assignee: unassignedbugs at nondot.org
Reporter: llvm at henning-thielemann.de
CC: craig.topper at gmail.com, llvm-bugs at lists.llvm.org,
llvm-dev at redking.me.uk, spatel+llvm at rotateright.com
Extracting an element from a vector from memory with small integers generates
pretty complicated code.
Problem is that you cannot access vector elements directly from memory with
getelementptr.
Here is an example and how one would certainly implement it in an efficient
way:
$ cat extract8i2.ll
define i16 @extract_vector(i16*, i16) {
_L1:
%2 = load i16, i16* %0
%3 = bitcast i16 %2 to <8 x i2>
%4 = extractelement <8 x i2> %3, i16 %1
%5 = zext i2 %4 to i16
ret i16 %5
}
define i16 @extract_bitmanip(i16*, i16) {
_L1:
%2 = load i16, i16* %0
%shift = mul i16 2, %1
%shifted = lshr i16 %2, %shift
%masked = and i16 3, %shifted
ret i16 %masked
}
$ llc-9 -mcpu=sandybridge </tmp/extract8i2.ll
.text
.file "<stdin>"
.globl extract_vector # -- Begin function extract_vector
.p2align 4, 0x90
.type extract_vector, at function
extract_vector: # @extract_vector
.cfi_startproc
# %bb.0: # %_L1
movzwl (%rdi), %eax
movl %eax, %ecx
shrl $2, %ecx
andl $3, %ecx
movl %eax, %edx
andl $3, %edx
vmovd %edx, %xmm0
vpinsrw $1, %ecx, %xmm0, %xmm0
movl %eax, %ecx
shrl $4, %ecx
andl $3, %ecx
vpinsrw $2, %ecx, %xmm0, %xmm0
movl %eax, %ecx
shrl $6, %ecx
andl $3, %ecx
vpinsrw $3, %ecx, %xmm0, %xmm0
movl %eax, %ecx
shrl $8, %ecx
andl $3, %ecx
vpinsrw $4, %ecx, %xmm0, %xmm0
movl %eax, %ecx
shrl $10, %ecx
andl $3, %ecx
vpinsrw $5, %ecx, %xmm0, %xmm0
movl %eax, %ecx
shrl $12, %ecx
andl $3, %ecx
vpinsrw $6, %ecx, %xmm0, %xmm0
shrl $14, %eax
vpinsrw $7, %eax, %xmm0, %xmm0
# kill: def $esi killed $esi def $rsi
vmovdqa %xmm0, -24(%rsp)
andl $7, %esi
movzwl -24(%rsp,%rsi,2), %eax
retq
.Lfunc_end0:
.size extract_vector, .Lfunc_end0-extract_vector
.cfi_endproc
# -- End function
.globl extract_bitmanip # -- Begin function extract_bitmanip
.p2align 4, 0x90
.type extract_bitmanip, at function
extract_bitmanip: # @extract_bitmanip
.cfi_startproc
# %bb.0: # %_L1
# kill: def $esi killed $esi def $rsi
movzwl (%rdi), %eax
leal (%rsi,%rsi), %ecx
# kill: def $cl killed $cl killed $ecx
shrl %cl, %eax
andl $3, %eax
# kill: def $ax killed $ax killed $eax
retq
.Lfunc_end1:
.size extract_bitmanip, .Lfunc_end1-extract_bitmanip
.cfi_endproc
# -- End function
.section ".note.GNU-stack","", at progbits
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200214/ce51b703/attachment.html>
More information about the llvm-bugs
mailing list