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>
(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)
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)