<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=http://email.email.llvm.org/c/eJy9V11v4jgU_TXwYhHlE5IHHmamRao0ux1t-z5yYkO8deLIdkrZX7_HTmApaJiWrooQIc69555777mJUyq2W96RrVaWE0qMaDrJScnbqm6ofiK9Ee2GGC55ZYVqiVHaEqtIpZqOak46rtdKN7StOFFr8ky1UL3xl4Xk2hDaMiJay3WnOX7NJPkyCW8m4fhbW9v5tXiF70bYui8DeONE9bajjEkQwNl32m5mpuOcHbvfkVZZUXFGbE0tqSSsSOGDSopwxHFs-qomRqotzmHWjmY52da8HTPslCdpXG5W02f85TBGTbSmu4CQO0sEspFGneM5O0MbVEOrjaYN2SIPYvrSVFp01sD92xjS1GprEBhkUXXVS0b4S4fiTuJvg9uBCeq_ES2VckfW1Nh9sCPY15Uw3DEGSWFMj260pFTAW2nOvz7ckEmc-7yPqjOJh5M_aHX_cDCIEqw7OrZW_aZ2QIOBS3NkR1yBnB4sfeIGJiBJS3SMREH2QqghUiFfHH9Bd6VV4wF1DxDRAMSVBpw5CuuiCwsM9QQk8cTHlhmrug7NZsqrUqHkqoO3-Ic6dRp47xQSmt3DlGrrrFDpPdnC9RHO7SReWF8v2u5QMliJoYvPBdHQOkXzISyQGpLyZbW7zmv8OOI-p-zrayGPICaQ8rkJlHYKLoIwCHFkqjI4_DWY_OnCBLVt5CS7QQv-Bxx076jSjwopQZisr_jJ8GHcUFjVcnLFGAawGmAqRk6nM4Cpb9msqnn1dBx0Mg_H7-DsG7vvUI7cIqdESzc-udvvt18ebn_mYYSztRuHQ3qPmA9uQZq85POf83TW4d5USjZbQ_GlYVESjDEea80pI41iXDr7ThnxMo5NC6FIydmN0O4SovQGg7GSqnKxVq7wuSt3KdrBZXY_HB8OynaO-08cRCEKTuXRSljgLoOh2X_Qv5CYnRlwfowDf4ziveIznPgSzuw-_g2x6BQQK59CzN2_LnNL5qeYSXYNtzg5xYkvcnstv2KQ3yfLq3iXvOL0LMPk_ZVKg_niNY5f-Yi8wvxMFhcBf0ksPSOWflRe4ZkswiuKlgRR9hrHr7xZXk4yB9F8mrzc8_yt8kKti7PqX3H3glf23i7-7u51dlvFyhXE8uiUWH4R5y3yis7kFV01k4sz6S8u4hyepVO2TFiRFHRKe2zb9PLoqT3ttVxeeMA7jYyHGfYJf_vN6MpvIt0jOEviMJvWS7aIS7rII56vs3Va0HAxj1nEs6Qo53HEwqmk2LuZJfZCkzhu-XbYh-I_NjbTjzMQyziM4zCK0igJ4zQLKAurqlzk8yrj6SKKJmnIGyrkYa801UsPWfbYS6ShFMb-t5GaUmPEpuXcEwZDK6zkyx9H7zOabzQ3fnLxjoAF50uK0zcG2A9vCfsXByqnnvvSE_8Xhrf1Tw>53205</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Performance regression since llvm 9 using pointers for array traversal
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
outpaddling
</td>
</tr>
</table>
<pre>
I wrote a simple benchmark using selection sort to compare performance of various compilers and interpreters:
https://github.com/outpaddling/Lang-speed
I noticed that clang 9 and later are much slower than clang 8 when using pointers to traverse the array. It is also much slower than the same program with subscripts. Clang 8 shows what I would expect, with pointers marginally faster than subscripts.
I see this issue on both FreeBSD (clang9 and later) and MacOS (clang13), though on MacOS the pointer version takes only about 1.5x as long as subscripts.
>From the run times shown below, it looks like clang stopped doing some optimizations beyond -O starting at version 9. I don't see anything in the v9 release notes about this type of optimization.
[https://releases.llvm.org/9.0.0/docs/ReleaseNotes.html](https://releases.llvm.org/9.0.0/docs/ReleaseNotes.html)
To reproduce:
git clone https://github.com/outpaddling/Lang-speed.git
cd Lang-speed
./clang-check
```
clang version 8.0.1 (tags/RELEASE_801/final)
Target: x86_64-portbld-freebsd13.0
Thread model: posix
InstalledDir: /usr/local/llvm80/bin
-O
Subscripts: 2.10 real 2.09 user 0.00 sys
Pointers: 2.02 real 2.02 user 0.00 sys
-O2
Subscripts: 2.11 real 2.11 user 0.00 sys
Pointers: 2.02 real 2.02 user 0.00 sys
-Ofast
Subscripts: 2.36 real 2.35 user 0.00 sys
Pointers: 2.23 real 2.22 user 0.00 sys
clang version 9.0.1
Target: x86_64-portbld-freebsd13.0
Thread model: posix
InstalledDir: /usr/local/llvm90/bin
-O
Subscripts: 2.24 real 2.23 user 0.00 sys
Pointers: 4.67 real 4.67 user 0.00 sys
-O2
Subscripts: 2.08 real 2.07 user 0.00 sys
Pointers: 4.64 real 4.64 user 0.00 sys
-Ofast
Subscripts: 2.03 real 2.03 user 0.00 sys
Pointers: 3.15 real 3.15 user 0.00 sys
clang version 13.0.0
Target: x86_64-portbld-freebsd13.0
Thread model: posix
InstalledDir: /usr/local/llvm13/bin
-O
Subscripts: 4.69 real 4.69 user 0.00 sys
Pointers: 4.65 real 4.64 user 0.00 sys
-O2
Subscripts: 2.10 real 2.10 user 0.00 sys
Pointers: 4.81 real 4.80 user 0.00 sys
-Ofast
Subscripts: 2.13 real 2.13 user 0.00 sys
Pointers: 4.74 real 4.73 user 0.00 sys
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy9Vl1v4jgU_TXwYhE5nyQPPMxMi1RpdjvazvvISVzirRNHtlPK_vo9dgJLQcO0zKoIEWKuzz333ONwS1XvVndkq5XlhBEj2l5yUvKualqmn8hgRLchhkteWaE6YpS2xCpSqbZnmpOe60elW9ZVnKhH8sy0UIPxPwvJtSGsq4noLNe95vg0s_jTjN7M6PTZWNv7tWiN90bYZigD7MaNGmzP6lqCAO6-sm6zMD3n9fH2O9IpKypeE9swSyqJKFL4pJIhHXEc26FqiJFqi3uEdVNYTrYN76YKe-VJGleb1ewZXzmCoYnWbBcQcmeJQDXSqHM8F2dYCzW02mjWki3qIGYoTaVFbw22f5lSmkZtDRKDLFRXg6wJf-kh7iz6Mm47MIH-G9ExKXfkkRm7T3YE-1oJwx1jkBTGDOhGR0oFvL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