<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/96146>96146</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
AArch64 Miscompile with RegUnits-based MachineLICM liveness calculation
</td>
</tr>
<tr>
<th>Labels</th>
<td>
backend:AArch64,
llvm:codegen,
miscompilation
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Pierre-vh
</td>
</tr>
</table>
<pre>
After https://github.com/llvm/llvm-project/pull/94608 and https://github.com/llvm/llvm-project/pull/95746, some code can miscompile in AArch64 because Qn and Dn registers both only have Bn registers as their regunits, and nothing else.
This means that the when a regmask marks Dn as being preserved across a call, Qn is also preserved if we analyze liveness using register units. It's actually not preserved and it's the source of the miscompile.
The easy solution would be to just revert the patches, but I would like to avoid that outcome as RU-based liveness analysis is much faster, and MachineLICM was extremely expensive on AMDGPU prior to these patches due to how it used RegAliasIterator intensively.
I would like to first discuss other possibilities to sort this out. Ideally, Q registers would have something to represent the upper 64 bits that can be lost.
One option would be to add a fake high 64 register in TableGen that can't be selected by regalloc. Another option, which I tried in this branch, is to add another regunit to Q registers, but it seems to cause a lot of changes in codegen that I can't quite understand yet https://github.com/Pierre-vh/llvm-project/tree/rfc-self-ru
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVdGO27gO_RrnhZjAdZw48-CHdAZTBLiD2y3aD6BlJmJHkbwilTT79QvZSSZtgQV2X2YQWSTPOTykUIT3nqgtlh-L5fMMk9oQ289MMdLD0c660J_bzU4pglUdpFhsiuqlqF72rDZ1cxMORfXi3PH672GI4TsZLaqXITlXVC-P9apcA_r-v2dYNvWqqJ5AwoHAhJ7AoIcDiwmHgR0Be9hsorGrGjoymITgDz_WfPYQac-iFAW6oBaCd2eweCT4eP8NBdQSx3yUPKvkgjmDD2rZ74Gc0Lwon4tyM_39alngQOhzJGoOh5MlD5hzHFDe4IDxTTIGFOg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