mirror of
https://github.com/golang/go
synced 2024-10-05 18:21:21 -06:00
[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/12610 Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
This commit is contained in:
parent
7e74e43366
commit
52d76f7a6a
@ -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 {
|
|||||||
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user