aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJorropo <jorropo.pgm@gmail.com>2025-11-18 01:42:37 +0100
committerGopher Robot <gobot@golang.org>2025-11-21 12:37:30 -0800
commitec92bc6d63efdbd1e04b7590b8ec3ea5236503e0 (patch)
treedf6444de3fa55fd85dab213762f592e81a2998d0 /src
parent3820f94c1d081921494ada1da64b4fab21ae1a48 (diff)
downloadgo-ec92bc6d63efdbd1e04b7590b8ec3ea5236503e0.tar.xz
cmd/compile: rewrite Rsh to RshU if arguments are proved positive
Fixes #76332 Change-Id: I9044025d5dc599531c7f88ed2870bcf3d8b0acbd Reviewed-on: https://go-review.googlesource.com/c/go/+/721206 Reviewed-by: Mark Freeman <markfreeman@google.com> Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Jorropo <jorropo.pgm@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src')
-rw-r--r--src/cmd/compile/internal/ssa/prove.go43
1 files changed, 33 insertions, 10 deletions
diff --git a/src/cmd/compile/internal/ssa/prove.go b/src/cmd/compile/internal/ssa/prove.go
index f6175a3bd7..5581da445d 100644
--- a/src/cmd/compile/internal/ssa/prove.go
+++ b/src/cmd/compile/internal/ssa/prove.go
@@ -2664,14 +2664,30 @@ var mostNegativeDividend = map[Op]int64{
OpMod64: -1 << 63,
}
var unsignedOp = map[Op]Op{
- OpDiv8: OpDiv8u,
- OpDiv16: OpDiv16u,
- OpDiv32: OpDiv32u,
- OpDiv64: OpDiv64u,
- OpMod8: OpMod8u,
- OpMod16: OpMod16u,
- OpMod32: OpMod32u,
- OpMod64: OpMod64u,
+ OpDiv8: OpDiv8u,
+ OpDiv16: OpDiv16u,
+ OpDiv32: OpDiv32u,
+ OpDiv64: OpDiv64u,
+ OpMod8: OpMod8u,
+ OpMod16: OpMod16u,
+ OpMod32: OpMod32u,
+ OpMod64: OpMod64u,
+ OpRsh8x8: OpRsh8Ux8,
+ OpRsh8x16: OpRsh8Ux16,
+ OpRsh8x32: OpRsh8Ux32,
+ OpRsh8x64: OpRsh8Ux64,
+ OpRsh16x8: OpRsh16Ux8,
+ OpRsh16x16: OpRsh16Ux16,
+ OpRsh16x32: OpRsh16Ux32,
+ OpRsh16x64: OpRsh16Ux64,
+ OpRsh32x8: OpRsh32Ux8,
+ OpRsh32x16: OpRsh32Ux16,
+ OpRsh32x32: OpRsh32Ux32,
+ OpRsh32x64: OpRsh32Ux64,
+ OpRsh64x8: OpRsh64Ux8,
+ OpRsh64x16: OpRsh64Ux16,
+ OpRsh64x32: OpRsh64Ux32,
+ OpRsh64x64: OpRsh64Ux64,
}
var bytesizeToConst = [...]Op{
@@ -2758,8 +2774,15 @@ func simplifyBlock(sdom SparseTree, ft *factsTable, b *Block) {
case OpRsh8x8, OpRsh8x16, OpRsh8x32, OpRsh8x64,
OpRsh16x8, OpRsh16x16, OpRsh16x32, OpRsh16x64,
OpRsh32x8, OpRsh32x16, OpRsh32x32, OpRsh32x64,
- OpRsh64x8, OpRsh64x16, OpRsh64x32, OpRsh64x64,
- OpLsh8x8, OpLsh8x16, OpLsh8x32, OpLsh8x64,
+ OpRsh64x8, OpRsh64x16, OpRsh64x32, OpRsh64x64:
+ if ft.isNonNegative(v.Args[0]) {
+ if b.Func.pass.debug > 0 {
+ b.Func.Warnl(v.Pos, "Proved %v is unsigned", v.Op)
+ }
+ v.Op = unsignedOp[v.Op]
+ }
+ fallthrough
+ case OpLsh8x8, OpLsh8x16, OpLsh8x32, OpLsh8x64,
OpLsh16x8, OpLsh16x16, OpLsh16x32, OpLsh16x64,
OpLsh32x8, OpLsh32x16, OpLsh32x32, OpLsh32x64,
OpLsh64x8, OpLsh64x16, OpLsh64x32, OpLsh64x64,