-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Mandatory optimizations: constant fold boolean literals before the DefiniteInitialization pass #70787
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
Conversation
@swift-ci test |
1 similar comment
@swift-ci test |
06566af
to
cd73481
Compare
@swift-ci test |
This is required for being able to constant fold boolean literals before the DefiniteInitialization pass
…finiteInitialization pass Add a new mandatory BooleanLiteralFolding pass which constant folds conditional branches with boolean literals as operands. ``` %1 = integer_literal -1 %2 = apply %bool_init(%1) // Bool.init(_builtinBooleanLiteral:) %3 = struct_extract %2, #Bool._value cond_br %3, bb1, bb2 ``` -> ``` ... br bb1 ``` This pass is intended to run before DefiniteInitialization, where mandatory inlining and constant folding didn't run, yet (which would perform this kind of optimization). This optimization is required to let DefiniteInitialization handle boolean literals correctly. For example in infinite loops: ``` init() { while true { // DI need to know that there is no loop exit from this while-statement if some_condition { member_field = init_value break } } } ```
cd73481
to
c89df9e
Compare
@swift-ci test |
Nice. I was looking in to a related issue which might also be fixed by this: #70655 I diffed the SIL produced by each version (I think it's the optimised SIL; I compiled with
Whereas for
Note the call to Sorry if it's not related - I don't mean to just mention random issues, but the pattern seems very similar to the pattern that you mention in the PR description. Is this something that would also be resolved by this new mandatory pass? |
@karwa calls to |
@eeckstein I am having one question / concern. This is a mandatory pass written in Swift. If swift is not in the compiler (e.g. on Windows or non-bootstrapped build), then the pass is just silently disabled, however, it's a mandatory one. Should there be some diagnostics or something like this? |
We will soon be requiring swift compiler sources to be in the build. Unfortunately this is not possible right now on Windows because of a miscompile. Hopefully this will be resolved soon. So the situation on Windows is not ideal right now, but hopefully not for long. |
Ok, is there some progress on speeding up the bootstrapping build? Or there will be some other things? Essentially I'm using non-bootstrapped build for development as otherwise the rebuild step after change is quite long as it rebuilds modules as well... |
You should be using |
Add a new mandatory BooleanLiteralFolding pass which constant folds conditional branches with boolean literals as operands.
->
This pass is intended to run before DefiniteInitialization, where mandatory inlining and constant folding didn't run, yet (which would perform this kind of optimization).
This optimization is required to let DefiniteInitialization handle boolean literals correctly.
For example in infinite loops: