-
Notifications
You must be signed in to change notification settings - Fork 4.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
JIT: Optimize redundant sign extensions in indexers #52414
Conversation
I ran an experiment a while back that involved touching a few more files, since I was trying to get array and span and string indexers all in one shot. GrabYourPitchforks/coreclr@d14b977 Though TBH I didn't have a clue what I was doing and it's entirely possible that prototype code is hot garbage. :) |
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.
Co-authored-by: Günther Foidl <[email protected]>
Partially, I guess a separate PR somewhere in RA/Emitter should also get rid of the mov (see https://www.diffchecker.com/FukMpulc)
With @GrabYourPitchforks's patch yes! @GrabYourPitchforks do you mind if I include your patch? it handles Spans 🙂 |
Typically one wants to avoid introducing casts into expressions like these as it complicates secondary IV analysis (which we don't yet do, but someday soon). I wonder if we need some other kind of cast node here or some extra GTF flag that makes it clear this is known to be a cast that does not alter the value. @BruceForstall thoughts? |
Wonder if we can split |
I forget: do all platform ABIs sign-/zero-extend arg registers, so the full register value is readable? If not, in the example here you'd still need a zero extend.
Doesn't the current Cast node have the right info to determine this? What would adding new node types improve?
I haven't thought about how IV widening would work, but it doesn't seem like we need to inhibit this opt. if we don't have a plan there yet. Seems like this zero extend case could also possibly be handled by some kind of bitwise zero forward propagation. If the index wasn't from an argument, would it be different? |
Ping myself |
Will revise this week |
Closing for now as it should be done in a more general way like in assertprop or something like that, to e.g. handle this: sharplab |
Just a quick fix for the issue noticed by @GrabYourPitchforks - we emit redundant sign-extension movs for indexers, e.g.:
Codegen:
New codegen: https://www.diffchecker.com/FukMpulc (mov is still there 🤔 but at least without the sign extension)