<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/143219>143219</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[flang][perf] Adding noalias for function arguments affects function specialization
</td>
</tr>
<tr>
<th>Labels</th>
<td>
flang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
vzakhari
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
vzakhari
</td>
</tr>
</table>
<pre>
CPU2017/548 slowed down after https://github.com/llvm/llvm-project/commit/a0d699a8e686cba99690cf28463d14526c5bfbc8, so this change was partially reverted by https://github.com/llvm/llvm-project/commit/d16ecad968244ca42ce09cb3199dea1ec994b211
I could reproduce it on neoverse-v1 with `-Ofast -flto -mcpu=neoverse-v1 -fuse-ld=lld -mmlir -force-no-alias=false/true`.
It looks like the `digits_2` function does not pass the function specialization threshold on the Latency bonus.
Without noalias:
```
FnSpecialization: Specialization bonus {Latency = 2424 (71%)}
```
With noalias:
```
FnSpecialization: Specialization bonus {Latency = 1098 (34%)}
FnSpecialization: No possible specializations found for _QMbrute_forcePdigits_2
```
The current threshold is 40%.
It looks like the big portion of the latency bounds comes from the multiple `mod(row, 3)` expressions, which are not CSEd without noalias - so function specialization computes a lot of bonus for them when `row` is a constant. With noalias, there is a single `srem` instruction that computes `mod(row, 3)` at the beginning of the function.
I will investigate more to see if the function specialization misses to account for some bonuses.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysVd2O4zYPfRrlhnAgyz-xL3KRmXwBPqA_W2yLXg5kibLVkSVDlJPOPn1hJ5md2XYKFC0QIBZF8fAcUqIksr1H3LPqgQlx_iKfBxktE4JVx42c0xDi_m7ddEG_7B8__SJ4vmPiVJUNkAsX1KDDxYM0CSMMKU3EigMTJyZOvU3D3G1VGJk4OXe-_2VTDL-hSkycVBhHu3xIruu2lQ3WTa062bZ1y5URTVkXOi8rUauqM51qmHgECpAGS6AG6XuEiySYZExWOvcCEc8YE2roXv5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