]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: introduce bytesizeToConst to cleanup switches in prove
authorJorropo <jorropo.pgm@gmail.com>
Sun, 26 Oct 2025 14:53:51 +0000 (15:53 +0100)
committerJorropo <jorropo.pgm@gmail.com>
Tue, 28 Oct 2025 06:24:29 +0000 (23:24 -0700)
Change-Id: I32b45d9632a8131911cb9bd6eff075eb8312ccfd
Reviewed-on: https://go-review.googlesource.com/c/go/+/715043
Auto-Submit: Jorropo <jorropo.pgm@gmail.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/ssa/prove.go

index 168bb29984a30f75fe575cb20e3a546ff34919bb..e38dd4a838623618576f76779511629515a301e1 100644 (file)
@@ -2640,6 +2640,13 @@ var mostNegativeDividend = map[Op]int64{
        OpDiv64: -1 << 63,
        OpMod64: -1 << 63}
 
+var bytesizeToConst = [...]Op{
+       8 / 8:  OpConst8,
+       16 / 8: OpConst16,
+       32 / 8: OpConst32,
+       64 / 8: OpConst64,
+}
+
 // simplifyBlock simplifies some constant values in b and evaluates
 // branches to non-uniquely dominated successors of b.
 func simplifyBlock(sdom SparseTree, ft *factsTable, b *Block) {
@@ -2702,18 +2709,7 @@ func simplifyBlock(sdom SparseTree, ft *factsTable, b *Block) {
                                if b.Func.pass.debug > 0 {
                                        b.Func.Warnl(v.Pos, "Proved %v shifts to zero", v.Op)
                                }
-                               switch bits {
-                               case 64:
-                                       v.reset(OpConst64)
-                               case 32:
-                                       v.reset(OpConst32)
-                               case 16:
-                                       v.reset(OpConst16)
-                               case 8:
-                                       v.reset(OpConst8)
-                               default:
-                                       panic("unexpected integer size")
-                               }
+                               v.reset(bytesizeToConst[bits/8])
                                v.AuxInt = 0
                                break // Be sure not to fallthrough - this is no longer OpRsh.
                        }