Commit 52d76f7a authored by Todd Neal's avatar Todd Neal

[dev.ssa] cmd/compile: rewrite if not

Rewrite if !cond by swapping the branches and removing the not.

Change-Id: If3af1bac02bfc566faba872a8c7f7e5ce38e9f58
Reviewed-on: https://go-review.googlesource.com/12610Reviewed-by: 's avatarJosh Bleecher Snyder <josharian@gmail.com>
parent 7e74e433
...@@ -51,5 +51,6 @@ ...@@ -51,5 +51,6 @@
(StringLen (StringMake _ len)) -> len (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)) (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 yes)
(If (Const {c}) yes no) && !c.(bool) -> (Plain nil no) (If (Const {c}) yes no) && !c.(bool) -> (Plain nil no)
...@@ -495,6 +495,26 @@ func rewriteValuegeneric(v *Value, config *Config) bool { ...@@ -495,6 +495,26 @@ func rewriteValuegeneric(v *Value, config *Config) bool {
func rewriteBlockgeneric(b *Block) bool { func rewriteBlockgeneric(b *Block) bool {
switch b.Kind { switch b.Kind {
case BlockIf: 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) // match: (If (Const {c}) yes no)
// cond: c.(bool) // cond: c.(bool)
// result: (Plain nil yes) // result: (Plain nil yes)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment