cmd/compile: remove sign extension before MULW on riscv64

These sign extensions aren't necessary.

Change-Id: Id68ea596a18b30949d4605b2885f02e49e42d8e1
Reviewed-on: https://go-review.googlesource.com/c/go/+/699595
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
This commit is contained in:
Michael Munday 2025-08-27 23:07:36 +01:00 committed by Gopher Robot
parent 84b070bfb1
commit 27ce6e4e26
2 changed files with 5 additions and 43 deletions

View file

@ -12,9 +12,7 @@
(Mul64 ...) => (MUL ...)
(Mul64uhilo ...) => (LoweredMuluhilo ...)
(Mul64uover ...) => (LoweredMuluover ...)
(Mul32 ...) => (MULW ...)
(Mul16 x y) => (MULW (SignExt16to32 x) (SignExt16to32 y))
(Mul8 x y) => (MULW (SignExt8to32 x) (SignExt8to32 y))
(Mul(32|16|8) ...) => (MULW ...)
(Mul(64|32)F ...) => (FMUL(D|S) ...)
(Div(64|32)F ...) => (FDIV(D|S) ...)

View file

@ -405,7 +405,8 @@ func rewriteValueRISCV64(v *Value) bool {
case OpMove:
return rewriteValueRISCV64_OpMove(v)
case OpMul16:
return rewriteValueRISCV64_OpMul16(v)
v.Op = OpRISCV64MULW
return true
case OpMul32:
v.Op = OpRISCV64MULW
return true
@ -425,7 +426,8 @@ func rewriteValueRISCV64(v *Value) bool {
v.Op = OpRISCV64LoweredMuluover
return true
case OpMul8:
return rewriteValueRISCV64_OpMul8(v)
v.Op = OpRISCV64MULW
return true
case OpNeg16:
v.Op = OpRISCV64NEG
return true
@ -3255,44 +3257,6 @@ func rewriteValueRISCV64_OpMove(v *Value) bool {
}
return false
}
func rewriteValueRISCV64_OpMul16(v *Value) bool {
v_1 := v.Args[1]
v_0 := v.Args[0]
b := v.Block
typ := &b.Func.Config.Types
// match: (Mul16 x y)
// result: (MULW (SignExt16to32 x) (SignExt16to32 y))
for {
x := v_0
y := v_1
v.reset(OpRISCV64MULW)
v0 := b.NewValue0(v.Pos, OpSignExt16to32, typ.Int32)
v0.AddArg(x)
v1 := b.NewValue0(v.Pos, OpSignExt16to32, typ.Int32)
v1.AddArg(y)
v.AddArg2(v0, v1)
return true
}
}
func rewriteValueRISCV64_OpMul8(v *Value) bool {
v_1 := v.Args[1]
v_0 := v.Args[0]
b := v.Block
typ := &b.Func.Config.Types
// match: (Mul8 x y)
// result: (MULW (SignExt8to32 x) (SignExt8to32 y))
for {
x := v_0
y := v_1
v.reset(OpRISCV64MULW)
v0 := b.NewValue0(v.Pos, OpSignExt8to32, typ.Int32)
v0.AddArg(x)
v1 := b.NewValue0(v.Pos, OpSignExt8to32, typ.Int32)
v1.AddArg(y)
v.AddArg2(v0, v1)
return true
}
}
func rewriteValueRISCV64_OpNeq16(v *Value) bool {
v_1 := v.Args[1]
v_0 := v.Args[0]