Skip to content

Commit

Permalink
cmd/compile: convert nilcheck elim rules to typed aux
Browse files Browse the repository at this point in the history
Passes toolstash-check.

Change-Id: Ic7efb0e4778844366f581c6310a1a2f3bfc1868a
Reviewed-on: https://go-review.googlesource.com/c/go/+/229686
Run-TryBot: Josh Bleecher Snyder <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Keith Randall <[email protected]>
  • Loading branch information
josharian committed Apr 24, 2020
1 parent b6f6259 commit 47b5efa
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
14 changes: 7 additions & 7 deletions src/cmd/compile/internal/ssa/gen/generic.rules
Original file line number Diff line number Diff line change
Expand Up @@ -1923,31 +1923,31 @@
&& mem.Op == OpStaticCall
&& isSameSym(mem.Aux, "runtime.newobject")
&& c == config.ctxt.FixedFrameSize() + config.RegSize // offset of return value
-> mem
=> mem
(Store (Load (OffPtr [c] (SP)) mem) x mem)
&& isConstZero(x)
&& mem.Op == OpStaticCall
&& isSameSym(mem.Aux, "runtime.newobject")
&& c == config.ctxt.FixedFrameSize() + config.RegSize // offset of return value
-> mem
=> mem
(Store (OffPtr (Load (OffPtr [c] (SP)) mem)) x mem)
&& isConstZero(x)
&& mem.Op == OpStaticCall
&& isSameSym(mem.Aux, "runtime.newobject")
&& c == config.ctxt.FixedFrameSize() + config.RegSize // offset of return value
-> mem
=> mem
// nil checks just need to rewrite to something useless.
// they will be deadcode eliminated soon afterwards.
(NilCheck (Load (OffPtr [c] (SP)) (StaticCall {sym} _)) _)
&& isSameSym(sym, "runtime.newobject")
&& symNamed(sym, "runtime.newobject")
&& c == config.ctxt.FixedFrameSize() + config.RegSize // offset of return value
&& warnRule(fe.Debug_checknil(), v, "removed nil check")
-> (Invalid)
=> (Invalid)
(NilCheck (OffPtr (Load (OffPtr [c] (SP)) (StaticCall {sym} _))) _)
&& isSameSym(sym, "runtime.newobject")
&& symNamed(sym, "runtime.newobject")
&& c == config.ctxt.FixedFrameSize() + config.RegSize // offset of return value
&& warnRule(fe.Debug_checknil(), v, "removed nil check")
-> (Invalid)
=> (Invalid)

// Evaluate constant address comparisons.
(EqPtr x x) -> (ConstBool [1])
Expand Down
5 changes: 5 additions & 0 deletions src/cmd/compile/internal/ssa/rewrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,11 @@ func canMergeLoad(target, load *Value) bool {
return true
}

// symNamed reports whether sym's name is name.
func symNamed(sym Sym, name string) bool {
return sym.String() == name
}

// isSameSym reports whether sym is the same as the given named symbol
func isSameSym(sym interface{}, name string) bool {
s, ok := sym.(fmt.Stringer)
Expand Down
22 changes: 11 additions & 11 deletions src/cmd/compile/internal/ssa/rewritegeneric.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 47b5efa

Please sign in to comment.