diff options
| author | Ruslan Andreev <kels9009@gmail.com> | 2021-06-16 16:25:57 +0000 |
|---|---|---|
| committer | Cherry Mui <cherryyz@google.com> | 2021-10-06 13:47:50 +0000 |
| commit | 810b08b8ec28ea00bce4c008f7c1b48bc9f3e134 (patch) | |
| tree | e06230d828b77c201f7642acca57fd30a98ed3c0 /test/codegen | |
| parent | ce72766a02a4be127a26e95fbd62c4b4bb906e91 (diff) | |
| download | go-810b08b8ec28ea00bce4c008f7c1b48bc9f3e134.tar.xz | |
cmd/compile: inline memequal(x, const, sz) for small sizes
This CL adds late expanded memequal(x, const, sz) inlining for 2, 4, 8
bytes size. This PoC is using the same method as CL 248404.
This optimization fires about 100 times in Go compiler (1675 occurrences
reduced to 1574, so -6%).
Also, added unit-tests to codegen/comparisions.go file.
Updates #37275
Change-Id: Ia52808d573cb706d1da8166c5746ede26f46c5da
Reviewed-on: https://go-review.googlesource.com/c/go/+/328291
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
Trust: David Chase <drchase@google.com>
Diffstat (limited to 'test/codegen')
| -rw-r--r-- | test/codegen/comparisons.go | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/test/codegen/comparisons.go b/test/codegen/comparisons.go index 17dcd94ae1..35a181f83b 100644 --- a/test/codegen/comparisons.go +++ b/test/codegen/comparisons.go @@ -538,3 +538,65 @@ func CmpToOneU_ex2(a uint8, b uint16, c uint32, d uint64) int { } return 0 } + +// Check that small memequals are replaced with eq instructions + +func equalConstString1() bool { + a := string("A") + b := string("Z") + // amd64:-".*memequal" + // arm64:-".*memequal" + return a == b +} + +func equalVarString1(a string) bool { + b := string("Z") + // amd64:-".*memequal" + // arm64:-".*memequal" + return a[:1] == b +} + +func equalConstString2() bool { + a := string("AA") + b := string("ZZ") + // amd64:-".*memequal" + // arm64:-".*memequal" + return a == b +} + +func equalVarString2(a string) bool { + b := string("ZZ") + // amd64:-".*memequal" + // arm64:-".*memequal" + return a[:2] == b +} + +func equalConstString4() bool { + a := string("AAAA") + b := string("ZZZZ") + // amd64:-".*memequal" + // arm64:-".*memequal" + return a == b +} + +func equalVarString4(a string) bool { + b := string("ZZZZ") + // amd64:-".*memequal" + // arm64:-".*memequal" + return a[:4] == b +} + +func equalConstString8() bool { + a := string("AAAAAAAA") + b := string("ZZZZZZZZ") + // amd64:-".*memequal" + // arm64:-".*memequal" + return a == b +} + +func equalVarString8(a string) bool { + b := string("ZZZZZZZZ") + // amd64:-".*memequal" + // arm64:-".*memequal" + return a[:8] == b +} |
