Uh oh!
There was an error while loading. Please reload this page.
Optimize IntRange::from_pat, then shrink ParamEnv - #77257
Conversation
Previously, this method called the more general `pat_constructor` function, which can return other pattern variants besides `IntRange`. Then it throws away any non-`IntRange` variants. Specialize it so work is only done when it could result in an `IntRange`.
…uct." This reverts commit ab83d37.
ecstatic-morse
commented
Sep 27, 2020
@bors try |
rust-timer
commented
Sep 27, 2020
Awaiting bors try build completion |
bors
commented
Sep 27, 2020
⌛ Trying commit c4d8089 with merge baa01e8429de2c041f0095c01d4e8ca99c0b11a7... |
bors
commented
Sep 27, 2020
☀️ Try build successful - checks-actions, checks-azure |
rust-timer
commented
Sep 27, 2020
Queued baa01e8429de2c041f0095c01d4e8ca99c0b11a7 with parent 1ec980d, future comparison URL. |
rust-timer
commented
Sep 27, 2020
Finished benchmarking try commit (baa01e8429de2c041f0095c01d4e8ca99c0b11a7): comparison url. Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up. @bors rollup=never |
(moved to summary) |
jackh726
left a comment
There was a problem hiding this comment.
LGTM :) Super weird that this was the cause of the slowdown. (A large one at that!)
vandenheuvel
commented
Sep 28, 2020
I'm not quite sure what you mean @vandenheuvel. I think I've gone as far as I care to. If you'd like to investigate further, feel free to keep #77058 open. Perhaps you can do even better. Here's the "slow" assembly ( Excerpt from 0.00 → callq rustc_mir_build::thir::pattern::_match::pat_constructor0.00mov0xb0(%rsp),%cl0.02mov0xc0(%rsp),%r90.20mov0xb8(%rsp),%rbp0.01mov0xd0(%rsp),%r130.01mov0xc8(%rsp),%r80.01mov0xd8(%rsp),%al0.01mov0xd9(%rsp),%edx32.37mov %edx,0x40(%rsp)0.00mov0xdc(%rsp),%edx0.00mov %edx,0x43(%rsp)cmp$0x7,%cl ↓ jne 5a1 Excerpt from (I think) 5a1: mov0x40(%rsp),%edx20.80mov0x43(%rsp),%esi0.03mov %esi,0x183(%rsp)mov %edx,0x180(%rsp)mov$0x1,%dlcmp$0x3,%cl ↓ jne 5d9 mov0x180(%rsp),%ecx0.01mov0x183(%rsp),%edx23.64mov %edx,0x23(%rsp)0.12mov %ecx,0x20(%rsp)cmp$0x2,%al sete %dl0.07 5d9: mov0x20(%rsp),%eax0.01mov0x23(%rsp),%ecx18.20mov %ecx,0xb3(%rsp)0.01mov %eax,0xb0(%rsp)test %dl,%dl0.00 ↓ jne1546mov %r14,0x18(%rsp)0.00mov0x218(%rsp),%rax0.00mov (%rax),%rdi0.01mov0x30(%rbx),%rax0.01mov0x8(%rbx),%r140.14mov0x10(%rbx),%rsimov0x20(%rbx),%rdxmov0x18(%rbx),%r10 movzbl (%rax),%ecxcmp$0x2,%rcx ↓ je629We're repeatedly copying two words into local stack variables, then branching, then reading them again. This sequence has a lot of data hazards, which is clearly slowing down the pipeline significantly. I can't say why LLVM chose to generate code this way, or what causes the data hazards to disappear with my changes to |
simonvandel
commented
Sep 28, 2020
I think the tag was meant for @vandenheuvel |
Sorry! |
Mark-Simulacrum
commented
Sep 28, 2020
r=me unless you're waiting on something further, not quite sure. |
ecstatic-morse
commented
Sep 28, 2020
@bors r=Mark-Simulacrum |
bors
commented
Sep 28, 2020
📌 Commit c4d8089 has been approved by |
bors
commented
Sep 29, 2020
bors
commented
Sep 29, 2020
☀️ Test successful - checks-actions, checks-azure |
@ecstatic-morse I don't have the expertise for further investigation either, unfortunately. And why I asked whether #77058 would remain open: it seems that the root cause has not yet been found.
So to document that, it seems useful to keep #77058 open, perhaps after renaming it and adding another comment. |
I don't think there's anything actionable left in #77058. If you disagree, you're free to reopen it (you should have the requisite permissions). |
ecstatic-morse
commented
Oct 6, 2020
Final perf results are in. Looks to be an improvement everywhere except |
Resolves#77058.
r? @Mark-Simulacrum
cc @vandenheuvel
Looking at the output of
perf reportfor #76244, the hot instructions seemed to be around the call topat_constructorinIntRange::from_pat. I carried out an obvious optimization, but it actually made the instruction count higher (see #77075). However, it seems to have mitigated whatever was causing the pipeline stalls, so when combined with #76244, it's a net win.As you can see below, the regression in #76244 seems to have originated from something measured by
stalled-cycles-backend. I'll try to collect some finer-grained stats to see if I can isolate it. I wish I had a better idea of what was going on here. I'd like to prevent the regression from reappearing in the future due to small changes in unrelated code.Current `master`:
Shrink `ParamEnv` without changing `IntRange::from_pat`:
Shrink `ParamEnv` and change `IntRange::from_pat`: