https://bugs.llvm.org/show_bug.cgi?id=44565
Bug ID: 44565
Summary: [X86] Failure to use MOVMSK reduction result for
branches
Product: libraries
Version: trunk
Hardware: PC
OS: Windows NT
Status: NEW
Severity: enhancement
Priority: P
Component: Backend: X86
Assignee: unassignedb...@nondot.org
Reporter: llvm-...@redking.me.uk
CC: craig.top...@gmail.com, llvm-bugs@lists.llvm.org,
llvm-...@redking.me.uk, spatel+l...@rotateright.com
https://godbolt.org/z/GLDirF
If we are selecting between 2 values using a comparison reduction then we use
the all_of/any_of MOVMSK result directly:
define i32 @select(<2 x double> %a0) {
%1 = fcmp ogt <2 x double> %a0, zeroinitializer
%2 = extractelement <2 x i1> %1, i32 0
%3 = extractelement <2 x i1> %1, i32 1
%4 = and i1 %2, %3
%5 = select i1 %4, i32 42, i32 88
ret i32 %5
}
select: # @select
vxorpd %xmm1, %xmm1, %xmm1
vcmpltpd %xmm0, %xmm1, %xmm0
vmovmskpd %xmm0, %eax
cmpb $3, %al
movl $42, %ecx
movl $88, %eax
cmovel %ecx, %eax
retq
But if we decided to create a branch instead then the MOVMSK bits are used
separately, meaning we end up with 2 compares+jmps instead:
define i32 @jmp(<2 x double> %a0) {
%1 = fcmp ogt <2 x double> %a0, zeroinitializer
%2 = extractelement <2 x i1> %1, i32 0
%3 = extractelement <2 x i1> %1, i32 1
%4 = and i1 %2, %3
br i1 %4, label %foo, label %bar
foo:
ret i32 42
bar:
ret i32 88
}
jmp: # @jmp
vxorpd %xmm1, %xmm1, %xmm1
vcmpltpd %xmm0, %xmm1, %xmm0
vmovmskpd %xmm0, %eax
testb $1, %al
je .LBB1_3
shrb %al
je .LBB1_3
movl $42, %eax
retq
.LBB1_3: # %bar
movl $88, %eax
retq
when I think it could be:
jmp: # @jmp
vxorpd %xmm1, %xmm1, %xmm1
vcmpltpd %xmm0, %xmm1, %xmm0
vmovmskpd %xmm0, %eax
cmp $3, %al
jne .LBB1_3
movl $42, %eax
retq
.LBB1_3: # %bar
movl $88, %eax
retq
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs