-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
[mir-opt] Optimize calls to CopyNonOverlapping #83785
Conversation
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit 98ee843a1bd2bd448f1302fa0c5e7c36555f750f with merge 00b94879e7876a43a12e5ded56e58d3d89406d74... |
☀️ Try build successful - checks-actions |
Queued 00b94879e7876a43a12e5ded56e58d3d89406d74 with parent a207871, future comparison URL. |
Finished benchmarking try commit (00b94879e7876a43a12e5ded56e58d3d89406d74): 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 |
98ee843
to
abe4c83
Compare
r? @oli-obk cc @rust-lang/wg-mir-opt |
Oli is on reduced availability currently; can anyone else from the WG take over review? |
abe4c83
to
1d6c391
Compare
This comment has been minimized.
This comment has been minimized.
1d6c391
to
b645894
Compare
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit b645894 with merge d47385f6d489305d533e77d71f332d73b96c22d4... |
☀️ Try build successful - checks-actions |
Queued d47385f6d489305d533e77d71f332d73b96c22d4 with parent 78c9639, future comparison URL. |
c.c. @rust-lang/compiler for thoughts |
I think we should merge it. perf regressions are <1% and likely just due arbitrary threshold changes in llvm opts. |
We should probably re-run the benchmarks anyway... @wesleywiser can you rebase and resolve the conflicts? |
Triage: @wesleywiser RalfJung commented 23 days ago |
StatementKind::Assign(box ( | ||
tcx.mk_place_deref(dst), | ||
Rvalue::Use(Operand::Copy(tcx.mk_place_deref(src))), | ||
)) |
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.
There was an interesting conversation on zulip around the semantics of copy_nonoverlapping
. If it does an "untyped copy", lowering it to a regular assignment is not a sound optimization, so this probably needs to wait on a decision if copy_nonoverlapping
does a typed or untyped copy. https://rust-lang.zulipchat.com/#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/copy_nonoverlapping.20and.20provenance/near/258410065
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.
Ah, thanks for digging this up, I knew this proposal was living somewhere... (and I think I was advocating for it, not realizing what equating copy_nonoverlapping and assignment would entail).
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 copy_nonoverlapping
does an untyped copy does that mean that the implementation of ptr::read
needs to change so that it does a typed read?
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.
It is correct to replace a typed by an untyped copy, just not the other way around.
So, read
purporting to be typed but actually doing an untyped operation under the hood is fine. (Typedness is force on it anyway because the result is returned by-value at type T
.)
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.
Sure, but that may pessimize the read. See #73258
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.
copy_nonoverlapping
does an untyped copy as per #97712, so this lowering is off the table now.
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.
Should we close it then?
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.
It could be made an assignment at type MaybeUninit<T>
.
I have rebased this PR locally but added test fails in a way suggesting this pass is not being ran. Could somebody instruct me how to debug it? |
the pass definitely runs, it is an unconditional pass. Beyond adding tracing statements and activating those while running the failing tests, I don't know how to debug this. |
I have badly chosen words, I meant the optimisation exit somewhere early. |
@wesleywiser any updates on this? |
No description provided.