go: cmd/compile: for-loops cannot be inlined
Using go devel +ed4a27a
Currently, functions with for-loops are not inline-able, would be nice if they did. Not long ago, I used a non-idiomatic goto in order to cheat around the inliner.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 16
- Comments: 24 (15 by maintainers)
Commits related to this issue
- Remove for loop in parseSize to enable inlining Using a goto based loop makes it become a leaf function which can be inlined, making us get a slight performance increase in the fast path. See: https:... — committed to wallyqs/nats-server by wallyqs 7 years ago
- Remove for loop in parseSize to enable inlining Using a goto based loop makes it become a leaf function which can be inlined, making us get a slight performance increase in the fast path. See: https:... — committed to wallyqs/nats-server by wallyqs 7 years ago
- cmd/compile: allow inlining of "for" loops We already allow inlining "if" and "goto" statements, so we might as well allow "for" loops too. The majority of frontend support is already there too. The... — committed to golang/go by mdempsky 4 years ago
- compress/flate: revert a goto for-loop In https://golang.org/cl/16528, a goto loop was chosen over a regular for loop since that would make the function inlinable. Thanks to the recent https://golan... — committed to golang/go by mvdan 4 years ago
- [dev.regabi] cmd/compile: fix latent import/export issue with break/continue In CL 145200, I changed OBREAK, OCONTINUE, OGOTO, and OLABEL to just use Sym instead of Node. However, within the export d... — committed to golang/go by mdempsky 4 years ago
- cmd/compile: allow inlining labeled for-statement and switch-statement After CL 349012 and CL 350911, we can fully handle these labeled statements, so we can allow them when inlining. Updates #14768... — committed to golang/go by wdvxdr1123 3 years ago
- cmd/compile: allow inlining of ORANGE Updates #14768 Change-Id: I33831f616eae5eeb099033e2b9cf90fa70d6ca86 Reviewed-on: https://go-review.googlesource.com/c/go/+/356869 Run-TryBot: Alberto Donizetti ... — committed to golang/go by nimelehin 3 years ago
Yes, thanks for pointing out. This is done now for 1.18. The missing cases (range loops and loops with labeled breaks/continues) are now inlineable, so all
forloops are now inlineable.Change https://golang.org/cl/256459 mentions this issue:
cmd/compile: allow inlining of "for" loopsTurns out that inlining for loops tickles (at least) two other bugs, don’t start the party yet.
A little of both. Some range loops desugar into non-trivial code (e.g., ranging over maps), so I punted on this because I expected it would be too complex… but in retrospect, all of that complexity happens after inlining anyway, so it would probably be pretty trivial actually.
We should be able to easily address this for next release, along with labeled for loops.
I will give it a look, I have a “adjust inlining parameters” CL up for review and I can try adding this one top see if it helps or hurts.
Change https://golang.org/cl/355497 mentions this issue:
cmd/compile: allow inlining labeled for-statement and switch-statementAny chance for this being fixed sometime soon? I would love to undo my re-writes where I wrote my loops using goto instead of for, so they can be inlined.
For reference, the easy part (inlining
forloops with norangeand nocontinue/break) inlines 924 additional calls ingo install stdand gives mixed results on the go1 benchmarks