From: Xiaolin Zhao Date: Mon, 1 Dec 2025 06:46:23 +0000 (+0800) Subject: cmd/compile: avoid extending when already sufficiently shifted on loong64 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=021d5ca042775537d707c6f5ae2f53f57dac243f;p=gostls13.git cmd/compile: avoid extending when already sufficiently shifted on loong64 This reduces 744 instructions from the go toolchain binary on loong64. file before after Δ % asm 599282 599222 -60 -0.0100% cgo 513606 513534 -72 -0.0140% compile 2939250 2939146 -104 -0.0035% cover 564136 564056 -80 -0.0142% fix 895622 895546 -76 -0.0085% link 759460 759376 -84 -0.0111% preprofile 264960 264916 -44 -0.0166% vet 869964 869888 -76 -0.0087% go 1712990 1712890 -100 -0.0058% gofmt 346416 346368 -48 -0.0139% total 9465686 9464942 -744 -0.0079% Change-Id: I32dfa7506d0458ca0b6de83b030c330cd2b82176 Reviewed-on: https://go-review.googlesource.com/c/go/+/725720 Auto-Submit: Keith Randall LUCI-TryBot-Result: Go LUCI Reviewed-by: Keith Randall Reviewed-by: Carlos Amedee Reviewed-by: Keith Randall --- diff --git a/src/cmd/compile/internal/ssa/_gen/LOONG64.rules b/src/cmd/compile/internal/ssa/_gen/LOONG64.rules index b15043032c..a40603e93d 100644 --- a/src/cmd/compile/internal/ssa/_gen/LOONG64.rules +++ b/src/cmd/compile/internal/ssa/_gen/LOONG64.rules @@ -843,6 +843,11 @@ (MOVBUreg (ANDconst [c] x)) => (ANDconst [c&0xff] x) +// Avoid extending when already sufficiently shifted. +(MOVBUreg x:(SRLconst [c] y)) && c >= 24 => x +(MOVHUreg x:(SRLconst [c] y)) && c >= 16 => x +(MOVWUreg x:(SRLconst [c] y)) => x + // Avoid extending when already sufficiently masked. (MOVBreg x:(ANDconst [c] y)) && c >= 0 && int64(int8(c)) == c => x (MOVHreg x:(ANDconst [c] y)) && c >= 0 && int64(int16(c)) == c => x diff --git a/src/cmd/compile/internal/ssa/rewriteLOONG64.go b/src/cmd/compile/internal/ssa/rewriteLOONG64.go index 30ce419d40..37aedcbe6e 100644 --- a/src/cmd/compile/internal/ssa/rewriteLOONG64.go +++ b/src/cmd/compile/internal/ssa/rewriteLOONG64.go @@ -2677,6 +2677,21 @@ func rewriteValueLOONG64_OpLOONG64MOVBUreg(v *Value) bool { v.AddArg(x) return true } + // match: (MOVBUreg x:(SRLconst [c] y)) + // cond: c >= 24 + // result: x + for { + x := v_0 + if x.Op != OpLOONG64SRLconst { + break + } + c := auxIntToInt64(x.AuxInt) + if !(c >= 24) { + break + } + v.copyOf(x) + return true + } // match: (MOVBUreg x:(ANDconst [c] y)) // cond: c >= 0 && int64(uint8(c)) == c // result: x @@ -4067,6 +4082,21 @@ func rewriteValueLOONG64_OpLOONG64MOVHUreg(v *Value) bool { v.AuxInt = int64ToAuxInt(int64(uint16(c))) return true } + // match: (MOVHUreg x:(SRLconst [c] y)) + // cond: c >= 16 + // result: x + for { + x := v_0 + if x.Op != OpLOONG64SRLconst { + break + } + c := auxIntToInt64(x.AuxInt) + if !(c >= 16) { + break + } + v.copyOf(x) + return true + } // match: (MOVHUreg x:(ANDconst [c] y)) // cond: c >= 0 && int64(uint16(c)) == c // result: x @@ -5301,6 +5331,16 @@ func rewriteValueLOONG64_OpLOONG64MOVWUreg(v *Value) bool { v.AuxInt = int64ToAuxInt(int64(uint32(c))) return true } + // match: (MOVWUreg x:(SRLconst [c] y)) + // result: x + for { + x := v_0 + if x.Op != OpLOONG64SRLconst { + break + } + v.copyOf(x) + return true + } // match: (MOVWUreg x:(ANDconst [c] y)) // cond: c >= 0 && int64(uint32(c)) == c // result: x