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: SSA runtime performance regression on function with multiple idiv instructions #16061

Closed
ALTree opened this issue Jun 14, 2016 · 2 comments

Comments

@ALTree
Copy link
Member

ALTree commented Jun 14, 2016

$ gotip version
go version devel +53242e4 Tue Jun 14 05:17:57 2016 +0000 linux/amd64

code:

package foo

import "testing"

func maxRem(a int32) int32 {
    maxR := int32(0)
    m := a * a
    r1, r2 := a+1, a-1
    for n := int32(1); n <= a*a; n++ {
        r1 = (r1 * (a + 1)) % m
        r2 = (r2 * (a - 1)) % m
        if r := (r1 + r2) % m; maxR < r {
            maxR = r
        }
    }
    return maxR
}

var sink int32

func BenchmarkMaxRem(b *testing.B) {
    for n := 0; n < b.N; n++ {
        sink = maxRem(100)
    }
}

go1.6 vs tip:

name      old time/op  new time/op  delta
MaxRem-4   116µs ± 1%   134µs ± 2%  +15.48%  (p=0.000 n=8+8)

same function with int64 is also slower, by ~5%.

@ianlancetaylor ianlancetaylor added this to the Go1.8 milestone Jun 14, 2016
@randall77
Copy link
Contributor

Looks like the SSA code does a bunch of spilling to the stack where the legacy compiler doesn't. The divide instructions require values in specific registers. Given two subsequent divide instructions, the result of the first needs to be moved somewhere else before the second is issued. SSA uses a stack slot for that, whereas the legacy compiler uses a register.
This will be a bit tricky to fix, but it is possible. 1.8 milestone sounds right.

@ALTree ALTree changed the title cmd/compile: SSA runtime performance regression on 32bit arithmetic cmd/compile: SSA runtime performance regression on function with multiple idiv instructions Jun 14, 2016
@gopherbot
Copy link

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

@golang golang locked and limited conversation to collaborators Sep 27, 2017
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

4 participants