]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: duplicate nil check to two branches of write barrier
authorCherry Mui <cherryyz@google.com>
Thu, 18 Sep 2025 17:59:41 +0000 (13:59 -0400)
committerCherry Mui <cherryyz@google.com>
Fri, 19 Sep 2025 14:13:32 +0000 (07:13 -0700)
commitf9e61a9a32c8cbfd810ac9fec135b5c0911b8d69
tree146fd209757e0d210e310a91383a4e9993cc4ef6
parent3cf1aaf8b9c846c44ec8db679495dd5816d1ec30
cmd/compile: duplicate nil check to two branches of write barrier

Currently, for a write of a pointer (e.g. *p = x where x is a
pointer), we generate an explicit nil check of p, despite that the
store instruction may have the same faulting behavior as the nil
check. This is because the write needs a write barrier, which
creates a control flow, which prevents the nil check being removed
as it is in a differnt block as the actual store.

This CL duplicates the nil check to two branches, so it is likely
that they will be followed by the actual store and the write
barrier load, which may have the same faulting behavior, so they
can be removed.

Change-Id: Ied9480de5dd6a8fcbd5affc5f6e029944943cc07
Reviewed-on: https://go-review.googlesource.com/c/go/+/705156
Reviewed-by: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
src/cmd/compile/internal/ssa/writebarrier.go
test/nilptr5.go
test/nilptr5_aix.go
test/nilptr5_wasm.go