Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Fixed const propagation not working in a particular scenario #71298
Fixed const propagation not working in a particular scenario #71298
Changes from all commits
837c29b
faa3fbb
e541d81
f64a0e4
45f1775
8a8c8c9
6e586b8
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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 wonder if we should move to a general scheme where we
visit_operand
and mutate the operand directly instead of finding all the operands in all the terminators and statements and mutating them manuallyThere 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.
Sounds interesting. That's probably worth a try, because I feel that we're gonna be redundant in many parts of the code after all is said and done.
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.
That would be specially useful for weirder
Operand
cases likeinterpret::Immediate::ScalarPair
andinterpret::Indirect
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.
In fact, in
ConstPropagator::replace_with_const
https://github.com/rust-lang/rust/blob/9fc9dc99ee60a7ab603622ee83d14f8e05485740/src/librustc_mir/transform/const_prop.rs#L699 this exact thing is implemented already. There is even a comment about howScalar
andScalarPair
were relatively easy to implement compared toOperand::Indirect
, and that because of that,Indirect
's const prop implementation was postponed.I'm currently trying to adapt the
replace_with_const
code to work with aScalarPair
that came from anOperand
(still trying to work out the types, because I don't have anRvalue
to capture my results). I think I 200% second your idea now @oli-obk, we're already having code duplication and it should be straight-forward-ish to do it, provided we work out the types so that indeed we can just directly mutate anOperand
without needing things likeRvalue
s to do it.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.
@wesleywiser what do you think?
If we go ahead with this idea, I think I could do a separate PR to address it, since I feel that this requires quite some work to be done outside of
mir/transform/const_prop.rs
. I can work theScalarPair
cases et al there as well, since after this hypothetical function is implemented, expanding the current propagation at function callsites intoScalarPair
s should be almost a one-liner.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 think that's a great idea! My only concern is that
replace_with_const
has some special handling forRvalue::Aggregate
and we should make sure we don't regress the optimizations we do there.rust/src/librustc_mir/transform/const_prop.rs
Lines 724 to 730 in 82e90d6
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've just realized that I left you hanging here. Yes, indeed. I wouldn't touch whatever optimizations are in there if at all possible.