-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
cmd/compile: optimize slice access with constant upper/lower bound #14266
Comments
/cc @dr2chase |
I wonder if this might actually come for free from existing SSA + @dr2chase work. There are no ordering requirements for the bitwise OR operations, and there are no side effects and there's only one return path. |
David (drchase) can take a look at the bounds checks. |
Grand plan is to do this in SSA. We have bounds-check removal code now that does this somewhat better. The enabling step is to search for the highest bounds check before a side-effect, and to hoist that one first where it dominates all the others. However, I just tried that experiment by hand, and constant indices aren't working well (yet). |
Can this be closed? I think the current BCE logic handles this case. |
Imho this is not exactly the case, and that's why in endian encoding routines there is explicit prologue check for whole length, e.g.
which is indeed gets compiled to
but without that explicit
( P.S. somehow for bigendian it works ok without |
I think this can be closed. The current Go semantic does not allow to optimize bound accesses if they are done in forward order (eg: 0 to 7). This is why an explicit So this is not a missing optimization. If you anybody wants to propose a semantic change, please file a Go 2 proposal. |
For example (https://golang.org/src/encoding/binary/binary.go#L69):
Gets compiled roughly to:
I was wondering if that can get optimized to something more like:
I tried to look at the code in
src/cmd/compile/internal/gc/cgen.go
but it was way above my head, if there's interest in that idea and no one wants to pick it up, I'll look more into learning how the code gen works and try to implement it.@randall77 you might find this interesting.
The text was updated successfully, but these errors were encountered: