Go: cmd/compile: simple functions in compress/flate, inlined in go1.10 no longer inlined

Created on 11 Sep 2018  ·  6Comments  ·  Source: golang/go

Please answer these questions before submitting your issue. Thanks!

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

tip

Does this issue reproduce with the latest release?

yes

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

ppc64le Ubuntu 16.04

What did you do?

Inspecting code from compress/flate, noticed some simple functions that I would expect to be inlined that are not.

What did you expect to see?

Functions compress/flate.byLiteral.Len, compress/flate.byLiteral.Less, compress/flate.byLiteral.Swap, compress/flate.byFreq.Len, compress/flate.byFreq.Less, compress/flate.byFreq.Swap inlined as was done in go 1.10.

What did you see instead?

No inlining for these functions on the latest branch or in go 1.11.

I just built the test in compress/flate and looked at the code. Not sure if you need more information.
I did add the -m=2 option and the output said those functions should be inlined.

../../compress/flate/huffman_code.go:321:6: can inline byLiteral.Len as: method(byLiteral) func() int { return len(s) }
../../compress/flate/huffman_code.go:323:6: can inline byLiteral.Less as: method(byLiteral) func(int, int) bool { return s[i].literal < s[j].literal }
../../compress/flate/huffman_code.go:327:6: can inline byLiteral.Swap as: method(byLiteral) func(int, int) { s[i], s[j] = s[j], s[i] }
../../compress/flate/huffman_code.go:336:6: can inline byFreq.Len as: method(byFreq) func() int { return len(s) }
../../compress/flate/huffman_code.go:338:6: can inline byFreq.Less as: method(byFreq) func(int, int) bool { if s[i].freq == s[j].freq { return s[i].literal < s[j].literal }; return s[i].freq < s[j].freq }
../../compress/flate/huffman_code.go:345:6: can inline byFreq.Swap as: method(byFreq) func(int, int) { s[i], s[j] = s[j], s[i] }

FrozenDueToAge NeedsInvestigation

Most helpful comment

Change https://golang.org/cl/135697 mentions this issue: cmd/compile/internal/gc: inline autogenerated (*T).M wrappers

All 6 comments

Forgot to mention: they aren't being inlined in the corresponding functions like these:
compress/flate.(byLiteral).Len
compress/flate.(
byLiteral).Less
compress/flate.(byLiteral).Swap
compress.flate.(
byFreq).Len
compress.flate.(byFreq).Less
compress.flate.(
byFreq).Swap

Change https://golang.org/cl/135697 mentions this issue: cmd/compile/internal/gc: inline autogenerated (*T).M wrappers

@laboger if you apply the above fix locally, is the issue resolved? If so, I'll close this as a dupe of #25338

I tried the fix above and the functions are now inlined.

@laboger thank you. Closing as a dupe of #25338.

Was this page helpful?
0 / 5 - 0 ratings