diff options
author | Keith Randall <khr@golang.org> | 2022-10-27 08:28:06 -0700 |
---|---|---|
committer | Keith Randall <khr@google.com> | 2022-10-27 17:09:50 +0000 |
commit | 0156b797e6f0d1a116a19cd852f569ec2c2eec11 (patch) | |
tree | 045ca4dc0202cb6844ff25f5096c432e9f30fea7 /src/cmd/compile/internal/ssa/_gen | |
parent | da0913f814dd4dcd28698dc5b85a3347b77b5550 (diff) | |
download | go-git-0156b797e6f0d1a116a19cd852f569ec2c2eec11.tar.gz |
cmd/compile: recognize when the result of append has a constant length
Fixes a performance regression due to CL 418554.
Fixes #56440
Change-Id: I6ff152e9b83084756363f49ee6b0844a7a284880
Reviewed-on: https://go-review.googlesource.com/c/go/+/445875
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'src/cmd/compile/internal/ssa/_gen')
-rw-r--r-- | src/cmd/compile/internal/ssa/_gen/generic.rules | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/ssa/_gen/generic.rules b/src/cmd/compile/internal/ssa/_gen/generic.rules index ccdb1d8a77..0fc0f54433 100644 --- a/src/cmd/compile/internal/ssa/_gen/generic.rules +++ b/src/cmd/compile/internal/ssa/_gen/generic.rules @@ -2539,6 +2539,13 @@ (SelectN [0] call:(StaticLECall {sym} a x)) && needRaceCleanup(sym, call) && clobber(call) => x (SelectN [0] call:(StaticLECall {sym} x)) && needRaceCleanup(sym, call) && clobber(call) => x +// When rewriting append to growslice, we use as the the new length the result of +// growslice so that we don't have to spill/restore the new length around the growslice call. +// The exception here is that if the new length is a constant, avoiding spilling it +// is pointless and its constantness is sometimes useful for subsequent optimizations. +// See issue 56440. +(SliceLen (SelectN [0] (StaticLECall {sym} _ newLen:(Const(64|32)) _ _ _ _))) && isSameCall(sym, "runtime.growslice") => newLen + // Collapse moving A -> B -> C into just A -> C. // Later passes (deadstore, elim unread auto) will remove the A -> B move, if possible. // This happens most commonly when B is an autotmp inserted earlier |