-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Stop generating assumes for validity ranges #129027
base: master
Are you sure you want to change the base?
Conversation
pub unsafe fn ordering_transmute_onetwothree(x: std::cmp::Ordering) -> OneTwoThree { | ||
// CHECK: ret i8 1 | ||
// CHECK: ret i8 %x | ||
std::mem::transmute(x) | ||
} |
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.
Previously, LLVM would intersect the validity ranges of Ordering
and OneTwoThree
, and deduce that the only valid value is 1
. Without the assumes, this no longer happens (although the information is not lost--the argument and return value get range
attributes, so this could in theory be recovered via a new LLVM opt).
This was added in https://github.com/rust-lang/rust/pull/109993/files#diff-658bfaf1eeca92ac9090a307cc820f2a7afa3c29c047d707a34da3531133f63aR89-R101. This specific example feels pretty obscure, so I don't think this change is significant, unless there's a real-world usecase this is derived from (@scottmcm?)
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 don't remember where this came from. The specific test is certainly contrived, but I vaguely recall that there was something in this vein, maybe it was transmuting a NonZero<Foo>
to something?
Assuming this gets range attributes on the parameter and return such that LLVM has enough information that it could do it, then I'm totally fine regressing this test with a FIXME link to an LLVM bug asking for the opt.
This comment has been minimized.
This comment has been minimized.
42fe613
to
4078a54
Compare
This comment has been minimized.
This comment has been minimized.
Now that LLVM has implemented range attributes on arguments and returns, and now that we generate such attributes, we no longer need to use assumes to represent validity ranges.
4078a54
to
0d514ae
Compare
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
Stop generating assumes for validity ranges After rust-lang#128371, we represent validity ranges as parameter / return value attributes, so we no longer need to use assumes. r? `@ghost`
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (3f964f8): comparison URL. Overall result: ❌✅ regressions and improvements - 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. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @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)Results (primary -0.4%, secondary -2.1%)This 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.
CyclesResults (primary 0.9%, secondary -3.6%)This 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 sizeResults (primary 0.0%, secondary 0.1%)This 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: 753.626s -> 753.637s (0.00%) |
// OPT: call void @llvm.assume(i1 %1) | ||
// DBG-NOT: icmp | ||
// DBG-NOT: assume | ||
// CHECK: ret i8 %x |
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.
fix: seems like this should be keeping at least the ret i8 %x
?
// DBG-NOT: icmp | ||
// DBG-NOT: assume | ||
// CHECK: ret i32 %x | ||
|
||
transmute(x) |
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.
general comment: the CHECK
that just checks the declaration makes these not transmute tests any more, because the body could be removed and it wouldn't matter.
Please put body checks back, or change them to be signature tests instead of transmute tests.
imm = bx.to_immediate_scalar(imm, to_scalar); | ||
imm | ||
} | ||
|
||
fn assume_scalar_range( |
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.
Do range operand bundles work yet? (Last I tried I couldn't get them to parse)
I ask because the problem with this PR is that if we inline NonZero::new_unchecked
and NonZero::get
, we can easily end up with
_2 = _1 as NonZero<u32> (Transmute);
_3 = _2 as u32 (Transmute);
where there's nowhere to put the range attributes, and thus transmute-then-transmute will regress with this PR because that'll compile to just %1
without any range information.
(For example, something like Layout::new_unchecked(size, align).align()
would lose the range information it gets from the assume today.)
Meaning that
so we no longer need to use assumes.
isn't quite true.
I wonder if we need a MIR primitive that we can inline for such things, when the inlined function's parameter isn't a caller parameter and such...
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.
No range operand bundles is still not implemented
After #128371, we represent validity ranges as parameter / return value attributes, so we no longer need to use assumes.
r? @ghost