Skip to content

Conversation

@aykevl
Copy link
Member

@aykevl aykevl commented Mar 25, 2020

Finally, I think this branch is ready.

The first three commits are commits to prepare for the change in the fourth commit, which is what this PR is about. They make sure escape analysis won't regress after runtime.isnil has been removed.

I found exactly one regression in escape analysis: in testdata/calls.go, but only on a host OS and on WebAssembly. Further investigation revealed that it has something to do with function pointers or closures.
Most tests I've done (including smoke tests) result in a reduction of code size however some get bigger (perhaps because the inliner made different choices somewhere). None of the baremetal tests resulted in an escape analysis regression. Overall I think this is an improvement.

(Note that the GitHub ordering of commits is wrong, they're sorted by date and not by actual commit order).

aykevl added 4 commits March 25, 2020 20:29
This gives a hint to the compiler that such parameters are either NULL
or point to a valid object that can be dereferenced. This is not
directly very useful, but is very useful when combined with
https://reviews.llvm.org/D60047 to remove the runtime.isnil hack without
regressing escape analysis.
The x/tools/go/ssa package splits slice loads/stores into two
operations. So for code like this:

    x = p[3]

It has two instructions:

    x_ptr = &p[3]
    x = *x_ptr

This makes the IR simpler, but also means we're accidentally inserting
more nil checks than necessary: the slice index operation has
effectively already checked for nil by performing a bounds check.
Therefore, omit nil pointer checks for pointers created by
*ssa.IndexAddr.

This change is necessary to make sure a future removal of runtime.isnil
will not cause the escape analysis pass to regress. Apart from that, it
reduces code size slightly in many smoke tests (with no increases in
code size).
The unsafe.Pointer type is used for many low-level operations,
especially in the runtime. It can for example be used to copy the
contents of a slice (in the copy builtin) independent of the slice
element type.
This hack was originally introduced in
#251 to fix an escape analysis
regression after #222
introduced nil checks. Since a new optimization in LLVM (see
https://reviews.llvm.org/D60047) this hack is not necessary anymore and
can be removed.

I've compared all regular tests and smoke tests before and after to
check the size. In most cases this change was an improvement although
there are a few regressions.
Copy link
Member

@niaow niaow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@deadprogram
Copy link
Member

Now merging, thanks @aykevl

@deadprogram deadprogram merged commit f8876ea into dev Mar 27, 2020
@deadprogram deadprogram deleted the remove-isnil branch March 27, 2020 06:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants