-
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
Promote unchecked integer math to MIR BinOp
s
#112238
Conversation
Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 Some changes occurred to the CTFE / Miri engine cc @rust-lang/miri This PR changes MIR cc @oli-obk, @RalfJung, @JakobDegen, @davidtwco, @celinval, @vakaras Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt This PR changes Stable MIR Some changes occurred in cc @BoxyUwU |
| sym::exact_div | ||
| sym::unchecked_shl | ||
| sym::unchecked_shr => { | ||
sym::exact_div => { |
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 exact_div
be promoted too, or is it too rare to bother?
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's pretty rare on its own: looks like it's in the middle of align_offset
, which is already pretty complicated, and as_chunks_unchecked
, which is unstable, only.
The place it comes in where it's really important is in sub_ptr
, but that's its own intrinsic, so the exact_div
doesn't show up in MIR at all.
So I think I'd like to leave it out of this PR, so it stays focused on just the "overflow is UB" ones.
@@ -601,6 +601,24 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { | |||
); | |||
} | |||
} | |||
AddUnchecked | SubUnchecked | MulUnchecked => { |
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.
Can this reuse the previous branch?
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 split it out because the *Unchecked
ones don't work on floats, which the previous branch accepts.
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 pulled out the "equal types" checks to a shared check, and used that to merge some of the arms.
@rustbot ready
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.
Interpreter changes look good!
add unchecked_shl test rust-lang/rust#112238 made me realize that we have a test for add,sub,mul,shr but not shl. Add the missing test. Also name the existing tests more consistently.
add unchecked_shl test rust-lang#112238 made me realize that we have a test for add,sub,mul,shr but not shl. Add the missing test. Also name the existing tests more consistently.
Thanks, Ralf! The MIRI tests were very helpful in ensuring I got everything exactly the same here 🙂 |
739af0e
to
b96de9e
Compare
@bors r+ |
…llot Promote unchecked integer math to MIR `BinOp`s So slice indexing by a range gets down to one basic block, for example. r? cjgillot
⌛ Testing commit 33be521 with merge 26d6ddd3f0aa50c1224ac38fdac9bb15231829e0... |
This comment has been minimized.
This comment has been minimized.
💔 Test failed - checks-actions |
33be521
to
adf1624
Compare
⌛ Trying commit 015f6ec719934c6082eabdd203b006fcdeec2c56 with merge d2a3397004f36e2ad1a270be102c6637ae511629... |
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (d2a3397004f36e2ad1a270be102c6637ae511629): comparison URL. Overall result: ❌✅ regressions and improvements - 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 is a highly reliable metric that was used to determine the overall result at the top of this comment.
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.
CyclesResultsThis 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.
Binary sizeResultsThis 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.
Bootstrap: 656.882s -> 655.76s (-0.17%) |
015f6ec
to
c780e55
Compare
@bors r+ |
☀️ Test successful - checks-actions |
Hooray, #112673 worked, then 🎉 |
Finished benchmarking commit (4051305): comparison URL. Overall result: ❌ regressions - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
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.
CyclesResultsThis 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.
Binary sizeResultsThis 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.
Bootstrap: 656.783s -> 658.381s (0.24%) |
So slice indexing by a range gets down to one basic block, for example.
r? cjgillot