mirror of
https://github.com/golang/go
synced 2024-09-30 22:58:34 -06:00
cmd/compile: remove useless block-indirection in type switch
Previously, when emitting type switches without an explicit "case nil" clause, we would emit: if x == nil { goto Lnil } ... Lnil: goto Ldefault But we can instead just emit: if x == nil { goto Ldefault } Doesn't pass toolstash-check; seems like it causes some harmless instruction scheduling changes. Change-Id: Ie233dda26756911e93a08b3db40407ba38694c62 Reviewed-on: https://go-review.googlesource.com/c/go/+/199644 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
e1446d9cee
commit
ab00f89c27
@ -588,20 +588,10 @@ func walkTypeSwitch(sw *Node) {
|
|||||||
if defaultGoto == nil {
|
if defaultGoto == nil {
|
||||||
defaultGoto = br
|
defaultGoto = br
|
||||||
}
|
}
|
||||||
|
if nilGoto == nil {
|
||||||
if nilGoto != nil {
|
nilGoto = defaultGoto
|
||||||
ifNil.Nbody.Set1(nilGoto)
|
|
||||||
} else {
|
|
||||||
// TODO(mdempsky): Just use defaultGoto directly.
|
|
||||||
|
|
||||||
// Jump to default case.
|
|
||||||
label := autolabel(".s")
|
|
||||||
ifNil.Nbody.Set1(nodSym(OGOTO, nil, label))
|
|
||||||
// Wrap default case with label.
|
|
||||||
blk := nod(OBLOCK, nil, nil)
|
|
||||||
blk.List.Set2(nodSym(OLABEL, nil, label), defaultGoto)
|
|
||||||
defaultGoto = blk
|
|
||||||
}
|
}
|
||||||
|
ifNil.Nbody.Set1(nilGoto)
|
||||||
|
|
||||||
s.Emit(&sw.Nbody)
|
s.Emit(&sw.Nbody)
|
||||||
sw.Nbody.Append(defaultGoto)
|
sw.Nbody.Append(defaultGoto)
|
||||||
|
Loading…
Reference in New Issue
Block a user