[llvm-bugs] [Bug 50920] New: Poor handling of float3 within a float4 type
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Jun 28 03:13:24 PDT 2021
https://bugs.llvm.org/show_bug.cgi?id=50920
Bug ID: 50920
Summary: Poor handling of float3 within a float4 type
Product: libraries
Version: trunk
Hardware: PC
OS: Windows NT
Status: NEW
Severity: enhancement
Priority: P
Component: Common Code Generator Code
Assignee: unassignedbugs at nondot.org
Reporter: llvm-dev at redking.me.uk
CC: a.bataev at hotmail.com, llvm-bugs at lists.llvm.org,
spatel+llvm at rotateright.com
https://godbolt.org/z/7jxnGdd7d
#include <cstdint>
#include <cfloat>
#include <x86intrin.h>
__m128 invert_float3(__m128 x) {
for (int i = 0; i != 3; ++i) {
x[i] = x[i] == 0 ? FLT_MAX : 1.0 / x[i];
}
return x;
}
define <4 x float> @invert_float3(<4 x float> %0) {
%2 = extractelement <4 x float> %0, i32 0
%3 = fcmp oeq float %2, 0.000000e+00
%4 = fdiv float 1.000000e+00, %2
%5 = select i1 %3, float 0x47EFFFFFE0000000, float %4
%6 = shufflevector <4 x float> %0, <4 x float> undef, <2 x i32> <i32 1, i32
2>
%7 = fcmp oeq <2 x float> %6, zeroinitializer
%8 = fdiv <2 x float> <float 1.000000e+00, float 1.000000e+00>, %6
%9 = select <2 x i1> %7, <2 x float> <float 0x47EFFFFFE0000000, float
0x47EFFFFFE0000000>, <2 x float> %8
%10 = insertelement <4 x float> %0, float %5, i32 0
%11 = shufflevector <2 x float> %9, <2 x float> poison, <4 x i32> <i32 0, i32
1, i32 undef, i32 undef>
%12 = shufflevector <4 x float> %10, <4 x float> %11, <4 x i32> <i32 0, i32
4, i32 5, i32 3>
ret <4 x float> %12
}
invert_float3(float __vector(4)):
vxorps %xmm1, %xmm1, %xmm1
vucomiss %xmm1, %xmm0
jne .LBB0_2
jp .LBB0_2
vmovss .LCPI0_0(%rip), %xmm1 # xmm1 = mem[0],zero,zero,zero
jmp .LBB0_3
.LBB0_2:
vmovss .LCPI0_1(%rip), %xmm1 # xmm1 = mem[0],zero,zero,zero
vdivss %xmm0, %xmm1, %xmm1
.LBB0_3:
vmovaps .LCPI0_2(%rip), %xmm4 # xmm4 = <1.0E+0,1.0E+0,u,u>
vpermilps $233, %xmm0, %xmm2 # xmm2 = xmm0[1,2,2,3]
vxorps %xmm3, %xmm3, %xmm3
vblendps $3, %xmm1, %xmm0, %xmm0 # xmm0 =
xmm1[0,1],xmm0[2,3]
vcmpeqps %xmm3, %xmm2, %xmm3
vdivps %xmm2, %xmm4, %xmm2
vblendvps %xmm3, .LCPI0_3(%rip), %xmm2, %xmm2
vshufps $76, %xmm2, %xmm0, %xmm0 # xmm0 = xmm0[0,3],xmm2[0,1]
vpermilps $120, %xmm0, %xmm0 # xmm0 = xmm0[0,2,3,1]
retq
Many vector math libraries embed float3 vectors inside a float4 register
vector, and just ignore the [3] element. For instance, in this safe fdiv code,
only the first 3 elements are inverted.
I'm hoping that D57059 will help with this, and ideally will generate a <float
x 3> pattern that blends with the [3] pass-through value.
--
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/20210628/f8ff2387/attachment.html>
More information about the llvm-bugs
mailing list