inefficient code for 128bit int comparison comparison with sse41
| Bugzilla Link | 12312 |
| Resolution | FIXED |
| Resolved on | Oct 19, 2012 14:02 |
| Version | trunk |
| OS | Linux |
| Reporter | LLVM Bugzilla Contributor |
| CC | @d0k,@lattner,@topperc,@darkbuck |
Extended Description
llvm always seems to extract the largest possible elements (i.e. quadword on x86-64, dword otherwise) and do the comparison on the int stack even if that's completely unnecessary.
This snippet
define i32 @veccond(<4 x i32> %input) { entry: %0 = bitcast <4 x i32> %input to i128 %1 = icmp ne i128 %0, 0 br i1 %1, label %if-true-block, label %endif-block
if-true-block: ; preds = %entry ret i32 0 endif-block: ; preds = %entry, %if-true-block ret i32 1 }
compiles to
pextrq $1, %xmm0, %rax
movd %xmm0, %rcx
orq %rax, %rcx
je .LBB0_2
BB#1: # %if-true-block
xorl %eax, %eax
ret
.LBB0_2: # %endif-block movl $1, %eax ret
(looks much worse with 32bit arch and/or 256bit int for obvious reasons though I didn't actually test the latter yet)
This looks like a near ideal case for PTEST to me, i.e. something like
ptest %xmm0, %xmm0
je .LBB0_2
etc.
should be much better.
The example compiles into ptest now.
patch fixing this issue is submitted for review
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20120730/147467.html http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20120730/147468.html
please review them when you have chance