Skip to content
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: incorrect 64->32 narrowing optimization #62360

Closed
randall77 opened this issue Aug 29, 2023 · 1 comment
Closed

cmd/compile: incorrect 64->32 narrowing optimization #62360

randall77 opened this issue Aug 29, 2023 · 1 comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge

Comments

@randall77
Copy link
Contributor

randall77 commented Aug 29, 2023

package main

import (
	"fmt"
	"math/big"
)

//go:noinline
func f(x uint32) *big.Int {
	return big.NewInt(int64(x))
}
func main() {
	b := f(0xffffffff)
	c := big.NewInt(0xffffffff)
	if b.Cmp(c) != 0 {
		panic(fmt.Sprintf("b:%x c:%x", b, c))
	}
}

The problem is with CL 522975 @jake-ciolek .

I think the issue is that when we change TESTQ to TESTL, a different bit gets copied into the sign bit of the flags register. We previously copied bit 63 (which is zero in the code above) but now we copy bit 31 (which is 1 in the code above).

So the TEST rule in that CL isn't correct. It would work if we just used the result for == or !=, but when we use the results for ordering comparisons it doesn't work.

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Aug 29, 2023
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/524255 mentions this issue: Revert "cmd/compile: use shorter ANDL/TESTL if upper 32 bits are known to be zero"

@golang golang locked and limited conversation to collaborators Aug 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge
Projects
None yet
Development

No branches or pull requests

2 participants