mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile/internal/ssa: correct sign extension for consts on riscv64
Correct sign extension handling for consts on riscv64. This fixes a bug
in part exposed by CL 302609 - previously 64 bit consts were rewritten into
multiple 32 bit consts and the expansion would result in sign/zero extension
not being eliminated. With this change a MOVDconst with a 64 bit value can be
followed by a MOV{B,H,W}reg, which will be eliminated without actually
truncating to a smaller value.
Change-Id: I8d9cd380217466997b341e008a1f139bc11a0d51
Reviewed-on: https://go-review.googlesource.com/c/go/+/303350
Trust: Joel Sing <joel@sing.id.au>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
parent
5437b5a24b
commit
8fd0f83552
2 changed files with 9 additions and 9 deletions
|
|
@ -607,9 +607,9 @@
|
||||||
(MOVDstore [off] {sym} ptr (MOVDconst [0]) mem) => (MOVDstorezero [off] {sym} ptr mem)
|
(MOVDstore [off] {sym} ptr (MOVDconst [0]) mem) => (MOVDstorezero [off] {sym} ptr mem)
|
||||||
|
|
||||||
// Avoid sign/zero extension for consts.
|
// Avoid sign/zero extension for consts.
|
||||||
(MOVBreg (MOVDconst [c])) => (MOVDconst [int64(c)])
|
(MOVBreg (MOVDconst [c])) => (MOVDconst [int64(int8(c))])
|
||||||
(MOVHreg (MOVDconst [c])) => (MOVDconst [int64(c)])
|
(MOVHreg (MOVDconst [c])) => (MOVDconst [int64(int16(c))])
|
||||||
(MOVWreg (MOVDconst [c])) => (MOVDconst [int64(c)])
|
(MOVWreg (MOVDconst [c])) => (MOVDconst [int64(int32(c))])
|
||||||
(MOVBUreg (MOVDconst [c])) => (MOVDconst [int64(uint8(c))])
|
(MOVBUreg (MOVDconst [c])) => (MOVDconst [int64(uint8(c))])
|
||||||
(MOVHUreg (MOVDconst [c])) => (MOVDconst [int64(uint16(c))])
|
(MOVHUreg (MOVDconst [c])) => (MOVDconst [int64(uint16(c))])
|
||||||
(MOVWUreg (MOVDconst [c])) => (MOVDconst [int64(uint32(c))])
|
(MOVWUreg (MOVDconst [c])) => (MOVDconst [int64(uint32(c))])
|
||||||
|
|
|
||||||
|
|
@ -2985,14 +2985,14 @@ func rewriteValueRISCV64_OpRISCV64MOVBreg(v *Value) bool {
|
||||||
v_0 := v.Args[0]
|
v_0 := v.Args[0]
|
||||||
b := v.Block
|
b := v.Block
|
||||||
// match: (MOVBreg (MOVDconst [c]))
|
// match: (MOVBreg (MOVDconst [c]))
|
||||||
// result: (MOVDconst [int64(c)])
|
// result: (MOVDconst [int64(int8(c))])
|
||||||
for {
|
for {
|
||||||
if v_0.Op != OpRISCV64MOVDconst {
|
if v_0.Op != OpRISCV64MOVDconst {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
c := auxIntToInt64(v_0.AuxInt)
|
c := auxIntToInt64(v_0.AuxInt)
|
||||||
v.reset(OpRISCV64MOVDconst)
|
v.reset(OpRISCV64MOVDconst)
|
||||||
v.AuxInt = int64ToAuxInt(int64(c))
|
v.AuxInt = int64ToAuxInt(int64(int8(c)))
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
// match: (MOVBreg x:(MOVBload _ _))
|
// match: (MOVBreg x:(MOVBload _ _))
|
||||||
|
|
@ -3638,14 +3638,14 @@ func rewriteValueRISCV64_OpRISCV64MOVHreg(v *Value) bool {
|
||||||
v_0 := v.Args[0]
|
v_0 := v.Args[0]
|
||||||
b := v.Block
|
b := v.Block
|
||||||
// match: (MOVHreg (MOVDconst [c]))
|
// match: (MOVHreg (MOVDconst [c]))
|
||||||
// result: (MOVDconst [int64(c)])
|
// result: (MOVDconst [int64(int16(c))])
|
||||||
for {
|
for {
|
||||||
if v_0.Op != OpRISCV64MOVDconst {
|
if v_0.Op != OpRISCV64MOVDconst {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
c := auxIntToInt64(v_0.AuxInt)
|
c := auxIntToInt64(v_0.AuxInt)
|
||||||
v.reset(OpRISCV64MOVDconst)
|
v.reset(OpRISCV64MOVDconst)
|
||||||
v.AuxInt = int64ToAuxInt(int64(c))
|
v.AuxInt = int64ToAuxInt(int64(int16(c)))
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
// match: (MOVHreg x:(MOVBload _ _))
|
// match: (MOVHreg x:(MOVBload _ _))
|
||||||
|
|
@ -4129,14 +4129,14 @@ func rewriteValueRISCV64_OpRISCV64MOVWreg(v *Value) bool {
|
||||||
v_0 := v.Args[0]
|
v_0 := v.Args[0]
|
||||||
b := v.Block
|
b := v.Block
|
||||||
// match: (MOVWreg (MOVDconst [c]))
|
// match: (MOVWreg (MOVDconst [c]))
|
||||||
// result: (MOVDconst [int64(c)])
|
// result: (MOVDconst [int64(int32(c))])
|
||||||
for {
|
for {
|
||||||
if v_0.Op != OpRISCV64MOVDconst {
|
if v_0.Op != OpRISCV64MOVDconst {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
c := auxIntToInt64(v_0.AuxInt)
|
c := auxIntToInt64(v_0.AuxInt)
|
||||||
v.reset(OpRISCV64MOVDconst)
|
v.reset(OpRISCV64MOVDconst)
|
||||||
v.AuxInt = int64ToAuxInt(int64(c))
|
v.AuxInt = int64ToAuxInt(int64(int32(c)))
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
// match: (MOVWreg x:(MOVBload _ _))
|
// match: (MOVWreg x:(MOVBload _ _))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue