aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/compile')
-rw-r--r--src/cmd/compile/internal/ssa/_gen/MIPS.rules3
-rw-r--r--src/cmd/compile/internal/ssa/rewriteMIPS.go34
2 files changed, 37 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/ssa/_gen/MIPS.rules b/src/cmd/compile/internal/ssa/_gen/MIPS.rules
index 4471763462..a4899ac24d 100644
--- a/src/cmd/compile/internal/ssa/_gen/MIPS.rules
+++ b/src/cmd/compile/internal/ssa/_gen/MIPS.rules
@@ -614,11 +614,14 @@
// generic simplifications
(ADD x (NEG y)) => (SUB x y)
+(SUB x (NEG y)) => (ADD x y)
(SUB x x) => (MOVWconst [0])
(SUB (MOVWconst [0]) x) => (NEG x)
(AND x x) => x
(OR x x) => x
(XOR x x) => (MOVWconst [0])
+(NEG (SUB x y)) => (SUB y x)
+(NEG (NEG x)) => x
// miscellaneous patterns generated by dec64
(AND (SGTUconst [1] x) (SGTUconst [1] y)) => (SGTUconst [1] (OR <x.Type> x y))
diff --git a/src/cmd/compile/internal/ssa/rewriteMIPS.go b/src/cmd/compile/internal/ssa/rewriteMIPS.go
index 1bc2cb6e6d..fe24f0fd0f 100644
--- a/src/cmd/compile/internal/ssa/rewriteMIPS.go
+++ b/src/cmd/compile/internal/ssa/rewriteMIPS.go
@@ -4096,6 +4096,28 @@ func rewriteValueMIPS_OpMIPSMUL(v *Value) bool {
}
func rewriteValueMIPS_OpMIPSNEG(v *Value) bool {
v_0 := v.Args[0]
+ // match: (NEG (SUB x y))
+ // result: (SUB y x)
+ for {
+ if v_0.Op != OpMIPSSUB {
+ break
+ }
+ y := v_0.Args[1]
+ x := v_0.Args[0]
+ v.reset(OpMIPSSUB)
+ v.AddArg2(y, x)
+ return true
+ }
+ // match: (NEG (NEG x))
+ // result: x
+ for {
+ if v_0.Op != OpMIPSNEG {
+ break
+ }
+ x := v_0.Args[0]
+ v.copyOf(x)
+ return true
+ }
// match: (NEG (MOVWconst [c]))
// result: (MOVWconst [-c])
for {
@@ -4748,6 +4770,18 @@ func rewriteValueMIPS_OpMIPSSUB(v *Value) bool {
v.AddArg(x)
return true
}
+ // match: (SUB x (NEG y))
+ // result: (ADD x y)
+ for {
+ x := v_0
+ if v_1.Op != OpMIPSNEG {
+ break
+ }
+ y := v_1.Args[0]
+ v.reset(OpMIPSADD)
+ v.AddArg2(x, y)
+ return true
+ }
// match: (SUB x x)
// result: (MOVWconst [0])
for {