<div dir="ltr">On Thu, Sep 19, 2013 at 11:53 AM, Gao, Yunzhong <span dir="ltr"><<a href="mailto:yunzhong_gao@playstation.sony.com" target="_blank">yunzhong_gao@playstation.sony.com</a>></span> wrote:<br><div class="gmail_extra">

<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all,<br>
<br>
I would like to make a proposal about changing the optimization strategy<br>
regarding when to insert a vzeroupper instruction in the x86 backend.<br>
<br>
Current implementation:<br>
vzeroupper is inserted to any functions that use AVX instructions. The<br>
insertion points are:<br>
1) before a call instruction;<br>
2) before a return instruction;<br>
<br>
Rationale:<br>
vzeroupper is an AVX instruction; it is inserted to avoid performance penalty<br>
when switching between x86 AVX mode and SSE mode, e.g., when an AVX function<br>
calls a SSE function.<br>
<br>
My proposal:<br>
Default to not insert vzeroupper instruction unless a function is using legacy<br>
SSE instructions. By a legacy SSE instruction, I mean any vector instructions<br>
that do not have a v- prefix, write XMM register but not YMM register. If a<br>
legacy SSE instruction is spotted, then insert a vzeroupper instruction:<br>
1) before a call instruction;<br>
2) before a return instruction;<br></blockquote><div><br></div><div>This is essentially equivalent to "don't insert vzeroupper anywhere", as far as I can tell.  (The case of SSE instructions without a v- prefixed equivalent is rare enough we can separate it from this discussion.)</div>

<div><br></div><div>The reason we need vzeroupper in the first place is because we can't assume other functions won't use legacy SSE instructions; for example, on most systems, calling sin() will use legacy SSE instructions.  I mean, if you can make some unusual guarantee about your platform, it might make sense to disable vzeroupper generation in general, but it simply doesn't make sense on most platforms.</div>
<div><br></div><div>If you want a mechanism to disable vzeroupper generation for particular function calls, that might make sense...</div>
<div><br></div><div>-Eli</div></div></div></div>