Skip to content

cmd/compile: SSA compiler removes code in benchmarks #14813

Closed
@ainar-g

Description

@ainar-g

Go version: go version devel +2dcbbbd Mon Mar 14 05:13:47 2016 +0000 linux/amd64

Go env:

GOARCH="amd64"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"

This code is a simple benchmark of Hamming weight algorithms: http://play.golang.org/p/kOid3lX9Yz

In Go 1.6 running go test popcnt_test.go -bench . gives the result:

testing: warning: no tests to run
PASS
BenchmarkPopcnt-4   50000000            27.1 ns/op
BenchmarkPopcnt2-4  1000000000           2.90 ns/op
ok      command-line-arguments  4.567s

But on tip with SSA turned on it's

testing: warning: no tests to run
BenchmarkPopcnt-4   100000000           24.0 ns/op
BenchmarkPopcnt2-4  2000000000           0.41 ns/op
PASS
ok      command-line-arguments  3.286s

Running with -gcflags "-S" confirms that the tip version completely removes the call to popcnt2. If I add //go:noinline before popcnt2 definition, it works fine (although slower than 1.6 because it doesn't inline):

testing: warning: no tests to run
BenchmarkPopcnt-4   50000000            22.9 ns/op
BenchmarkPopcnt2-4  300000000            4.42 ns/op
PASS
ok      command-line-arguments  2.946s

Same goes for running with -gcflags "-ssa=0", the call isn't removed.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions