-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Deduplicate unreachable blocks, for real this time #110569
Conversation
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
This comment has been minimized.
This comment has been minimized.
4867f69
to
eead45d
Compare
@@ -0,0 +1,16 @@ | |||
// compile-flags: -Zmir-opt-level=2 -Zinline-mir | |||
// ignore-debug: standard library debug assertions add a panic that breaks this optimization |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blessing the ignore-debug
tests requires to recompile everything, which is tedious.
Can you use the intrinsic directly and cook your own unreachable_unchecked
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm really wary of doing things like that. Modifying the mir-opt test for the convenience of testing is what caused this regression in the first place, and this test is already somewhat removed from the code that was reported to not optimize.
*target = self.duplicates[0]; | ||
} | ||
} | ||
|
||
if optimization_was_applied { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this heavy enough to warrant the short circuit?
Could this cause us to miss cases where combining would be useful, but the branches are already deduplicated?
match { A => {}, B | C => unreachable }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or do you rely on the call in instcombine?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I wrote this I think I didn't realize how rare this code should be, since we already only get here this if there are multiple unreachable blocks in the Body. And I'm quite sure I do not want to be relying on InstCombine.
@@ -0,0 +1,16 @@ | |||
// compile-flags: -Zmir-opt-level=2 -Zinline-mir | |||
// ignore-debug: standard library debug assertions add a panic that breaks this optimization | |||
#![crate_type = "lib"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated: should we make mir-opt tests "lib" by default, to avoid to list all the cases in a fn main
everywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we can. The codegen tests could do with the same treatment; I pulled this style of testing from them. There's a #![crate_type = "lib"]
in nearly every single codegen test file.
eead45d
to
8ec49ad
Compare
It seems prudent to |
This comment has been minimized.
This comment has been minimized.
⌛ Trying commit 8ec49ad with merge 31ffe61ee8b251efc5bd2f3561d22d594d5a0cab... |
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (31ffe61ee8b251efc5bd2f3561d22d594d5a0cab): comparison URL. Overall result: no relevant changes - no action neededBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. @bors rollup=never Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)This benchmark run did not return any relevant results for this metric. CyclesThis benchmark run did not return any relevant results for this metric. |
@bors r+ |
☀️ Test successful - checks-actions |
Finished benchmarking commit (4a03f14): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. |
In #106428 (in particular 41eda69) we noticed that inlining
unreachable_unchecked
can produce duplicate unreachable blocks. So we improved two MIR optimizations:SimplifyCfg
was given a simplify to deduplicate unreachable blocks, thenInstCombine
was given a combiner to deduplicate switch targets that point at the same block. The problem is that change doesn't actually work.Our current pass order is
So in here, I have factored out the specific function from
InstCombine
and placed it inside the simplify that produces the case it is looking for. This should ensure that it runs in the scenario it was designed for.Fixes #110551
r? @cjgillot