-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
if matches!(...)
results in worse mir than if let ...
#77355
Comments
Any opinions on what the best fix here would be? Maybe look for Then other existing simplification and const prop passes could do the rest... |
I don't know if the following is the best fix, but at least it's some form of simplication. If we look for bbs with the pattern "set bool, go to bb that only switches on that bool", we would find bb1 and bb2 that both jump to bb3. It should then be fairly easy to see that bb1 can just jump to bb4 and bb2 can jump to bb5. I don't know if this is enough of a simplification to allow the other passes to do the rest, but at least it should allow the removal of bb3 and probably also _2 which then seems unused. By that time I would think simplifycfg would replace bb1 with bb4 and bb2 with bb5. |
see the relevant discussion on zulip: https://rust-lang.zulipchat.com/#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/optimizing.20matches/near/211759874 @oli-obk proposed extending |
New mir-opt pass to simplify gotos with const values (reopening rust-lang#77486) Reopening PR rust-lang#77486 Fixes rust-lang#77355 This pass optimizes the following sequence ```rust bb2: { _2 = const true; goto -> bb3; } bb3: { switchInt(_2) -> [false: bb4, otherwise: bb5]; } ``` into ```rust bb2: { _2 = const true; goto -> bb5; } ```
This is probably something we can and should optimize:
results in
https://godbolt.org/z/8K79o8
The text was updated successfully, but these errors were encountered: