1
0
mirror of https://github.com/golang/go synced 2024-11-24 20:40:23 -07:00

[dev.ssa] cmd/compile/internal/ssa/gen: constant fold Neg*.

Change-Id: Id51e5c97e9653b764b809bf3424f1a6d31b6ffea
Reviewed-on: https://go-review.googlesource.com/19338
Run-TryBot: David Chase <drchase@google.com>
Reviewed-by: David Chase <drchase@google.com>
This commit is contained in:
Alexandru Moșoi 2016-02-08 18:55:56 +01:00 committed by David Chase
parent 58cfa40419
commit 964dda9bf1
2 changed files with 81 additions and 0 deletions

View File

@ -20,6 +20,11 @@
// For now, the generated successors must be a permutation of the matched successors.
// constant folding
(Neg8 (Const8 [c])) -> (Const8 [-c])
(Neg16 (Const16 [c])) -> (Const16 [-c])
(Neg32 (Const32 [c])) -> (Const32 [-c])
(Neg64 (Const64 [c])) -> (Const64 [-c])
(Add8 (Const8 [c]) (Const8 [d])) -> (Const8 [c+d])
(Add16 (Const16 [c]) (Const16 [d])) -> (Const16 [c+d])
(Add32 (Const32 [c]) (Const32 [d])) -> (Const32 [c+d])

View File

@ -183,6 +183,14 @@ func rewriteValuegeneric(v *Value, config *Config) bool {
return rewriteValuegeneric_OpMul64(v, config)
case OpMul8:
return rewriteValuegeneric_OpMul8(v, config)
case OpNeg16:
return rewriteValuegeneric_OpNeg16(v, config)
case OpNeg32:
return rewriteValuegeneric_OpNeg32(v, config)
case OpNeg64:
return rewriteValuegeneric_OpNeg64(v, config)
case OpNeg8:
return rewriteValuegeneric_OpNeg8(v, config)
case OpNeq16:
return rewriteValuegeneric_OpNeq16(v, config)
case OpNeq32:
@ -3428,6 +3436,74 @@ func rewriteValuegeneric_OpMul8(v *Value, config *Config) bool {
}
return false
}
func rewriteValuegeneric_OpNeg16(v *Value, config *Config) bool {
b := v.Block
_ = b
// match: (Neg16 (Const16 [c]))
// cond:
// result: (Const16 [-c])
for {
if v.Args[0].Op != OpConst16 {
break
}
c := v.Args[0].AuxInt
v.reset(OpConst16)
v.AuxInt = -c
return true
}
return false
}
func rewriteValuegeneric_OpNeg32(v *Value, config *Config) bool {
b := v.Block
_ = b
// match: (Neg32 (Const32 [c]))
// cond:
// result: (Const32 [-c])
for {
if v.Args[0].Op != OpConst32 {
break
}
c := v.Args[0].AuxInt
v.reset(OpConst32)
v.AuxInt = -c
return true
}
return false
}
func rewriteValuegeneric_OpNeg64(v *Value, config *Config) bool {
b := v.Block
_ = b
// match: (Neg64 (Const64 [c]))
// cond:
// result: (Const64 [-c])
for {
if v.Args[0].Op != OpConst64 {
break
}
c := v.Args[0].AuxInt
v.reset(OpConst64)
v.AuxInt = -c
return true
}
return false
}
func rewriteValuegeneric_OpNeg8(v *Value, config *Config) bool {
b := v.Block
_ = b
// match: (Neg8 (Const8 [c]))
// cond:
// result: (Const8 [-c])
for {
if v.Args[0].Op != OpConst8 {
break
}
c := v.Args[0].AuxInt
v.reset(OpConst8)
v.AuxInt = -c
return true
}
return false
}
func rewriteValuegeneric_OpNeq16(v *Value, config *Config) bool {
b := v.Block
_ = b