(Add32F (Const32F [c]) (Const32F [d])) ->
(Const32F [f2i(float64(i2f32(c) + i2f32(d)))]) // ensure we combine the operands with 32 bit precision
(Add64F (Const64F [c]) (Const64F [d])) -> (Const64F [f2i(i2f(c) + i2f(d))])
+(AddPtr <t> x (Const64 [c])) -> (OffPtr <t> x [c])
(Sub8 (Const8 [c]) (Const8 [d])) -> (Const8 [c-d])
(Sub16 (Const16 [c]) (Const16 [d])) -> (Const16 [c-d])
(Neq8 x (Const8 <t> [c])) && x.Op != OpConst8 -> (Neq8 (Const8 <t> [c]) x)
(Neq8 x (ConstBool <t> [c])) && x.Op != OpConstBool -> (Neq8 (ConstBool <t> [c]) x)
+// AddPtr is not canonicalized because nilcheck ptr checks the first argument to be non-nil.
(Add64 x (Const64 <t> [c])) && x.Op != OpConst64 -> (Add64 (Const64 <t> [c]) x)
(Add32 x (Const32 <t> [c])) && x.Op != OpConst32 -> (Add32 (Const32 <t> [c]) x)
(Add16 x (Const16 <t> [c])) && x.Op != OpConst16 -> (Add16 (Const16 <t> [c]) x)
// Collapse OffPtr
(OffPtr (OffPtr p [b]) [a]) -> (OffPtr p [a+b])
+(OffPtr p [0]) && v.Type.Compare(p.Type) == CMPeq -> p
// indexing operations
return rewriteValuegeneric_OpAdd64F(v, config)
case OpAdd8:
return rewriteValuegeneric_OpAdd8(v, config)
+ case OpAddPtr:
+ return rewriteValuegeneric_OpAddPtr(v, config)
case OpAnd16:
return rewriteValuegeneric_OpAnd16(v, config)
case OpAnd32:
}
return false
}
+func rewriteValuegeneric_OpAddPtr(v *Value, config *Config) bool {
+ b := v.Block
+ _ = b
+ // match: (AddPtr <t> x (Const64 [c]))
+ // cond:
+ // result: (OffPtr <t> x [c])
+ for {
+ t := v.Type
+ x := v.Args[0]
+ if v.Args[1].Op != OpConst64 {
+ break
+ }
+ c := v.Args[1].AuxInt
+ v.reset(OpOffPtr)
+ v.Type = t
+ v.AddArg(x)
+ v.AuxInt = c
+ return true
+ }
+ return false
+}
func rewriteValuegeneric_OpAnd16(v *Value, config *Config) bool {
b := v.Block
_ = b
v.AuxInt = a + b
return true
}
+ // match: (OffPtr p [0])
+ // cond: v.Type.Compare(p.Type) == CMPeq
+ // result: p
+ for {
+ p := v.Args[0]
+ if v.AuxInt != 0 {
+ break
+ }
+ if !(v.Type.Compare(p.Type) == CMPeq) {
+ break
+ }
+ v.reset(OpCopy)
+ v.Type = p.Type
+ v.AddArg(p)
+ return true
+ }
return false
}
func rewriteValuegeneric_OpOr16(v *Value, config *Config) bool {