diff options
Diffstat (limited to 'src/cmd/compile/internal/ssa')
-rw-r--r-- | src/cmd/compile/internal/ssa/_gen/generic.rules | 7 | ||||
-rw-r--r-- | src/cmd/compile/internal/ssa/rewritegeneric.go | 40 |
2 files changed, 47 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 diff --git a/src/cmd/compile/internal/ssa/rewritegeneric.go b/src/cmd/compile/internal/ssa/rewritegeneric.go index de7f3e8bc7..6598c0e483 100644 --- a/src/cmd/compile/internal/ssa/rewritegeneric.go +++ b/src/cmd/compile/internal/ssa/rewritegeneric.go @@ -26977,6 +26977,46 @@ func rewriteValuegeneric_OpSliceLen(v *Value) bool { v.AddArg(x) return true } + // match: (SliceLen (SelectN [0] (StaticLECall {sym} _ newLen:(Const64) _ _ _ _))) + // cond: isSameCall(sym, "runtime.growslice") + // result: newLen + for { + if v_0.Op != OpSelectN || auxIntToInt64(v_0.AuxInt) != 0 { + break + } + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpStaticLECall || len(v_0_0.Args) != 6 { + break + } + sym := auxToCall(v_0_0.Aux) + _ = v_0_0.Args[1] + newLen := v_0_0.Args[1] + if newLen.Op != OpConst64 || !(isSameCall(sym, "runtime.growslice")) { + break + } + v.copyOf(newLen) + return true + } + // match: (SliceLen (SelectN [0] (StaticLECall {sym} _ newLen:(Const32) _ _ _ _))) + // cond: isSameCall(sym, "runtime.growslice") + // result: newLen + for { + if v_0.Op != OpSelectN || auxIntToInt64(v_0.AuxInt) != 0 { + break + } + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpStaticLECall || len(v_0_0.Args) != 6 { + break + } + sym := auxToCall(v_0_0.Aux) + _ = v_0_0.Args[1] + newLen := v_0_0.Args[1] + if newLen.Op != OpConst32 || !(isSameCall(sym, "runtime.growslice")) { + break + } + v.copyOf(newLen) + return true + } return false } func rewriteValuegeneric_OpSlicePtr(v *Value) bool { |