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: Some bounds checks are not eliminated in arguments to append #19692
Comments
cc @brtzsnr |
I haven't dug into this, but I strongly suspect that the problem is that the argument to append gets assigned to a temp, and BCE doesn't propagate through the temp appropriately. |
For func AppendHexHi2(buf []byte, b byte) []byte {
h := hex[b >> 4]
return append(buf, h)
} the bounds check is eliminated here in the call to In func AppendHexHi(buf []byte, b byte) []byte { return append(buf, hex[b >> 4]) } BCE does not work, because the right shift expression is assigned to a temp node (so the right node of the index expression is ONAME, not ORSH). and Maybe someone can give a hint? |
I think it just needs a new generic ssa rule along the lines of:
I need to think a bit more to make sure this is right, though, and also generalize it to other widths and variants. |
CL https://golang.org/cl/43775 mentions this issue. |
We may have missed the 1.9 window for these, not sure. Mailed a CL. If/when that CL goes in, I plan to repurpose this issue to be able removing bounded from walk.go and doing all these optimizations in SSA form, which would have prevented this issue from arising in the first place. We're close on that--I think we just need to add some division-based rules and do some testing. |
These rules trigger a few times during make.bash. When we eliminate boundedness checks from walk.go we'll rely on them more heavily. Updates golang#19692 Change-Id: I268c36ae2f1401c68dd685b15f2d30f5d6971176
These rules trigger a few times during make.bash. When we eliminate boundedness checks from walk.go we'll rely on them more heavily. Updates #19692 Change-Id: I268c36ae2f1401c68dd685b15f2d30f5d6971176 Reviewed-on: https://go-review.googlesource.com/43775 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
@josharian, since this issue is pretty old, maybe open a new issue tracking the idea to move bounded into SSA and close this one? |
I have some work in progress locally to move bounded into SSA. It's pretty close, just a few minor regalloc sticking points. So I'll close this now and not bother with a new issue. :) Thanks for the ping. |
Please answer these questions before submitting your issue. Thanks!
What did you do?
Hello up there. Please consider the following function:
(https://play.golang.org/p/-IHVJrTcq4)
When it is compiled the bounds check for
hex[b >> 4]
is not eliminated:However if I write it this way:
there is no bounds check generated:
Bounds checking is also not generated for
hex[b & 0xf]
irregardless of where it is under append or not:Seem being under append affects only shifts.
What did you expect to see?
No bounds checking is generated for all cases.
What did you see instead?
Bounds checking was generated for
append(buf, hex[b >> 4])
Does this issue reproduce with the latest release (go1.8)?
Yes, but there bounds checking is also emitted for
AppendHexLo
.System details
Thanks beforehand,
Kirill
/cc @randall77
The text was updated successfully, but these errors were encountered: