(SRLI [x] (MOVDconst [y])) => (MOVDconst [int64(uint64(y) >> uint32(x))])
(SRAI [x] (MOVDconst [y])) => (MOVDconst [int64(y) >> uint32(x)])
+// Combine doubling via addition with shift.
+(SLLI <t> [c] (ADD x x)) && c < t.Size() * 8 - 1 => (SLLI <t> [c+1] x)
+(SLLI <t> [c] (ADD x x)) && c >= t.Size() * 8 - 1 => (MOVDconst [0])
+
// SLTI/SLTIU with constants.
(SLTI [x] (MOVDconst [y])) => (MOVDconst [b2i(int64(y) < int64(x))])
(SLTIU [x] (MOVDconst [y])) => (MOVDconst [b2i(uint64(y) < uint64(x))])
v.AuxInt = int64ToAuxInt(y << uint32(x))
return true
}
+ // match: (SLLI <t> [c] (ADD x x))
+ // cond: c < t.Size() * 8 - 1
+ // result: (SLLI <t> [c+1] x)
+ for {
+ t := v.Type
+ c := auxIntToInt64(v.AuxInt)
+ if v_0.Op != OpRISCV64ADD {
+ break
+ }
+ x := v_0.Args[1]
+ if x != v_0.Args[0] || !(c < t.Size()*8-1) {
+ break
+ }
+ v.reset(OpRISCV64SLLI)
+ v.Type = t
+ v.AuxInt = int64ToAuxInt(c + 1)
+ v.AddArg(x)
+ return true
+ }
+ // match: (SLLI <t> [c] (ADD x x))
+ // cond: c >= t.Size() * 8 - 1
+ // result: (MOVDconst [0])
+ for {
+ t := v.Type
+ c := auxIntToInt64(v.AuxInt)
+ if v_0.Op != OpRISCV64ADD {
+ break
+ }
+ x := v_0.Args[1]
+ if x != v_0.Args[0] || !(c >= t.Size()*8-1) {
+ break
+ }
+ v.reset(OpRISCV64MOVDconst)
+ v.AuxInt = int64ToAuxInt(0)
+ return true
+ }
return false
}
func rewriteValueRISCV64_OpRISCV64SLLW(v *Value) bool {
func lshConst32x1Add(x int32) int32 {
// amd64:"SHLL\t[$]2"
// loong64:"SLL\t[$]2"
+ // riscv64:"SLLI\t[$]2"
return (x + x) << 1
}
func lshConst64x1Add(x int64) int64 {
// amd64:"SHLQ\t[$]2"
// loong64:"SLLV\t[$]2"
+ // riscv64:"SLLI\t[$]2"
return (x + x) << 1
}
func lshConst32x2Add(x int32) int32 {
// amd64:"SHLL\t[$]3"
// loong64:"SLL\t[$]3"
+ // riscv64:"SLLI\t[$]3"
return (x + x) << 2
}
func lshConst64x2Add(x int64) int64 {
// amd64:"SHLQ\t[$]3"
// loong64:"SLLV\t[$]3"
+ // riscv64:"SLLI\t[$]3"
return (x + x) << 2
}
+func lshConst32x31Add(x int32) int32 {
+ // riscv64:-"SLLI","MOV\t[$]0"
+ return (x + x) << 31
+}
+
+func lshConst64x63Add(x int64) int64 {
+ // riscv64:-"SLLI","MOV\t[$]0"
+ return (x + x) << 63
+}
+
// ------------------ //
// masked shifts //
// ------------------ //