-
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
Tell LLVM about NonZero integer types #54995
Conversation
Change the `get` method on NonZero integer types to insert an `assume`, so that LLVM can optimize better. Closes rust-lang#54868
r? @dtolnay (rust_highfive has picked a reviewer for you, use r? to override) |
r? @eddyb |
pub fn assume_nonzero(x: u64, y: NonZeroU64) -> u64 { | ||
x / y.get() | ||
// CHECK: icmp ne i64 %y, 0 | ||
// CHECK: @llvm.assume |
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.
Would it be worth a CHECK-NOT
of some sort that there's no branch/select/panic/whatever?
Also, cc @rkruppe who might have thoughts here.
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.
Yes, the assume
is just a hint and might get removed at some stage of the pipeline in the future. Checking for lack of the branch is the more correct way to test this here.
I am hesitant to add assumes in random places because they add more IR (particularly if they're in a very common, small and usually-inlined function like this) and they can, unfortunately, also block some optimizations. |
I'd like to learn what optimization this could block. |
@tromey anything that would be blocked by a regular non-inlined call to an empty function is going to be blocked by the
In addition to that, the call to |
Besides passes treating |
The most appropriate way to solve this would be to assign the |
We already have range metadata on loads (there's no range metadata on stores). Without making NonZeroU32 a lang item, too -- it's a consequence of it being laid out as scalar and inheriting the niche from |
Thanks. |
…-obk Unstably allow assume intrinsic in const contexts Not sure much about this usage because there are concerns about [blocking optimization][1] and [slowing down LLVM][2] when using `assme` intrinsic in inline functions. But since Oli suggested in rust-lang#76960 (comment), here we are. [1]: rust-lang#54995 (comment) [2]: rust-lang#49572 (comment)
…-obk Unstably allow assume intrinsic in const contexts Not sure much about this usage because there are concerns about [blocking optimization][1] and [slowing down LLVM][2] when using `assme` intrinsic in inline functions. But since Oli suggested in rust-lang#76960 (comment), here we are. [1]: rust-lang#54995 (comment) [2]: rust-lang#49572 (comment)
Change the
get
method on NonZero integer types to insert anassume
, so that LLVM can optimize better.Closes #54868