-
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
Model physical resource liveness in LIR #8353
Comments
Regarding flags modelling in particular, here's a sketch of what I've been thinking:
@CarolEidt @BruceForstall @mikedn thoughts? This should all be pretty simple and should serve our purposes well enough. |
That makes sense. Presumably the liveness and side-effect analyses would only be done when in LIR. |
Sounds reasonable for a start and maybe for more. Some notes:
We already have something like that but it's a bit messy -
I'm not sure that's needed right now. The only cross block use of flags we had disappeared with my recent long relop lowering simplification. That said, some future optimizations might need this - eliminating a redundant compare from code like: if (x < y) {
}
else if (x > y) {
} |
Correct.
I think the semantics of this bit are a bit different than they seem. IIUC this bit is used to indicate that the ARM backend should generate an instruction that sets the CCR; it does not appear to have any meaning on other platforms. W.R.T. an implementation of the proposed design, I would suggest that we replace the APIs you've mentioned with
I don't think that it hurts to do the work now (unless doing so has an undue adverse impact on JIT throughput). |
Does this generalize to other physical resources? GP registers, sub flags, system registers a la arm64? This seems like a place where we'd want a plan that covers the broader category of hardware resources in LIR even if we only need to stage a piece of it today. |
It does, see the
Yes, that would be good. |
Yuck, I see that use now. My quick skim of
Yes, definitely. We want any code that reasons about side-effects to be able to depend on this, so it needs to be set consistently and accurately. Until it is, we may need to be extremely pessimistic (e.g. assume all nodes will generate code that sets flags unless they have explicitly indicated otherwise). |
It does not. If we all agree on the aforementioned design for an interim solution for flags, I will open a separate issue to track that and we can discuss a more complete design here. I do not want to block making incremental progress (i.e. flags modeling) on a design for a feature for which we have no short-term use case. |
I'd like to make progress too but I'm concerned that interim solutions evolve into defacto designs hamstring medium term work - can we at least surface what the divergent concerns are that are in the way of us proposing a more consistent design? |
I think it is a greater danger to design for scenarios that we are not currently addressing. Chances are that the design will not be quite what we want down the road. I am a strong proponent of designing for scenarios at hand. |
Here are some of the issues that I think a more complete solution would need to address:
At first glance, it seems that unifying physical resources with lclVars is a reasonable approach in a broad sense: both are multi-def, multi-use resources that want to participate in liveness, and both must be considered by the RA. The practicalities of implementing such a design may be prohibitive, however, given the various assumptions made throughout the code about lclVars and how they relate to physical resources. |
I believe the goal of optimizing LIR is near enough at hand that having a design that covers the more general is both practical and profitable. In concrete terms this just allows us to better answer two related questions we already ask today:
My view is that these are fundamental and immediate enough that I don't think this is premature design. |
@mikedn There are unordered FP compares that do back to back flags tests... eg
So technically the flags are live cross block here. But perhaps this does this not really count as cross-block live to the jit, if it allows 2 jump instructions in a single BB if they have the same target? |
Yeah, I think this would be represented in the IR as a single |
Yes, these aren't lowered, codegen handles them as already mentioned by @pgavlin. I preserved this approach even in my relop lowering experiment, it doesn't seem to be worth changing. |
To allow for more general optimizations of the instruction stream in LIR (like dotnet/coreclr#12250 and #8035) we will need be able to deal with the liveness of flags, as well as physical registers in the IR. Not having this blocks reordering optimizations and makes changes in transformations more error prone. ("oh darn I forgot about the flags case" bugs)
category:design
theme:ir
skill-level:expert
cost:large
impact:medium
The text was updated successfully, but these errors were encountered: