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: [0:x] slicing doesn't need to protect against past-end-of-object pointers #14849
Comments
Note that if we change the slicing in Uint64 to |
This is just a missed optimization by generic.
v29 is 0 here, but AddPtr v30 v29 is not folded until the lowering pass. This means that v41 is not replaced by v30 which means fuse cannot collapse the branch. Stupid jumps and empty branches after trim are a sign of missed opportunities for fuse. I'm going to submit a fix tomorrow, but if anyone wants to take care make sure the proper canonicalization rule is added: (AddPtr x const) -> (AddPtr const x). |
I think a better canonicalization would be (AddPtr x const) -> (OffPtr [const] x), that way it can be optimized further against other OffPtrs. |
Or perhaps better yet, find out where that AddPtr came from. I think there are no (AddPtr x const) at the beginning, by construction, so someone introduced it; they should just introduce OffPtr instead. |
The rule is legit. |
CL https://golang.org/cl/20833 mentions this issue. |
For s[i:j:k], SSA does:
The
if
is to make sure we don't end up manufacturing a pointer to the next object in the heap, and thus falsely retaining it.If i==0, we don't need that check.
This comes up in encoding/binary.littleEndian.Uint64:
That second comparison is useless, and represents the
rcap != 0
comparison. Maybe we should not emit this check at all if i==0. Maybe we could detect this comparison is redundant (cx >= 8 implies cx != 0), or maybe we could detect that the branch is dumb because its taken and fallthrough go to the same place (as we've already constant-folded the i*elemsize to 0, there's no phi anymore).@dr2chase @brtzsnr
The text was updated successfully, but these errors were encountered: