Skip to content

Commit ec70d19

Browse files
dr2chasecherrymui
authored andcommitted
cmd/compile: rewrite to elide Slicemask from len==c>0 slicing
This might have been something that prove could be educated into figuring out, but this also works, and it also helps prove downstream. Adjusted the prove test, because this change moved a message. Cherry-picked from the dev.simd branch. This CL is not necessarily SIMD specific. Apply early to reduce risk. Change-Id: I5eabe639eff5db9cd9766a6a8666fdb4973829cb Reviewed-on: https://go-review.googlesource.com/c/go/+/697715 Commit-Queue: David Chase <[email protected]> Reviewed-by: Cherry Mui <[email protected]> TryBot-Bypass: David Chase <[email protected]> Reviewed-on: https://go-review.googlesource.com/c/go/+/708858 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: David Chase <[email protected]> Reviewed-by: Junyang Shao <[email protected]>
1 parent 10e7968 commit ec70d19

File tree

3 files changed

+93
-2
lines changed

3 files changed

+93
-2
lines changed

src/cmd/compile/internal/ssa/_gen/generic.rules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,10 @@
989989
(Const64 <typ.Int> [0])
990990
(Const64 <typ.Int> [0]))
991991

992+
// Special rule to help constant slicing; len > 0 implies cap > 0 implies Slicemask is all 1
993+
(SliceMake (AddPtr <t> x (And64 y (Slicemask _))) w:(Const64 [c]) z) && c > 0 => (SliceMake (AddPtr <t> x y) w z)
994+
(SliceMake (AddPtr <t> x (And32 y (Slicemask _))) w:(Const32 [c]) z) && c > 0 => (SliceMake (AddPtr <t> x y) w z)
995+
992996
// interface ops
993997
(ConstInterface) =>
994998
(IMake

src/cmd/compile/internal/ssa/rewritegeneric.go

Lines changed: 87 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/prove.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,10 +511,10 @@ func f19() (e int64, err error) {
511511

512512
func sm1(b []int, x int) {
513513
// Test constant argument to slicemask.
514-
useSlice(b[2:8]) // ERROR "Proved slicemask not needed$"
514+
useSlice(b[2:8]) // optimized away earlier by rewrite
515515
// Test non-constant argument with known limits.
516516
if cap(b) > 10 {
517-
useSlice(b[2:])
517+
useSlice(b[2:]) // ERROR "Proved slicemask not needed$"
518518
}
519519
}
520520

0 commit comments

Comments
 (0)