<div dir="auto">If you're using clang you could try to see if it emits any hints about optimizations using the remarks: <div dir="auto"><br></div><div dir="auto"><a href="https://clang.llvm.org/docs/UsersManual.html#options-to-emit-optimization-reports">https://clang.llvm.org/docs/UsersManual.html#options-to-emit-optimization-reports</a></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Aug 31, 2020, 4:43 PM Alexandre Bique via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
After reading <a href="https://llvm.org/docs/Vectorizers.html#vectorization-of-function-calls" rel="noreferrer noreferrer" target="_blank">https://llvm.org/docs/Vectorizers.html#vectorization-of-function-calls</a><br>
I decided to write the following C++ program:<br>
<br>
#include <cmath><br>
<br>
using v4f32 = float __attribute__((__vector_size__(16)));<br>
<br>
v4f32 fct1(v4f32 x)<br>
{<br>
v4f32 y;<br>
y[0] = std::sin(x[0]);<br>
y[1] = std::sin(x[1]);<br>
y[2] = std::sin(x[2]);<br>
y[3] = std::sin(x[3]);<br>
return y;<br>
}<br>
<br>
v4f32 fct2(v4f32 x)<br>
{<br>
v4f32 y;<br>
for (int i = 0; i < 4; ++i)<br>
y[i] = std::sin(x[i]);<br>
return y;<br>
}<br>
<br>
void fct3(float *x)<br>
{<br>
#pragma clang loop vectorize(enable)<br>
for (int i = 0; i < 16; ++i)<br>
x[i] = sinf(x[i]);<br>
}<br>
<br>
Which I compiled with: clang++ -O3 -march=native -mtune=native -c -o<br>
vec.o vec.cc -lmvec -fno-math-errno<br>
<br>
And here is what I get:<br>
<br>
vec.o: file format elf64-x86-64<br>
<br>
<br>
Disassembly of section .text:<br>
<br>
0000000000000000 <_Z4fct1Dv4_f>:<br>
0: 48 83 ec 48 sub $0x48,%rsp<br>
4: c5 f8 29 04 24 vmovaps %xmm0,(%rsp)<br>
9: e8 00 00 00 00 callq e <_Z4fct1Dv4_f+0xe><br>
e: c5 f8 29 44 24 30 vmovaps %xmm0,0x30(%rsp)<br>
14: c5 fa 16 04 24 vmovshdup (%rsp),%xmm0<br>
19: e8 00 00 00 00 callq 1e <_Z4fct1Dv4_f+0x1e><br>
1e: c5 f8 29 44 24 20 vmovaps %xmm0,0x20(%rsp)<br>
24: c4 e3 79 05 04 24 01 vpermilpd $0x1,(%rsp),%xmm0<br>
2b: e8 00 00 00 00 callq 30 <_Z4fct1Dv4_f+0x30><br>
30: c5 f9 29 44 24 10 vmovapd %xmm0,0x10(%rsp)<br>
36: c4 e3 79 04 04 24 e7 vpermilps $0xe7,(%rsp),%xmm0<br>
3d: e8 00 00 00 00 callq 42 <_Z4fct1Dv4_f+0x42><br>
42: c5 f8 28 4c 24 30 vmovaps 0x30(%rsp),%xmm1<br>
48: c4 e3 71 21 4c 24 20 vinsertps $0x10,0x20(%rsp),%xmm1,%xmm1<br>
4f: 10<br>
50: c4 e3 71 21 4c 24 10 vinsertps $0x20,0x10(%rsp),%xmm1,%xmm1<br>
57: 20<br>
58: c4 e3 71 21 c0 30 vinsertps $0x30,%xmm0,%xmm1,%xmm0<br>
5e: 48 83 c4 48 add $0x48,%rsp<br>
62: c3 retq<br>
63: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)<br>
6a: 00 00 00<br>
6d: 0f 1f 00 nopl (%rax)<br>
<br>
0000000000000070 <_Z4fct2Dv4_f>:<br>
70: 48 83 ec 48 sub $0x48,%rsp<br>
74: c5 f8 29 04 24 vmovaps %xmm0,(%rsp)<br>
79: e8 00 00 00 00 callq 7e <_Z4fct2Dv4_f+0xe><br>
7e: c5 f8 29 44 24 30 vmovaps %xmm0,0x30(%rsp)<br>
84: c5 fa 16 04 24 vmovshdup (%rsp),%xmm0<br>
89: e8 00 00 00 00 callq 8e <_Z4fct2Dv4_f+0x1e><br>
8e: c5 f8 29 44 24 20 vmovaps %xmm0,0x20(%rsp)<br>
94: c4 e3 79 05 04 24 01 vpermilpd $0x1,(%rsp),%xmm0<br>
9b: e8 00 00 00 00 callq a0 <_Z4fct2Dv4_f+0x30><br>
a0: c5 f9 29 44 24 10 vmovapd %xmm0,0x10(%rsp)<br>
a6: c4 e3 79 04 04 24 e7 vpermilps $0xe7,(%rsp),%xmm0<br>
ad: e8 00 00 00 00 callq b2 <_Z4fct2Dv4_f+0x42><br>
b2: c5 f8 28 4c 24 30 vmovaps 0x30(%rsp),%xmm1<br>
b8: c4 e3 71 21 4c 24 20 vinsertps $0x10,0x20(%rsp),%xmm1,%xmm1<br>
bf: 10<br>
c0: c4 e3 71 21 4c 24 10 vinsertps $0x20,0x10(%rsp),%xmm1,%xmm1<br>
c7: 20<br>
c8: c4 e3 71 21 c0 30 vinsertps $0x30,%xmm0,%xmm1,%xmm0<br>
ce: 48 83 c4 48 add $0x48,%rsp<br>
d2: c3 retq<br>
d3: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)<br>
da: 00 00 00<br>
dd: 0f 1f 00 nopl (%rax)<br>
<br>
00000000000000e0 <_Z4fct3Pf>:<br>
e0: 53 push %rbx<br>
e1: 48 83 ec 10 sub $0x10,%rsp<br>
e5: 48 89 fb mov %rdi,%rbx<br>
e8: c5 fa 10 07 vmovss (%rdi),%xmm0<br>
ec: c5 fa 10 4f 04 vmovss 0x4(%rdi),%xmm1<br>
f1: c5 fa 11 4c 24 0c vmovss %xmm1,0xc(%rsp)<br>
f7: e8 00 00 00 00 callq fc <_Z4fct3Pf+0x1c><br>
fc: c5 fa 11 03 vmovss %xmm0,(%rbx)<br>
100: c5 fa 10 44 24 0c vmovss 0xc(%rsp),%xmm0<br>
106: e8 00 00 00 00 callq 10b <_Z4fct3Pf+0x2b><br>
10b: c5 fa 11 43 04 vmovss %xmm0,0x4(%rbx)<br>
110: c5 fa 10 43 08 vmovss 0x8(%rbx),%xmm0<br>
115: e8 00 00 00 00 callq 11a <_Z4fct3Pf+0x3a><br>
11a: c5 fa 11 43 08 vmovss %xmm0,0x8(%rbx)<br>
11f: c5 fa 10 43 0c vmovss 0xc(%rbx),%xmm0<br>
124: e8 00 00 00 00 callq 129 <_Z4fct3Pf+0x49><br>
129: c5 fa 11 43 0c vmovss %xmm0,0xc(%rbx)<br>
12e: c5 fa 10 43 10 vmovss 0x10(%rbx),%xmm0<br>
133: e8 00 00 00 00 callq 138 <_Z4fct3Pf+0x58><br>
138: c5 fa 11 43 10 vmovss %xmm0,0x10(%rbx)<br>
13d: c5 fa 10 43 14 vmovss 0x14(%rbx),%xmm0<br>
142: e8 00 00 00 00 callq 147 <_Z4fct3Pf+0x67><br>
147: c5 fa 11 43 14 vmovss %xmm0,0x14(%rbx)<br>
14c: c5 fa 10 43 18 vmovss 0x18(%rbx),%xmm0<br>
151: e8 00 00 00 00 callq 156 <_Z4fct3Pf+0x76><br>
156: c5 fa 11 43 18 vmovss %xmm0,0x18(%rbx)<br>
15b: c5 fa 10 43 1c vmovss 0x1c(%rbx),%xmm0<br>
160: e8 00 00 00 00 callq 165 <_Z4fct3Pf+0x85><br>
165: c5 fa 11 43 1c vmovss %xmm0,0x1c(%rbx)<br>
16a: c5 fa 10 43 20 vmovss 0x20(%rbx),%xmm0<br>
16f: e8 00 00 00 00 callq 174 <_Z4fct3Pf+0x94><br>
174: c5 fa 11 43 20 vmovss %xmm0,0x20(%rbx)<br>
179: c5 fa 10 43 24 vmovss 0x24(%rbx),%xmm0<br>
17e: e8 00 00 00 00 callq 183 <_Z4fct3Pf+0xa3><br>
183: c5 fa 11 43 24 vmovss %xmm0,0x24(%rbx)<br>
188: c5 fa 10 43 28 vmovss 0x28(%rbx),%xmm0<br>
18d: e8 00 00 00 00 callq 192 <_Z4fct3Pf+0xb2><br>
192: c5 fa 11 43 28 vmovss %xmm0,0x28(%rbx)<br>
197: c5 fa 10 43 2c vmovss 0x2c(%rbx),%xmm0<br>
19c: e8 00 00 00 00 callq 1a1 <_Z4fct3Pf+0xc1><br>
1a1: c5 fa 11 43 2c vmovss %xmm0,0x2c(%rbx)<br>
1a6: c5 fa 10 43 30 vmovss 0x30(%rbx),%xmm0<br>
1ab: e8 00 00 00 00 callq 1b0 <_Z4fct3Pf+0xd0><br>
1b0: c5 fa 11 43 30 vmovss %xmm0,0x30(%rbx)<br>
1b5: c5 fa 10 43 34 vmovss 0x34(%rbx),%xmm0<br>
1ba: e8 00 00 00 00 callq 1bf <_Z4fct3Pf+0xdf><br>
1bf: c5 fa 11 43 34 vmovss %xmm0,0x34(%rbx)<br>
1c4: c5 fa 10 43 38 vmovss 0x38(%rbx),%xmm0<br>
1c9: e8 00 00 00 00 callq 1ce <_Z4fct3Pf+0xee><br>
1ce: c5 fa 11 43 38 vmovss %xmm0,0x38(%rbx)<br>
1d3: c5 fa 10 43 3c vmovss 0x3c(%rbx),%xmm0<br>
1d8: e8 00 00 00 00 callq 1dd <_Z4fct3Pf+0xfd><br>
1dd: c5 fa 11 43 3c vmovss %xmm0,0x3c(%rbx)<br>
1e2: 48 83 c4 10 add $0x10,%rsp<br>
1e6: 5b pop %rbx<br>
1e7: c3 retq<br>
<br>
As you can see there is no call to a vectorized version of sin.<br>
Did I do something wrong?<br>
<br>
By the way I am on Linux with glibc 2.32 which has libmvec.<br>
<br>
Regards,<br>
-- <br>
Alexandre Bique<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" rel="noreferrer">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>