diff options
| author | Jake Bailey <jacob.b.bailey@gmail.com> | 2025-09-05 18:13:03 -0700 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2025-09-09 12:10:10 -0700 |
| commit | a67977da5e26e0c328488fe05bdd200903e58e99 (patch) | |
| tree | 667d10c20017962f9e0d01e72c2c6b250fb011fc /src | |
| parent | a5fa5ea51cd8fd9bcb8230d2accf9d55826f76b3 (diff) | |
| download | go-a67977da5e26e0c328488fe05bdd200903e58e99.tar.xz | |
cmd/compile/internal/inline: ignore superfluous slicing
When slicing, ignore expressions which could be elided, as in slicing
starting at 0 or ending at len(v).
Fixes #75278
Change-Id: I9c18e29c3d4da9bef89bd25bb261d3cb60e66392
Reviewed-on: https://go-review.googlesource.com/c/go/+/701216
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Mark Freeman <markfreeman@google.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/cmd/compile/internal/inline/inl.go | 11 | ||||
| -rw-r--r-- | src/cmd/compile/internal/test/inl_test.go | 1 |
2 files changed, 12 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/inline/inl.go b/src/cmd/compile/internal/inline/inl.go index b39710548e..9f03f6404a 100644 --- a/src/cmd/compile/internal/inline/inl.go +++ b/src/cmd/compile/internal/inline/inl.go @@ -738,6 +738,17 @@ opSwitch: if n.X.Op() == ir.OINDEX && isIndexingCoverageCounter(n.X) { return false } + + case ir.OSLICE, ir.OSLICEARR, ir.OSLICESTR, ir.OSLICE3, ir.OSLICE3ARR: + n := n.(*ir.SliceExpr) + + // Ignore superfluous slicing. + if n.Low != nil && n.Low.Op() == ir.OLITERAL && ir.Int64Val(n.Low) == 0 { + v.budget++ + } + if n.High != nil && n.High.Op() == ir.OLEN && n.High.(*ir.UnaryExpr).X == n.X { + v.budget += 2 + } } v.budget-- diff --git a/src/cmd/compile/internal/test/inl_test.go b/src/cmd/compile/internal/test/inl_test.go index 4e51d7d9d1..3bea11dbb1 100644 --- a/src/cmd/compile/internal/test/inl_test.go +++ b/src/cmd/compile/internal/test/inl_test.go @@ -234,6 +234,7 @@ func TestIntendedInlining(t *testing.T) { "(*B).Loop", }, "path": { + "Base", "scanChunk", }, "path/filepath": { |
