cmd/compile: simplify negative on multiplication

goos: linux
goarch: amd64
pkg: cmd/compile/internal/test
cpu: AMD EPYC 7532 32-Core Processor
               │       simplify_base │               simplify_new          │
               │       sec/op        │   sec/op     vs base                │
SimplifyNegMul           623.0n ± 0%   319.3n ± 1%  -48.75% (p=0.000 n=10)

goos: linux
goarch: riscv64
pkg: cmd/compile/internal/test
cpu: Spacemit(R) X60
               │       simplify.base │               simplify.new          │
               │       sec/op        │   sec/op     vs base                │
SimplifyNegMul          10.928µ ± 0%   6.432µ ± 0%  -41.14% (p=0.000 n=10)

Change-Id: I1d9393cd19a0b948a5d3a512d627cdc0cf0b38be
Reviewed-on: https://go-review.googlesource.com/c/go/+/721520
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Mark Freeman <markfreeman@google.com>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
Meng Zhuo 2025-11-18 09:53:21 +08:00 committed by Gopher Robot
parent 35d2712b32
commit e7d47ac33d
4 changed files with 228 additions and 0 deletions

View file

@ -337,11 +337,26 @@ func Mul32(a, b int32) int64 {
// arm64:"SMULL" -"MOVW"
return int64(a) * int64(b)
}
func Mul32U(a, b uint32) uint64 {
// arm64:"UMULL" -"MOVWU"
return uint64(a) * uint64(b)
}
func SimplifyNegMulConst(a int) int {
// amd64:-"NEGQ"
// arm64:"MOVD [$]11" "MUL" -"NEG"
// riscv64:"MOV [$]11" "MUL" -"NEG"
return -(a * -11)
}
func SimplifyNegMul(a, b int) int {
// amd64:-"NEGQ"
// arm64:"MUL" -"NEG"
// riscv64:"MUL" -"NEG"
return -(-a * b)
}
// -------------- //
// Division //
// -------------- //