aboutsummaryrefslogtreecommitdiff
path: root/test/codegen
diff options
context:
space:
mode:
authorMichael Munday <mndygolang+git@gmail.com>2025-08-26 21:17:36 +0100
committerGopher Robot <gobot@golang.org>2025-11-14 10:59:56 -0800
commit0a569528ea355099af864f7612c3fa1973df30e4 (patch)
tree189f828573801d88d072ebd988ae1d553d2a8afa /test/codegen
parent1e5e6663e958dcc9579fb38ffcd8a1999d75128d (diff)
downloadgo-0a569528ea355099af864f7612c3fa1973df30e4.tar.xz
cmd/compile: optimize comparisons with single bit difference
Optimize comparisons with constants that only differ by 1 bit (i.e. a power of 2). For example: x == 4 || x == 6 -> x|2 == 6 x != 1 && x != 5 -> x|4 != 5 Change-Id: Ic61719e5118446d21cf15652d9da22f7d95b2a15 Reviewed-on: https://go-review.googlesource.com/c/go/+/719420 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Junyang Shao <shaojunyang@google.com> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com>
Diffstat (limited to 'test/codegen')
-rw-r--r--test/codegen/fuse.go120
1 files changed, 120 insertions, 0 deletions
diff --git a/test/codegen/fuse.go b/test/codegen/fuse.go
index 4fbb03bef8..e5a28549dc 100644
--- a/test/codegen/fuse.go
+++ b/test/codegen/fuse.go
@@ -198,6 +198,126 @@ func ui4d(c <-chan uint8) {
}
}
+// ------------------------------------ //
+// single bit difference (conjunction) //
+// ------------------------------------ //
+
+func sisbc64(c <-chan int64) {
+ // amd64: "ORQ [$]2,"
+ // riscv64: "ORI [$]2,"
+ for x := <-c; x != 4 && x != 6; x = <-c {
+ }
+}
+
+func sisbc32(c <-chan int32) {
+ // amd64: "ORL [$]4,"
+ // riscv64: "ORI [$]4,"
+ for x := <-c; x != -1 && x != -5; x = <-c {
+ }
+}
+
+func sisbc16(c <-chan int16) {
+ // amd64: "ORL [$]32,"
+ // riscv64: "ORI [$]32,"
+ for x := <-c; x != 16 && x != 48; x = <-c {
+ }
+}
+
+func sisbc8(c <-chan int8) {
+ // amd64: "ORL [$]16,"
+ // riscv64: "ORI [$]16,"
+ for x := <-c; x != -15 && x != -31; x = <-c {
+ }
+}
+
+func uisbc64(c <-chan uint64) {
+ // amd64: "ORQ [$]4,"
+ // riscv64: "ORI [$]4,"
+ for x := <-c; x != 1 && x != 5; x = <-c {
+ }
+}
+
+func uisbc32(c <-chan uint32) {
+ // amd64: "ORL [$]4,"
+ // riscv64: "ORI [$]4,"
+ for x := <-c; x != 2 && x != 6; x = <-c {
+ }
+}
+
+func uisbc16(c <-chan uint16) {
+ // amd64: "ORL [$]32,"
+ // riscv64: "ORI [$]32,"
+ for x := <-c; x != 16 && x != 48; x = <-c {
+ }
+}
+
+func uisbc8(c <-chan uint8) {
+ // amd64: "ORL [$]64,"
+ // riscv64: "ORI [$]64,"
+ for x := <-c; x != 64 && x != 0; x = <-c {
+ }
+}
+
+// ------------------------------------ //
+// single bit difference (disjunction) //
+// ------------------------------------ //
+
+func sisbd64(c <-chan int64) {
+ // amd64: "ORQ [$]2,"
+ // riscv64: "ORI [$]2,"
+ for x := <-c; x == 4 || x == 6; x = <-c {
+ }
+}
+
+func sisbd32(c <-chan int32) {
+ // amd64: "ORL [$]4,"
+ // riscv64: "ORI [$]4,"
+ for x := <-c; x == -1 || x == -5; x = <-c {
+ }
+}
+
+func sisbd16(c <-chan int16) {
+ // amd64: "ORL [$]32,"
+ // riscv64: "ORI [$]32,"
+ for x := <-c; x == 16 || x == 48; x = <-c {
+ }
+}
+
+func sisbd8(c <-chan int8) {
+ // amd64: "ORL [$]16,"
+ // riscv64: "ORI [$]16,"
+ for x := <-c; x == -15 || x == -31; x = <-c {
+ }
+}
+
+func uisbd64(c <-chan uint64) {
+ // amd64: "ORQ [$]4,"
+ // riscv64: "ORI [$]4,"
+ for x := <-c; x == 1 || x == 5; x = <-c {
+ }
+}
+
+func uisbd32(c <-chan uint32) {
+ // amd64: "ORL [$]4,"
+ // riscv64: "ORI [$]4,"
+ for x := <-c; x == 2 || x == 6; x = <-c {
+ }
+}
+
+func uisbd16(c <-chan uint16) {
+ // amd64: "ORL [$]32,"
+ // riscv64: "ORI [$]32,"
+ for x := <-c; x == 16 || x == 48; x = <-c {
+ }
+}
+
+func uisbd8(c <-chan uint8) {
+ // amd64: "ORL [$]64,"
+ // riscv64: "ORI [$]64,"
+ for x := <-c; x == 64 || x == 0; x = <-c {
+ }
+}
+
// -------------------------------------//
// merge NaN checks //
// ------------------------------------ //