]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: include constant bools in memcombine
authorKeith Randall <khr@golang.org>
Thu, 21 Mar 2024 16:15:30 +0000 (09:15 -0700)
committerKeith Randall <khr@golang.org>
Thu, 21 Mar 2024 19:45:41 +0000 (19:45 +0000)
Constant bools are like constant 1-byte values, they memcombine just fine.

(There are still trickier cases that this pass doesn't catch
yet, see TODO at memcombine.go:503.)

Fixes #66413

Change-Id: Ia67cf72ed1c416e27ac22da443bd88a3f09a6cc8
Reviewed-on: https://go-review.googlesource.com/c/go/+/573416
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Mauri de Souza Meneguzzo <mauri870@gmail.com>
Reviewed-by: Keith Randall <khr@google.com>
src/cmd/compile/internal/ssa/memcombine.go
test/codegen/memcombine.go

index b1a47510be2513d1901a2bd17250ded5e68865e7..a7e8ede5bca82b52295939b2d80849806ad9aa84 100644 (file)
@@ -534,7 +534,7 @@ func combineStores(root *Value, n int64) bool {
        isConst := true
        for i := int64(0); i < n; i++ {
                switch a[i].store.Args[1].Op {
-               case OpConst32, OpConst16, OpConst8:
+               case OpConst32, OpConst16, OpConst8, OpConstBool:
                default:
                        isConst = false
                        break
index 6d6c33d947ef7bed80abbac2a7a4a4b6463c1ee9..ff67a442e4b2232d2bcf99a7463bcaff568165fd 100644 (file)
@@ -918,3 +918,23 @@ func store16be(p *struct{ a, b uint16 }, x uint32) {
        // s390x:-"MOVH",-"SRW"
        p.b = uint16(x)
 }
+
+func storeBoolConst(p *struct{ a, b bool }) {
+       // amd64:"MOVW",-"MOVB"
+       // arm64:"MOVH",-"MOVB"
+       p.a = true
+       p.b = true
+}
+func issue66413(p *struct {
+       a byte
+       b bool
+       c bool
+       d int8
+}) {
+       // amd64:"MOVL",-"MOVB"
+       // arm64:"MOVW",-"MOVB"
+       p.a = 31
+       p.b = false
+       p.c = true
+       p.d = 12
+}