diff options
| author | Xiaolin Zhao <zhaoxiaolin@loongson.cn> | 2024-10-10 19:46:13 +0800 |
|---|---|---|
| committer | abner chenc <chenguoqi@loongson.cn> | 2024-10-29 01:17:54 +0000 |
| commit | aef81a75516fa10338cf2e770914fad70037c49c (patch) | |
| tree | 3e3753b99d8178bb8d6f6a3f617e0e00c4961070 /src | |
| parent | 98b3be702b05e8fc071fececf7bf44f078bf032f (diff) | |
| download | go-aef81a75516fa10338cf2e770914fad70037c49c.tar.xz | |
cmd/compile: add rules to optimize go codes to constant 0 on loong64
goos: linux
goarch: loong64
pkg: test/bench/go1
cpu: Loongson-3A6000 @ 2500.00MHz
│ old.bench │ new.bench │
│ sec/op │ sec/op vs base │
BinaryTree17 7.735 ± 1% 7.716 ± 1% -0.23% (p=0.041 n=15)
Fannkuch11 2.645 ± 0% 2.646 ± 0% +0.05% (p=0.013 n=15)
FmtFprintfEmpty 35.87n ± 0% 35.89n ± 0% +0.06% (p=0.000 n=15)
FmtFprintfString 59.54n ± 0% 59.47n ± 0% ~ (p=0.213 n=15)
FmtFprintfInt 62.23n ± 0% 62.06n ± 0% ~ (p=0.212 n=15)
FmtFprintfIntInt 98.16n ± 0% 97.90n ± 0% -0.26% (p=0.000 n=15)
FmtFprintfPrefixedInt 117.0n ± 0% 116.7n ± 0% -0.26% (p=0.000 n=15)
FmtFprintfFloat 204.6n ± 0% 204.2n ± 0% -0.20% (p=0.000 n=15)
FmtManyArgs 456.3n ± 0% 455.4n ± 0% -0.20% (p=0.000 n=15)
GobDecode 7.210m ± 0% 7.156m ± 1% -0.75% (p=0.000 n=15)
GobEncode 8.143m ± 1% 8.177m ± 1% ~ (p=0.806 n=15)
Gzip 280.2m ± 0% 279.7m ± 0% -0.19% (p=0.005 n=15)
Gunzip 32.71m ± 0% 32.65m ± 0% -0.19% (p=0.000 n=15)
HTTPClientServer 53.76µ ± 0% 53.65µ ± 0% ~ (p=0.083 n=15)
JSONEncode 9.297m ± 0% 9.295m ± 0% ~ (p=0.806 n=15)
JSONDecode 46.97m ± 1% 47.07m ± 1% ~ (p=0.683 n=15)
Mandelbrot200 4.602m ± 0% 4.600m ± 0% -0.05% (p=0.001 n=15)
GoParse 4.682m ± 0% 4.670m ± 1% -0.25% (p=0.001 n=15)
RegexpMatchEasy0_32 59.80n ± 0% 59.63n ± 0% -0.28% (p=0.000 n=15)
RegexpMatchEasy0_1K 458.3n ± 0% 457.3n ± 0% -0.22% (p=0.001 n=15)
RegexpMatchEasy1_32 59.39n ± 0% 59.23n ± 0% -0.27% (p=0.000 n=15)
RegexpMatchEasy1_1K 557.9n ± 0% 556.6n ± 0% -0.23% (p=0.001 n=15)
RegexpMatchMedium_32 803.6n ± 0% 801.8n ± 0% -0.22% (p=0.001 n=15)
RegexpMatchMedium_1K 27.32µ ± 0% 27.26µ ± 0% -0.21% (p=0.000 n=15)
RegexpMatchHard_32 1.385µ ± 0% 1.382µ ± 0% -0.22% (p=0.000 n=15)
RegexpMatchHard_1K 40.93µ ± 0% 40.83µ ± 0% -0.24% (p=0.000 n=15)
Revcomp 474.8m ± 0% 474.3m ± 0% ~ (p=0.250 n=15)
Template 77.41m ± 1% 76.63m ± 1% -1.01% (p=0.023 n=15)
TimeParse 271.1n ± 0% 271.2n ± 0% +0.04% (p=0.022 n=15)
TimeFormat 290.0n ± 0% 289.8n ± 0% ~ (p=0.118 n=15)
geomean 51.73µ 51.64µ -0.18%
Change-Id: I45a1e6c85bb3cea0f62766ec932432803e9af10a
Reviewed-on: https://go-review.googlesource.com/c/go/+/619315
Reviewed-by: Qiqi Huang <huangqiqi@loongson.cn>
Reviewed-by: Meidan Li <limeidan@loongson.cn>
Reviewed-by: abner chenc <chenguoqi@loongson.cn>
Reviewed-by: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
Diffstat (limited to 'src')
| -rw-r--r-- | src/cmd/compile/internal/ssa/_gen/LOONG64.rules | 10 | ||||
| -rw-r--r-- | src/cmd/compile/internal/ssa/rewriteLOONG64.go | 90 |
2 files changed, 100 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/ssa/_gen/LOONG64.rules b/src/cmd/compile/internal/ssa/_gen/LOONG64.rules index a5fa2ae48f..c1067c8272 100644 --- a/src/cmd/compile/internal/ssa/_gen/LOONG64.rules +++ b/src/cmd/compile/internal/ssa/_gen/LOONG64.rules @@ -646,6 +646,16 @@ (ROTR x (MOVVconst [c])) => (ROTRconst x [c&31]) (ROTRV x (MOVVconst [c])) => (ROTRVconst x [c&63]) +// If the shift amount is larger than the datasize(32, 16, 8), we can optimize to constant 0. +(MOVWUreg (SLLVconst [lc] x)) && lc >= 32 => (MOVVconst [0]) +(MOVHUreg (SLLVconst [lc] x)) && lc >= 16 => (MOVVconst [0]) +(MOVBUreg (SLLVconst [lc] x)) && lc >= 8 => (MOVVconst [0]) + +// After zero extension, the upper (64-datasize(32|16|8)) bits are zero, we can optimize to constant 0. +(SRLVconst [rc] (MOVWUreg x)) && rc >= 32 => (MOVVconst [0]) +(SRLVconst [rc] (MOVHUreg x)) && rc >= 16 => (MOVVconst [0]) +(SRLVconst [rc] (MOVBUreg x)) && rc >= 8 => (MOVVconst [0]) + // mul by constant (MULV x (MOVVconst [-1])) => (NEGV x) (MULV _ (MOVVconst [0])) => (MOVVconst [0]) diff --git a/src/cmd/compile/internal/ssa/rewriteLOONG64.go b/src/cmd/compile/internal/ssa/rewriteLOONG64.go index 9f22c99172..95fa7cd30e 100644 --- a/src/cmd/compile/internal/ssa/rewriteLOONG64.go +++ b/src/cmd/compile/internal/ssa/rewriteLOONG64.go @@ -1989,6 +1989,21 @@ func rewriteValueLOONG64_OpLOONG64MOVBUreg(v *Value) bool { v.AddArg(x) return true } + // match: (MOVBUreg (SLLVconst [lc] x)) + // cond: lc >= 8 + // result: (MOVVconst [0]) + for { + if v_0.Op != OpLOONG64SLLVconst { + break + } + lc := auxIntToInt64(v_0.AuxInt) + if !(lc >= 8) { + break + } + v.reset(OpLOONG64MOVVconst) + v.AuxInt = int64ToAuxInt(0) + return true + } // match: (MOVBUreg (MOVVconst [c])) // result: (MOVVconst [int64(uint8(c))]) for { @@ -3223,6 +3238,21 @@ func rewriteValueLOONG64_OpLOONG64MOVHUreg(v *Value) bool { v.AddArg(x) return true } + // match: (MOVHUreg (SLLVconst [lc] x)) + // cond: lc >= 16 + // result: (MOVVconst [0]) + for { + if v_0.Op != OpLOONG64SLLVconst { + break + } + lc := auxIntToInt64(v_0.AuxInt) + if !(lc >= 16) { + break + } + v.reset(OpLOONG64MOVVconst) + v.AuxInt = int64ToAuxInt(0) + return true + } // match: (MOVHUreg (MOVVconst [c])) // result: (MOVVconst [int64(uint16(c))]) for { @@ -4415,6 +4445,21 @@ func rewriteValueLOONG64_OpLOONG64MOVWUreg(v *Value) bool { v.AddArg(x) return true } + // match: (MOVWUreg (SLLVconst [lc] x)) + // cond: lc >= 32 + // result: (MOVVconst [0]) + for { + if v_0.Op != OpLOONG64SLLVconst { + break + } + lc := auxIntToInt64(v_0.AuxInt) + if !(lc >= 32) { + break + } + v.reset(OpLOONG64MOVVconst) + v.AuxInt = int64ToAuxInt(0) + return true + } // match: (MOVWUreg (MOVVconst [c])) // result: (MOVVconst [int64(uint32(c))]) for { @@ -5839,6 +5884,51 @@ func rewriteValueLOONG64_OpLOONG64SRLVconst(v *Value) bool { v.AddArg(x) return true } + // match: (SRLVconst [rc] (MOVWUreg x)) + // cond: rc >= 32 + // result: (MOVVconst [0]) + for { + rc := auxIntToInt64(v.AuxInt) + if v_0.Op != OpLOONG64MOVWUreg { + break + } + if !(rc >= 32) { + break + } + v.reset(OpLOONG64MOVVconst) + v.AuxInt = int64ToAuxInt(0) + return true + } + // match: (SRLVconst [rc] (MOVHUreg x)) + // cond: rc >= 16 + // result: (MOVVconst [0]) + for { + rc := auxIntToInt64(v.AuxInt) + if v_0.Op != OpLOONG64MOVHUreg { + break + } + if !(rc >= 16) { + break + } + v.reset(OpLOONG64MOVVconst) + v.AuxInt = int64ToAuxInt(0) + return true + } + // match: (SRLVconst [rc] (MOVBUreg x)) + // cond: rc >= 8 + // result: (MOVVconst [0]) + for { + rc := auxIntToInt64(v.AuxInt) + if v_0.Op != OpLOONG64MOVBUreg { + break + } + if !(rc >= 8) { + break + } + v.reset(OpLOONG64MOVVconst) + v.AuxInt = int64ToAuxInt(0) + return true + } // match: (SRLVconst [c] (MOVVconst [d])) // result: (MOVVconst [int64(uint64(d)>>uint64(c))]) for { |
