diff options
author | Daniel Martà <mvdan@mvdan.cc> | 2019-03-13 11:57:29 +0000 |
---|---|---|
committer | Daniel Martà <mvdan@mvdan.cc> | 2019-03-22 15:41:51 +0000 |
commit | 0fbf6818407366d79a7a388b58718f6c32ef16d2 (patch) | |
tree | 0f77bd0051e176e7fa09fcefe78df6f1e1a8a7fe /src/cmd/compile/internal/ssa/rewriteMIPS64.go | |
parent | b06d2122eec394a044d7b04a011b5b79318dc4c0 (diff) | |
download | go-0fbf6818407366d79a7a388b58718f6c32ef16d2.tar.gz go-0fbf6818407366d79a7a388b58718f6c32ef16d2.zip |
cmd/compile: reduce rulegen's for loop verbosity
A lot of the naked for loops begin like:
for {
v := b.Control
if v.Op != OpConstBool {
break
}
...
return true
}
Instead, write them out in a more compact and readable way:
for v.Op == OpConstBool {
...
return true
}
This requires the addition of two bytes.Buffer writers, as this helps us
make a decision based on future pieces of generated code. This probably
makes rulegen slightly slower, but that's not noticeable; the code
generation still takes ~3.5s on my laptop, excluding build time.
The "v := b.Control" declaration can be moved to the top of each
function. Even though the rules can modify b.Control when firing, they
also make the function return, so v can't be used again.
While at it, remove three unnecessary lines from the top of each
rewriteBlock func.
In total, this results in ~4k lines removed from the generated code, and
a slight improvement in readability.
Change-Id: I317e4c6a4842c64df506f4513375475fad2aeec5
Reviewed-on: https://go-review.googlesource.com/c/go/+/167399
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/ssa/rewriteMIPS64.go')
-rw-r--r-- | src/cmd/compile/internal/ssa/rewriteMIPS64.go | 199 |
1 files changed, 34 insertions, 165 deletions
diff --git a/src/cmd/compile/internal/ssa/rewriteMIPS64.go b/src/cmd/compile/internal/ssa/rewriteMIPS64.go index d9efa99261..453b81e75f 100644 --- a/src/cmd/compile/internal/ssa/rewriteMIPS64.go +++ b/src/cmd/compile/internal/ssa/rewriteMIPS64.go @@ -10036,21 +10036,16 @@ func rewriteValueMIPS64_OpZeroExt8to64_0(v *Value) bool { } func rewriteBlockMIPS64(b *Block) bool { config := b.Func.Config - _ = config - fe := b.Func.fe - _ = fe typ := &config.Types _ = typ + v := b.Control + _ = v switch b.Kind { case BlockMIPS64EQ: // match: (EQ (FPFlagTrue cmp) yes no) // cond: // result: (FPF cmp yes no) - for { - v := b.Control - if v.Op != OpMIPS64FPFlagTrue { - break - } + for v.Op == OpMIPS64FPFlagTrue { cmp := v.Args[0] b.Kind = BlockMIPS64FPF b.SetControl(cmp) @@ -10060,11 +10055,7 @@ func rewriteBlockMIPS64(b *Block) bool { // match: (EQ (FPFlagFalse cmp) yes no) // cond: // result: (FPT cmp yes no) - for { - v := b.Control - if v.Op != OpMIPS64FPFlagFalse { - break - } + for v.Op == OpMIPS64FPFlagFalse { cmp := v.Args[0] b.Kind = BlockMIPS64FPT b.SetControl(cmp) @@ -10074,11 +10065,7 @@ func rewriteBlockMIPS64(b *Block) bool { // match: (EQ (XORconst [1] cmp:(SGT _ _)) yes no) // cond: // result: (NE cmp yes no) - for { - v := b.Control - if v.Op != OpMIPS64XORconst { - break - } + for v.Op == OpMIPS64XORconst { if v.AuxInt != 1 { break } @@ -10095,11 +10082,7 @@ func rewriteBlockMIPS64(b *Block) bool { // match: (EQ (XORconst [1] cmp:(SGTU _ _)) yes no) // cond: // result: (NE cmp yes no) - for { - v := b.Control - if v.Op != OpMIPS64XORconst { - break - } + for v.Op == OpMIPS64XORconst { if v.AuxInt != 1 { break } @@ -10116,11 +10099,7 @@ func rewriteBlockMIPS64(b *Block) bool { // match: (EQ (XORconst [1] cmp:(SGTconst _)) yes no) // cond: // result: (NE cmp yes no) - for { - v := b.Control - if v.Op != OpMIPS64XORconst { - break - } + for v.Op == OpMIPS64XORconst { if v.AuxInt != 1 { break } @@ -10136,11 +10115,7 @@ func rewriteBlockMIPS64(b *Block) bool { // match: (EQ (XORconst [1] cmp:(SGTUconst _)) yes no) // cond: // result: (NE cmp yes no) - for { - v := b.Control - if v.Op != OpMIPS64XORconst { - break - } + for v.Op == OpMIPS64XORconst { if v.AuxInt != 1 { break } @@ -10156,11 +10131,7 @@ func rewriteBlockMIPS64(b *Block) bool { // match: (EQ (SGTUconst [1] x) yes no) // cond: // result: (NE x yes no) - for { - v := b.Control - if v.Op != OpMIPS64SGTUconst { - break - } + for v.Op == OpMIPS64SGTUconst { if v.AuxInt != 1 { break } @@ -10173,11 +10144,7 @@ func rewriteBlockMIPS64(b *Block) bool { // match: (EQ (SGTU x (MOVVconst [0])) yes no) // cond: // result: (EQ x yes no) - for { - v := b.Control - if v.Op != OpMIPS64SGTU { - break - } + for v.Op == OpMIPS64SGTU { _ = v.Args[1] x := v.Args[0] v_1 := v.Args[1] @@ -10195,11 +10162,7 @@ func rewriteBlockMIPS64(b *Block) bool { // match: (EQ (SGTconst [0] x) yes no) // cond: // result: (GEZ x yes no) - for { - v := b.Control - if v.Op != OpMIPS64SGTconst { - break - } + for v.Op == OpMIPS64SGTconst { if v.AuxInt != 0 { break } @@ -10212,11 +10175,7 @@ func rewriteBlockMIPS64(b *Block) bool { // match: (EQ (SGT x (MOVVconst [0])) yes no) // cond: // result: (LEZ x yes no) - for { - v := b.Control - if v.Op != OpMIPS64SGT { - break - } + for v.Op == OpMIPS64SGT { _ = v.Args[1] x := v.Args[0] v_1 := v.Args[1] @@ -10234,11 +10193,7 @@ func rewriteBlockMIPS64(b *Block) bool { // match: (EQ (MOVVconst [0]) yes no) // cond: // result: (First nil yes no) - for { - v := b.Control - if v.Op != OpMIPS64MOVVconst { - break - } + for v.Op == OpMIPS64MOVVconst { if v.AuxInt != 0 { break } @@ -10250,11 +10205,7 @@ func rewriteBlockMIPS64(b *Block) bool { // match: (EQ (MOVVconst [c]) yes no) // cond: c != 0 // result: (First nil no yes) - for { - v := b.Control - if v.Op != OpMIPS64MOVVconst { - break - } + for v.Op == OpMIPS64MOVVconst { c := v.AuxInt if !(c != 0) { break @@ -10269,11 +10220,7 @@ func rewriteBlockMIPS64(b *Block) bool { // match: (GEZ (MOVVconst [c]) yes no) // cond: c >= 0 // result: (First nil yes no) - for { - v := b.Control - if v.Op != OpMIPS64MOVVconst { - break - } + for v.Op == OpMIPS64MOVVconst { c := v.AuxInt if !(c >= 0) { break @@ -10286,11 +10233,7 @@ func rewriteBlockMIPS64(b *Block) bool { // match: (GEZ (MOVVconst [c]) yes no) // cond: c < 0 // result: (First nil no yes) - for { - v := b.Control - if v.Op != OpMIPS64MOVVconst { - break - } + for v.Op == OpMIPS64MOVVconst { c := v.AuxInt if !(c < 0) { break @@ -10305,11 +10248,7 @@ func rewriteBlockMIPS64(b *Block) bool { // match: (GTZ (MOVVconst [c]) yes no) // cond: c > 0 // result: (First nil yes no) - for { - v := b.Control - if v.Op != OpMIPS64MOVVconst { - break - } + for v.Op == OpMIPS64MOVVconst { c := v.AuxInt if !(c > 0) { break @@ -10322,11 +10261,7 @@ func rewriteBlockMIPS64(b *Block) bool { // match: (GTZ (MOVVconst [c]) yes no) // cond: c <= 0 // result: (First nil no yes) - for { - v := b.Control - if v.Op != OpMIPS64MOVVconst { - break - } + for v.Op == OpMIPS64MOVVconst { c := v.AuxInt if !(c <= 0) { break @@ -10342,8 +10277,6 @@ func rewriteBlockMIPS64(b *Block) bool { // cond: // result: (NE cond yes no) for { - v := b.Control - _ = v cond := b.Control b.Kind = BlockMIPS64NE b.SetControl(cond) @@ -10354,11 +10287,7 @@ func rewriteBlockMIPS64(b *Block) bool { // match: (LEZ (MOVVconst [c]) yes no) // cond: c <= 0 // result: (First nil yes no) - for { - v := b.Control - if v.Op != OpMIPS64MOVVconst { - break - } + for v.Op == OpMIPS64MOVVconst { c := v.AuxInt if !(c <= 0) { break @@ -10371,11 +10300,7 @@ func rewriteBlockMIPS64(b *Block) bool { // match: (LEZ (MOVVconst [c]) yes no) // cond: c > 0 // result: (First nil no yes) - for { - v := b.Control - if v.Op != OpMIPS64MOVVconst { - break - } + for v.Op == OpMIPS64MOVVconst { c := v.AuxInt if !(c > 0) { break @@ -10390,11 +10315,7 @@ func rewriteBlockMIPS64(b *Block) bool { // match: (LTZ (MOVVconst [c]) yes no) // cond: c < 0 // result: (First nil yes no) - for { - v := b.Control - if v.Op != OpMIPS64MOVVconst { - break - } + for v.Op == OpMIPS64MOVVconst { c := v.AuxInt if !(c < 0) { break @@ -10407,11 +10328,7 @@ func rewriteBlockMIPS64(b *Block) bool { // match: (LTZ (MOVVconst [c]) yes no) // cond: c >= 0 // result: (First nil no yes) - for { - v := b.Control - if v.Op != OpMIPS64MOVVconst { - break - } + for v.Op == OpMIPS64MOVVconst { c := v.AuxInt if !(c >= 0) { break @@ -10426,11 +10343,7 @@ func rewriteBlockMIPS64(b *Block) bool { // match: (NE (FPFlagTrue cmp) yes no) // cond: // result: (FPT cmp yes no) - for { - v := b.Control - if v.Op != OpMIPS64FPFlagTrue { - break - } + for v.Op == OpMIPS64FPFlagTrue { cmp := v.Args[0] b.Kind = BlockMIPS64FPT b.SetControl(cmp) @@ -10440,11 +10353,7 @@ func rewriteBlockMIPS64(b *Block) bool { // match: (NE (FPFlagFalse cmp) yes no) // cond: // result: (FPF cmp yes no) - for { - v := b.Control - if v.Op != OpMIPS64FPFlagFalse { - break - } + for v.Op == OpMIPS64FPFlagFalse { cmp := v.Args[0] b.Kind = BlockMIPS64FPF b.SetControl(cmp) @@ -10454,11 +10363,7 @@ func rewriteBlockMIPS64(b *Block) bool { // match: (NE (XORconst [1] cmp:(SGT _ _)) yes no) // cond: // result: (EQ cmp yes no) - for { - v := b.Control - if v.Op != OpMIPS64XORconst { - break - } + for v.Op == OpMIPS64XORconst { if v.AuxInt != 1 { break } @@ -10475,11 +10380,7 @@ func rewriteBlockMIPS64(b *Block) bool { // match: (NE (XORconst [1] cmp:(SGTU _ _)) yes no) // cond: // result: (EQ cmp yes no) - for { - v := b.Control - if v.Op != OpMIPS64XORconst { - break - } + for v.Op == OpMIPS64XORconst { if v.AuxInt != 1 { break } @@ -10496,11 +10397,7 @@ func rewriteBlockMIPS64(b *Block) bool { // match: (NE (XORconst [1] cmp:(SGTconst _)) yes no) // cond: // result: (EQ cmp yes no) - for { - v := b.Control - if v.Op != OpMIPS64XORconst { - break - } + for v.Op == OpMIPS64XORconst { if v.AuxInt != 1 { break } @@ -10516,11 +10413,7 @@ func rewriteBlockMIPS64(b *Block) bool { // match: (NE (XORconst [1] cmp:(SGTUconst _)) yes no) // cond: // result: (EQ cmp yes no) - for { - v := b.Control - if v.Op != OpMIPS64XORconst { - break - } + for v.Op == OpMIPS64XORconst { if v.AuxInt != 1 { break } @@ -10536,11 +10429,7 @@ func rewriteBlockMIPS64(b *Block) bool { // match: (NE (SGTUconst [1] x) yes no) // cond: // result: (EQ x yes no) - for { - v := b.Control - if v.Op != OpMIPS64SGTUconst { - break - } + for v.Op == OpMIPS64SGTUconst { if v.AuxInt != 1 { break } @@ -10553,11 +10442,7 @@ func rewriteBlockMIPS64(b *Block) bool { // match: (NE (SGTU x (MOVVconst [0])) yes no) // cond: // result: (NE x yes no) - for { - v := b.Control - if v.Op != OpMIPS64SGTU { - break - } + for v.Op == OpMIPS64SGTU { _ = v.Args[1] x := v.Args[0] v_1 := v.Args[1] @@ -10575,11 +10460,7 @@ func rewriteBlockMIPS64(b *Block) bool { // match: (NE (SGTconst [0] x) yes no) // cond: // result: (LTZ x yes no) - for { - v := b.Control - if v.Op != OpMIPS64SGTconst { - break - } + for v.Op == OpMIPS64SGTconst { if v.AuxInt != 0 { break } @@ -10592,11 +10473,7 @@ func rewriteBlockMIPS64(b *Block) bool { // match: (NE (SGT x (MOVVconst [0])) yes no) // cond: // result: (GTZ x yes no) - for { - v := b.Control - if v.Op != OpMIPS64SGT { - break - } + for v.Op == OpMIPS64SGT { _ = v.Args[1] x := v.Args[0] v_1 := v.Args[1] @@ -10614,11 +10491,7 @@ func rewriteBlockMIPS64(b *Block) bool { // match: (NE (MOVVconst [0]) yes no) // cond: // result: (First nil no yes) - for { - v := b.Control - if v.Op != OpMIPS64MOVVconst { - break - } + for v.Op == OpMIPS64MOVVconst { if v.AuxInt != 0 { break } @@ -10631,11 +10504,7 @@ func rewriteBlockMIPS64(b *Block) bool { // match: (NE (MOVVconst [c]) yes no) // cond: c != 0 // result: (First nil yes no) - for { - v := b.Control - if v.Op != OpMIPS64MOVVconst { - break - } + for v.Op == OpMIPS64MOVVconst { c := v.AuxInt if !(c != 0) { break |