]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.ssa] cmd/compile: rewrite if not
authorTodd Neal <todd@tneal.org>
Thu, 23 Jul 2015 23:44:09 +0000 (18:44 -0500)
committerTodd Neal <todd@tneal.org>
Sun, 26 Jul 2015 02:10:45 +0000 (02:10 +0000)
Rewrite if !cond by swapping the branches and removing the not.

Change-Id: If3af1bac02bfc566faba872a8c7f7e5ce38e9f58
Reviewed-on: https://go-review.googlesource.com/12610
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
src/cmd/compile/internal/ssa/gen/generic.rules
src/cmd/compile/internal/ssa/rewritegeneric.go

index 492676d9b7dc7d1fe6433714e8c577a77dac20d2..fc5ffb96100b4cbacaf98016e6060766576c562f 100644 (file)
@@ -51,5 +51,6 @@
 (StringLen (StringMake _ len)) -> len
 (Store dst str mem) && str.Type.IsString() -> (Store (OffPtr <TypeBytePtr> [config.PtrSize] dst) (StringLen <config.Uintptr> str) (Store <TypeMem> dst (StringPtr <TypeBytePtr> str) mem))
 
+(If (Not cond) yes no) -> (If cond no yes)
 (If (Const {c}) yes no) && c.(bool) -> (Plain nil yes)
 (If (Const {c}) yes no) && !c.(bool) -> (Plain nil no)
index 66b6c1a7a5146b0cff162897205c04758a347394..54358129e0c173b7f75dc9f8de208fbe8ea0cb7b 100644 (file)
@@ -495,6 +495,26 @@ func rewriteValuegeneric(v *Value, config *Config) bool {
 func rewriteBlockgeneric(b *Block) bool {
        switch b.Kind {
        case BlockIf:
+               // match: (If (Not cond) yes no)
+               // cond:
+               // result: (If cond no yes)
+               {
+                       v := b.Control
+                       if v.Op != OpNot {
+                               goto endebe19c1c3c3bec068cdb2dd29ef57f96
+                       }
+                       cond := v.Args[0]
+                       yes := b.Succs[0]
+                       no := b.Succs[1]
+                       b.Kind = BlockIf
+                       b.Control = cond
+                       b.Succs[0] = no
+                       b.Succs[1] = yes
+                       return true
+               }
+               goto endebe19c1c3c3bec068cdb2dd29ef57f96
+       endebe19c1c3c3bec068cdb2dd29ef57f96:
+               ;
                // match: (If (Const {c}) yes no)
                // cond: c.(bool)
                // result: (Plain nil yes)