Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance regression since llvm 9 using pointers for array traversal #53205

Open
outpaddling opened this issue Jan 14, 2022 · 2 comments
Open

Comments

@outpaddling
Copy link

outpaddling commented Jan 14, 2022

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

To reproduce:

git clone https://github.com/outpaddling/Lang-speed.git
cd Lang-speed
(Edit clang-check to use available clang compilers)
./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
@dwblaikie
Copy link
Collaborator

@aeubanks - /maybe/ this could be some loss due to opaque pointers? (not sure if we have a group or how to tag a group here... )

@outpaddling
Copy link
Author

I don't think so, it's a simple array that's part of a fully defined structure. The code is here in case someone wants a quick peek without cloning:
https://github.com/outpaddling/Lang-speed/blob/master/selsort-pointers.c
https://github.com/outpaddling/Lang-speed/blob/master/selsort-subscripts.c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants