-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Fix mod_inv termination for the last iteration #103378
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
On usize=u64 platforms, the 4th iteration would overflow the `mod_gate` back to 0. Similarly for usize=u32 platforms, the 3rd iteration would overflow much the same way. I tested various approaches to resolving this, including approaches with `saturating_mul` and `widening_mul` to a double usize. Turns out LLVM likes `mul_with_overflow` the best. In fact now, that LLVM can see the iteration count is limited, it will happily unroll the loop into a nice linear sequence. You will also notice that the code around the loop got simplified somewhat. Now that LLVM is handling the loop nicely, there isn’t any more reasons to manually unroll the first iteration out of the loop (though looking at the code today I’m not sure all that complexity was necessary in the first place). Fixes #103361
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -455,6 +455,18 @@ fn align_offset_various_strides() { | |
| assert!(!x); | ||
| } | ||
|
|
||
| #[test] | ||
| fn align_offset_issue_103361() { | ||
| #[cfg(target_pointer_width = "64")] | ||
| const SIZE: usize = 1 << 47; | ||
| #[cfg(target_pointer_width = "32")] | ||
| const SIZE: usize = 1 << 30; | ||
| #[cfg(target_pointer_width = "16")] | ||
| const SIZE: usize = 1 << 13; | ||
| struct HugeSize([u8; SIZE - 1]); | ||
| let _ = (SIZE as *const HugeSize).align_offset(SIZE); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We usually prefer the strict provenance APIs in libcore -- #104632 Note sure if the lint against int2ptr casts ever got implemented? If yes we should probably enable it here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I basically just copy-pasted over the reproducer from the issue… |
||
| } | ||
|
|
||
| #[test] | ||
| fn offset_from() { | ||
| let mut a = [0; 5]; | ||
|
|
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.
Sadly
uncheckedis useless here today -- LLVM turnssub nuw %m, 1intoadd %m, -1during normalization :((Doesn't need to change here, though. I'm just sad about llvm/llvm-project#53377.)