-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/compile: liveness analysis conservative for compound objects #28626
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
Comments
Ignoring reads of scalar fields during liveness analysis was my first thought too. |
It's not trivial to check the scalarness of a read in plive.go. If we could extract the offset+size of the read, we could check in the type of the variable directly. |
Isn't the offset already in AuxInt? We'd just need to encode the size of the read in the ssa.Op's SymEffects (at least for reads up to word size). |
Yeah, the offset info is there. We'd have to switch on the aux type, there are a few others like symValAndOff. |
Punting to 1.13. |
Punting to 1.14. |
The compiler reports (with
-live
) thatdata
is live at theruntime.GC
call. In fact, only the.len
field ofdata
is live at that point. But because we track liveness by variable, if any field of that variable is live whole variable is live. This meansdata
will be retained unnecessarily by the garbage collector.The generated code contains:
Even though the code looks like it reads the length first, the compiler postpones that read until after the
runtime.GC
call (so it doesn't have to issue a pointless spill).Two solutions come to mind. One is to track liveness of individual pointer fields of variables, instead of whole variables. That would work, but could be expensive for variables which have lots of pointer fields. It also isn't possible to do precisely for variables which are arrays of pointers and have non-constant indexes.
The other solution is to ignore reads of scalars when doing the liveness analysis, as the results of the liveness analysis are only used by the GC. This is more of a hack but would be a simpler fix for the code in this issue.
The text was updated successfully, but these errors were encountered: