-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/compile: handle subslices in range -> memclear optimization #18908
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
The code in |
Yes. Thanks. :) |
(Or |
Because it's easy to get wrong on the index for the 2nd form, I still
prefer to create a temp slice and then use the first form (unless a = 0).
|
Looks like a nice project and i am happy to work on it for 1.9. |
Had a quick look whats involved and i think this is not as localized a change as i thought. By the time we get to memclrrange the order pass seems to have moved the slicing into a temporary. So we would need to add a isMemclrrange and intercept that case early by adding a OCLEARRANGE Node and teach order and other walks to not hide the slicing away from memclrrange. But adding that much special casing to write e.g.:
instead of
does not seem to pay for the added complexity in the compiler. Thoughts or hints how to possible make adding this feature easier (or if i understand the interference from the order pass wrong)? |
I agree. I think we should simply not do this. Thanks for digging into it, @martisch. |
The core of
f
gets compiled into a memclear call. The core ofg
does not, because the current pattern matcher looks for an exact match between the range expression and the LHS of the zeroing statement. We should expand this to allow the range expression to match the LHS of the zeroing statement plus slicing. The generated code should first generate any required bounds checks for the slicing, then call memclear with appropriately adjusted values, taking care if necessary not to generate a pointer to the end of the slice.If/when this gets implemented, also update some quirky code in the compiler that was written to work around this shortcoming. (For a sample, grep for
tail :=
. I suspect https://go-review.googlesource.com/36212 will introduce more such code.)This might be a good moderate-difficulty medium-sized project for someone learning the compiler.
cc @martisch @randall77
The text was updated successfully, but these errors were encountered: