<div dir="ltr">Thanks Christian!<div><br></div><div>That explains it, I was pretty sure it had to be something in that direction.</div><div><br></div><div>Best</div><div>Martin</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Am Do., 17. Aug. 2023 um 15:31 Uhr schrieb Christian Hagedorn <<a href="mailto:christian.hagedorn@oracle.com">christian.hagedorn@oracle.com</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Martin<br>
<br>
-XX:-UseSuperWord will turn off auto-vectorization. What you are observing is<br>
that for some instructions like adding two floats (AddFNode), we directly emit<br>
some vector instructions if the AVX instructions are available. This is done<br>
independently of auto-vectorization.<br>
<br>
AddFNode is matched with the addF_reg_mem rule which emits vaddss:<br>
<a href="https://github.com/openjdk/jdk/blob/c634bdf9d917c96c38efe826239eab7900c33e74/src/hotspot/cpu/x86/x86.ad#L2987-L2997" rel="noreferrer" target="_blank">https://github.com/openjdk/jdk/blob/c634bdf9d917c96c38efe826239eab7900c33e74/src/hotspot/cpu/x86/x86.ad#L2987-L2997</a><br>
<br>
For example, this code:<br>
<br>
    static float test() {<br>
        return floatFlield + 3.4f;<br>
    }<br>
<br>
will be compiled to (if UseAVX > 0):<br>
<br>
  vmovss -0x4c(%rip),%xmm1        # 0x00007fca3c5b1aa0<br>
  vaddss 0x70(%r10),%xmm1,%xmm0   ;*fadd {reexecute=0 rethrow=0 return_oop=0}<br>
<br>
<br>
So, even if you turn off auto-vectorization, C2 will still emit vector<br>
instructions for some code.<br>
<br>
Best regards,<br>
Christian<br>
<br>
<br>
On 17.08.23 15:00, Martin Stypinski wrote:<br>
> I am benchmarking some algorithms, wondering how much the JIT applies<br>
> auto-vectorization. I set up a JMH project and am trying to turn<br>
> auto-vectorization off.<br>
> <br>
> <br>
> The code snipped, and the results can be found in the following<br>
> gist: <a href="https://gist.github.com/Styp/16e8a20fedfb771107377407fc1cf210" rel="noreferrer" target="_blank">https://gist.github.com/Styp/16e8a20fedfb771107377407fc1cf210</a><br>
> <<a href="https://gist.github.com/Styp/16e8a20fedfb771107377407fc1cf210" rel="noreferrer" target="_blank">https://gist.github.com/Styp/16e8a20fedfb771107377407fc1cf210</a>> (Sorry too long<br>
> to post here).<br>
> <br>
> <br>
> The results indicate that one is faster than the other, which is expected.<br>
> Nevertheless, the deviation is so high that the benchmark is not representative.<br>
> What irritates me the most is that the version with turned of SuperWord still<br>
> contains vadd and vmove instructions in the Jit-generated code. Do I miss<br>
> something? How can I enforce vectorization turned off for good?<br>
> <br>
> Any ideas? <br>
> <br>
</blockquote></div>