Skip to content

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

@laboger

Description

@laboger

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions