-
Notifications
You must be signed in to change notification settings - Fork 17.6k
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: large shifts miscompiled on riscv64 #64285
Comments
Note that this is a test of a new API added for Go 1.22 (#61716). |
Change https://go.dev/cl/543716 mentions this issue: |
Change https://go.dev/cl/543895 mentions this issue: |
This reverts commit 6382893. Reason for revert: Causes failures on big endian platforms and riscv64. Possibly a bug in the generic implementation. For #64284. For #64285. Change-Id: Ic1bb8533d9641fae28d0337b36d434b9a575cd7e Reviewed-on: https://go-review.googlesource.com/c/go/+/543895 Reviewed-by: Heschi Kreinick <heschi@google.com> Auto-Submit: Michael Knyszek <mknyszek@google.com> TryBot-Bypass: Michael Knyszek <mknyszek@google.com>
/cc @markdryan This code is triggering a code generation bug in the riscv64 rewrite rules (presumably introduced by https://go.dev/cl/528975 - 561bf04). I'm investigating a fix. |
@4a6f656c Thanks for letting me know. I can reproduce this locally as well and can confirm that the issue goes away with https://go-review.googlesource.com/c/go/+/528975 and https://go-review.googlesource.com/c/go/+/535115 reverted. The reproducer is embarrassingly simple.
This should print
but it actually prints
Without the patches, badShift generates
and with them it generates
which obviously isn't going to zero what was originally a 32 bit value in the same way that shifting by 0x38 will. |
The issue is also reproducible with variable shifts, e.g.,
where s > 32 e.g.,
also prints
|
@4a6f656c do let me know if there's anything I can do to help. Note that removing
and modifying the 32 bit shift rules directly, for example by replacing
with
does fix the issue, at the cost of missing out on the optimisation that is causing the problem, i.e., this disables the broken optimisation for uint64(c) >> s (where c is an uint32) rather than fixing it, while retaining the optimisations for shifts of 32 bit ints. Perhaps there's a more elegant solutions though, ... |
@markdryan thanks for investigating/confirming. Unfortunately, my suggestion to optimise more generally has lead to a problem where by a valid type conversion and overflow shift is resulting in bad/incorrect code. The following two rules:
result in |
Change https://go.dev/cl/545035 mentions this issue: |
Thanks @4a6f656c. I'll give the patch a good test this morning. |
Change https://go.dev/cl/546020 mentions this issue: |
This is a replay of CL 516859, after its rollback in CL 543895, with big-endian systems fixed and the tests disabled on RISC-V since the compiler is broken there (#64285). ChaCha8 provides a cryptographically strong generator alongside PCG, so that people who want stronger randomness have access to that. On systems with 128-bit vector math assembly (amd64 and arm64), ChaCha8 runs at about the same speed as PCG (25% slower on amd64, 2% faster on arm64). Fixes #64284. Change-Id: I6290bb8ace28e1aff9a61f805dbe380ccdf25b94 Reviewed-on: https://go-review.googlesource.com/c/go/+/546020 Reviewed-by: Filippo Valsorda <filippo@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This is a replay of CL 516859, after its rollback in CL 543895, with big-endian systems fixed and the tests disabled on RISC-V since the compiler is broken there (golang#64285). ChaCha8 provides a cryptographically strong generator alongside PCG, so that people who want stronger randomness have access to that. On systems with 128-bit vector math assembly (amd64 and arm64), ChaCha8 runs at about the same speed as PCG (25% slower on amd64, 2% faster on arm64). Fixes golang#64284. Change-Id: I6290bb8ace28e1aff9a61f805dbe380ccdf25b94 Reviewed-on: https://go-review.googlesource.com/c/go/+/546020 Reviewed-by: Filippo Valsorda <filippo@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
https://build.golang.org/log/2031961837b8091c07edd2b489ea824efae86fe6:
(attn @rsc @FiloSottile @golang/riscv64)
The text was updated successfully, but these errors were encountered: