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

-Wall causes massive compilation slowdown #105959

Open
mikulas-patocka opened this issue Aug 24, 2024 · 7 comments
Open

-Wall causes massive compilation slowdown #105959

mikulas-patocka opened this issue Aug 24, 2024 · 7 comments
Labels
clang:analysis clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer confirmed Verified by a second party slow-compile

Comments

@mikulas-patocka
Copy link

Download an example file from:
http://www.jikos.cz/~mikulas/testcases/clang/ipret.e
(the file comes from Ajla, https://www.ajla-lang.cz/ )

If you compile it with
$ time clang-20 -c -x c ipret.e -O2
it takes 23 seconds

If you compile it with
$ time clang-20 -c -x c ipret.e -O2 -Wall
it takes 31 minutes

I tested it with clang-20 from Debian Sid. On clang-18 and older, it takes a long time to compile the file even without -Wall, but the -Wall switch makes it twice worse.

Also, note that while clang-19 and clang-20 compile faster than clang-18, the code generated by clang-19 and clang-20 for this file is inferior to the code generated by clang-18 and older.

@EugeneZelenko EugeneZelenko added slow-compile clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer and removed new issue labels Aug 24, 2024
@AaronBallman AaronBallman added the confirmed Verified by a second party label Aug 27, 2024
@AaronBallman
Copy link
Collaborator

AaronBallman commented Aug 27, 2024

We are spending the vast majority of our time in AnalysisBasedWarnings (runUninitializedVariablesAnalysis() specifically). Those are enabled by default with -Wmost which is included in -Wall; however, that behavior hasn't changed in a long time, so I'm not certain why it's slowed down so much recently (this is why -Wall made it twice as bad in earlier versions of Clang though).

Here are some timing tests I did on Windows:

PS F:\source\llvm-project> Measure-Command{.\llvm\out\build\x64-Debug\bin\clang.exe --target=x86_64-pc-linux -c -x c "c:\Users\aballman\OneDrive - Intel Corporation\Desktop\ipret.e"}


Days              : 0
Hours             : 0
Minutes           : 1
Seconds           : 6
Milliseconds      : 766
Ticks             : 667660246
TotalDays         : 0.000772754914351852
TotalHours        : 0.0185461179444444
TotalMinutes      : 1.11276707666667
TotalSeconds      : 66.7660246
TotalMilliseconds : 66766.0246



PS F:\source\llvm-project> Measure-Command{.\llvm\out\build\x64-Debug\bin\clang.exe --target=x86_64-pc-linux -Wall -Wno-uninitialized -c -x c "c:\Users\aballman\OneDrive - Intel Corporation\Desktop\ipret.e"}


Days              : 0
Hours             : 0
Minutes           : 1
Seconds           : 9
Milliseconds      : 712
Ticks             : 697128500
TotalDays         : 0.000806861689814815
TotalHours        : 0.0193646805555556
TotalMinutes      : 1.16188083333333
TotalSeconds      : 69.71285
TotalMilliseconds : 69712.85

(I did not let the non--Wall execution run to completion, I gave up after five minutes.)

So -Wuninitialized definitely seems like it contributes the most to the issue.

@mikulas-patocka
Copy link
Author

I explained it badly - it is not a regression between version 18 and 20. If I try to compile the file ipret.e with clang-18 on the same machine, I get 17 minutes without -Wall and 49 minutes with -Wall. So it seems that the -Wall slowdown was always there.

@AaronBallman
Copy link
Collaborator

Ah, thank you for the update, that makes so much more sense to me!

Despite not being a new issue, this is still worth investigating how we can improve; that much of a compile time performance hit is hard to swallow (it would normally be enough to remove this from -Wall which I would really like to avoid as an outcome given the security benefits of that particular diagnostic being enabled by default).

CC @gribozavr @ymand @sgatev as CFG code owners

@mikulas-patocka
Copy link
Author

BTW. when I compare performance of the binary generated by clang-18, clang-20 and gcc-14, I get:
clang-18: 17.9s
clang-20: 20.1s
gcc-14: 18.8s

So, clang-20 compiles faster than clang-18, but it produces slower code. Should I create another bug report for this regression?

@AaronBallman
Copy link
Collaborator

Should I create another bug report for this regression?

Yeah, it's worth filing an issue over. FWIW, it would be helpful if you were able to give a small reproducer instead of a whole program, if possible!

@mikulas-patocka
Copy link
Author

OK. I made a simple reproducer and submitted it here: #106846

@DanielRein-1
Copy link

My c++ config is "cpp": "cd $dir && g++ -std=c++17 -g-Wall -lm -o $fileNameWithoutExt && $dir$fileNameWithoutExt" when i try to run using the keyboard shortcut/ run code my terminal says unrecognized debug output level '-Wall' mean when i run c++

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:analysis clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer confirmed Verified by a second party slow-compile
Projects
None yet
Development

No branches or pull requests

4 participants