Skip to content

cmd/compile: wrong shift code generation #12133

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

Closed
brtzsnr opened this issue Aug 13, 2015 · 8 comments
Closed

cmd/compile: wrong shift code generation #12133

brtzsnr opened this issue Aug 13, 2015 · 8 comments
Milestone

Comments

@brtzsnr
Copy link
Contributor

brtzsnr commented Aug 13, 2015

Edit: the bug manifests on master.

The following code:

package main
import "fmt"
func main() {
fmt.Println(f1())
}
func f1() uint {
switch {} // prevent inlining
v1 := uint8(4) // uint8
v2 := uint8(3) // uint8
v3 := uint(2) // uint
return uint(5) << (uint(2) + uint(4) >> (v1) - uint(v1) >> (uint16(0)) >> (uint16(v2)) - v3)
}
% GOROOT=~/go1.4 ~/go1.4/bin/go version
go version go1.4.1 linux/amd64
% GOROOT=~/go1.4 ~/go1.4/bin/go run ../issue12133-1.go 
5

% go version
go version devel +cda1fc0 Wed Aug 12 20:31:26 2015 +0000 linux/amd64
% go run ../issue12133-1.go                           
0

Another example:

package main
import "fmt"
func main() {
fmt.Println(f1())
}
func f1() int64 {
switch {} // prevent inlining
v1 := uint16(7) // uint16
v2 := v1 * uint16(int8(v1)) + 8 // uint16
v3 := v2 // uint16
v4 := v3 // uint16
v5 := v4 // uint16
return 1 * (2 >> 7) - 8 << (v5 * 5 * v2 + v2 + 1 << v5) + int64(v4) * int64(v5) - int64(v5) >> uint(8 >> v1) - int64(v3) - 6 + 8 << uint8(v3) - 3 << uint64(1 << 6 + 5 + 3 * uint(v2) + 6 - uint(v4) << (9 * 8))
}

prints 1152921504606850105 with go1.4 http://play.golang.org/p/mZ3HZnFP0E
and prints 3129 with the latest code on master

@brtzsnr brtzsnr changed the title dev.ssa: wrong shift code generation wrong shift code generation Aug 13, 2015
@brtzsnr
Copy link
Contributor Author

brtzsnr commented Aug 13, 2015

A simpler testcase:

package main
import "fmt"
func main() {
fmt.Println(f1())
}
func f1() uint {
v1 := uint(48) 
return v1 >> ((1 >> v1) + (1 >> v1))
}                     

Should print 48, but the last version returns 0.

@ianlancetaylor ianlancetaylor changed the title wrong shift code generation cmd/compile: wrong shift code generation Aug 13, 2015
@ianlancetaylor ianlancetaylor added this to the Go1.5Maybe milestone Aug 13, 2015
@ianlancetaylor
Copy link
Member

CC @rsc

@randall77
Copy link
Contributor

Bisect says this is the culprit: https://go-review.googlesource.com/#/c/7853/

Author: Russ Cox rsc@golang.org
Date: Wed Mar 18 17:26:36 2015 -0400

cmd/internal/gc: move cgen, regalloc, et al to portable code

@randall77
Copy link
Contributor

CL out for review (why didn't Gerrit update this bug?): https://go-review.googlesource.com/13630

@gopherbot
Copy link
Contributor

CL https://golang.org/cl/13630 mentions this issue.

@gopherbot
Copy link
Contributor

CL https://golang.org/cl/13650 mentions this issue.

@rsc
Copy link
Contributor

rsc commented Aug 15, 2015

@randall77 The update come from a cron job. I think it's once an hour or something like that.

@rsc rsc closed this as completed in e97ab0a Aug 15, 2015
@mikioh mikioh modified the milestones: Go1.5, Go1.5Maybe Aug 15, 2015
@davecheney
Copy link
Contributor

Reopening because this change broke */arm64. Fix proposed in https://golang.org/cl/13650

@davecheney davecheney reopened this Aug 15, 2015
@golang golang locked and limited conversation to collaborators Aug 22, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants