<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/94025>94025</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
AVX-512 mask registers spill to stack when GPRs are available
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
embg
</td>
</tr>
</table>
<pre>
I hit some cases where LLVM spills mask registers to the stack in memory-bound code, where extra loads and stores to the stack are quite expensive. Some of these spills may be avoidable through better scheduling, but I think improving the performance of the spills (when unavoidable) would also be useful.
I noticed that GCC spills these registers to GPRs -- could LLVM do the same?
Here is a minimal example:
* clang spills mask registers to the stack: https://godbolt.org/z/e9nGb6z8s
* gcc spills mask registers to GPRs: https://godbolt.org/z/h46cdje7a
Here is a more realistic scenario, where better scheduling could theoretically eliminate the spills (but doesn't): https://godbolt.org/z/Pz1dsrh53
For the realistic scenario, I also observed that GCC spills to GPRs, while LLVM spills to the stack.
I chatted offline with @MatzeB, who indicated that this would probably require a lot of work in the register allocator. I understand if the gains aren't large enough to justify this work. But I still thought it might be useful to share this data point with the community.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVMFu2zgQ_Rr6MrAhU1ZsHXRIUjgboAWKXaDY64gai5NQpEuO7Dpfv6DsNKm3BXKxDZjz3syb9wZT4t4TNaq6U9WnGY5iQ2xoaPtZG7pT8wiWBVIYCAwmSnC0FAk-f_72BdKenUswYHqGSD0noZhAAoglSILmGdjDQEOIp3kbRt-BCR0pfX9BoR8SEVzALgH6DpKESFcIGAm-jyz59Z584gMt4J_cT9jlZ4ne-jhBS4CHwB22jkBsDGNvoSURipCMpW507PvcQTsKPIJY9s_Awz6GA_t-4t1T3IU4oDevHK8MSm-OljyM_ieJ0jUcw-g6QJdC5h8T7Ua3UMUnVdyePx_BB2FDHYhFgYf7-1fE8wC_iPfw9e8E8zmYCXUSursIggOpc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