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

math: calls to math.Sqrt not inlined when called from other math pkg functions #17354

Closed
laboger opened this issue Oct 6, 2016 · 2 comments
Closed
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@laboger
Copy link
Contributor

laboger commented Oct 6, 2016

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version devel +91706c0 Thu Oct 6 11:45:48 2016 +0000 linux/ppc64le

What operating system and processor architecture are you using (go env)?

Ubuntu 16.04 ppc64le

What did you do?

Inspecting code in math.hypot

What did you expect to see?

Call to math.Sqrt inlined as fsqrt.

What did you see instead?

Out of line call to math.Sqrt

Simple testcase containg a call to math.Sqrt shows that it is inlined. The function f looks like this:

func f(f float64) float64 {
return math.Sqrt(f)
}

The initial ssa output for the good case looks like this:
v1 = InitMem
v2 = SP
v3 = SB DEAD
v4 = Addr <_float64> {f} v2 DEAD
v5 = Addr <_float64> {~r1} v2
v6 = Arg {f}
v7 = Const64F [0] DEAD
v8 = Sqrt v6
v9 = VarDef {~r1} v1
v10 = Store [8] v5 v8 v9
v15 = Unknown DEAD
Ret v10

Final asm looks like this: 00000 (/home/boger/gotests/test-sqrt.go:8) TEXT "".f(SB)
00001 (/home/boger/gotests/test-sqrt.go:8) FUNCDATA $0, "".gcargs·0(SB)
00002 (/home/boger/gotests/test-sqrt.go:8) FUNCDATA $1, "".gclocals·1(SB)
00003 (/home/boger/gotests/test-sqrt.go:8) TYPE "".f(FP)type.float64
00004 (/home/boger/gotests/test-sqrt.go:8) TYPE "".~r1+8(FP)type.float64
v9 00005 (/home/boger/gotests/test-sqrt.go:9) VARDEF "".~r1+8(FP)
v5 00006 (/home/boger/gotests/test-sqrt.go:9) FMOVD "".f(FP), F1
v8 00007 (/home/boger/gotests/test-sqrt.go:9) FSQRT F1, F1
v10 00008 (/home/boger/gotests/test-sqrt.go:9) FMOVD F1, "".~r1+8(FP)
b1 00009 (/home/boger/gotests/test-sqrt.go:9) RET
00010 () END

However a function in the math package like hypot is not inlining Sqrt. The initial SSA output looks like this:
b54: <- b52
v104 = Copy v130
v105 = Copy v124
v106 = Div64F v104 v105
v108 = Mul64F v106 v106
v109 = Add64F v107 v108
v111 = Copy v1
v112 = Store [8] v110 v109 v111
v113 = StaticCall {Sqrt} [16] v112
v115 = Load v114 v113
v116 = Mul64F v105 v115
v117 = VarDef {~r2} v113
v118 = Store [8] v6 v116 v117
Ret v118

And it is not inlined in this case.

This does not appear to be specific to ppc64le. I looked at an objdump on x86 and also saw a call to Sqrt from inside hypot. This happens for all the functions in the math package that call Sqrt.

@rsc rsc added this to the Go1.8 milestone Oct 6, 2016
@rsc rsc added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 6, 2016
@rsc
Copy link
Contributor

rsc commented Oct 6, 2016

Thanks. I was just talking to @cherrymui about other intrinics, so maybe he can look at this too. My guess is that the test looking for "math" as the qualified package in math.Sqrt doesn't work when compiling math itself.

@gopherbot
Copy link

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

@golang golang locked and limited conversation to collaborators Oct 6, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants