Use NEGW to produce a negated and sign extended word, rather than doing
the same via two instructions:
neg t0, t0
sext.w a0, t0
Becomes:
negw t0, t0
Change-Id: I824ab25001bd3304bdbd435e7b244fcc036ef212
Reviewed-on: https://go-review.googlesource.com/c/go/+/652319
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Mark Ryan <markdryan@rivosinc.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
(MOVHUreg (ANDI [c] x)) && c < 0 => (ANDI [int64(uint16(c))] x)
(MOVWUreg (ANDI [c] x)) && c < 0 => (AND (MOVDconst [int64(uint32(c))]) x)
+// Combine negation and sign extension.
+(MOVWreg (NEG x)) => (NEGW x)
+
// Avoid sign/zero extension for consts.
(MOVBreg (MOVDconst [c])) => (MOVDconst [int64(int8(c))])
(MOVHreg (MOVDconst [c])) => (MOVDconst [int64(int16(c))])
v.copyOf(x)
return true
}
+ // match: (MOVWreg (NEG x))
+ // result: (NEGW x)
+ for {
+ if v_0.Op != OpRISCV64NEG {
+ break
+ }
+ x := v_0.Args[0]
+ v.reset(OpRISCV64NEGW)
+ v.AddArg(x)
+ return true
+ }
// match: (MOVWreg (MOVDconst [c]))
// result: (MOVDconst [int64(int32(c))])
for {
}
func NegToInt32(a int) int {
- // riscv64: "NEG","MOVW"
+ // riscv64: "NEGW",-"MOVW"
r := int(int32(-a))
return r
}