Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2654)

Issue 91850043: code review 91850043: cmd/gc: alias more variables during register allocation (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
10 years ago by josharian
Modified:
9 years, 11 months ago
Reviewers:
rsc
CC:
rsc, DMorsing, bradfitz, dave_cheney.net, golang-codereviews
Visibility:
Public.

Description

cmd/gc: alias more variables during register allocation This is joint work with Daniel Morsing. In order for the register allocator to alias two variables, they must have the same width, stack offset, and etype. Code generation was altering a variable's etype in a few places. This prevented the variable from being moved to a register, which in turn prevented peephole optimization. This failure to alias was very common, with almost 23,000 instances just running make.bash. This phenomenon was not visible in the register allocation debug output because the variables that failed to alias had the same name. The debugging-only change to bits.c fixes this by printing the variable number with its name. This CL fixes the source of all etype mismatches for 6g, all but one case for 8g, and depressingly few cases for 5g. (I believe that extending CL 6819083 to 5g is a prerequisite.) Fixing the remaining cases in 8g and 5g is work for the future. The etype mismatch fixes are: * [gc] Slicing changed the type of the base pointer into a uintptr in order to perform arithmetic on it. Instead, support addition directly on pointers. * [*g] OSPTR was giving type uintptr to slice base pointers; undo that. This arose, for example, while compiling copy(dst, src). * [8g] 64 bit float conversion was assigning int64 type during codegen, overwriting the existing uint64 type. Note that some etype mismatches are appropriate, such as a struct with a single field or an array with a single element. With these fixes, the number of registerizations that occur while running make.bash for 6g increases ~10%. Hello world binary size shrinks ~1.5%. Running all benchmarks in the standard library show performance improvements ranging from nominal to substantive (>10%); a full comparison using 6g on my laptop is available at https://gist.github.com/josharian/8f9b5beb46667c272064. The microbenchmarks must be taken with a grain of salt; see issue 7920. The few benchmarks that show real regressions are likely due to issue 7920. I manually examined the generated code for the top few regressions and none had any assembly output changes. The few benchmarks that show extraordinary improvements are likely also due to issue 7920. Performance results from 8g appear similar to 6g. 5g shows no performance improvements. This is not surprising, given the discussion above. Update issue 7316

Patch Set 1 #

Patch Set 2 : diff -r acf346c00e56 https://code.google.com/p/go #

Patch Set 3 : diff -r acf346c00e56 https://code.google.com/p/go #

Patch Set 4 : diff -r acf346c00e56 https://code.google.com/p/go #

Patch Set 5 : diff -r acf346c00e56 https://code.google.com/p/go #

Patch Set 6 : diff -r acf346c00e56 https://code.google.com/p/go #

Patch Set 7 : diff -r acf346c00e56 https://code.google.com/p/go #

Patch Set 8 : diff -r acf346c00e56 https://code.google.com/p/go #

Patch Set 9 : diff -r acf346c00e56 https://code.google.com/p/go #

Patch Set 10 : diff -r acf346c00e56 https://code.google.com/p/go #

Patch Set 11 : diff -r acf346c00e56 https://code.google.com/p/go #

Patch Set 12 : diff -r acf346c00e56 https://code.google.com/p/go #

Patch Set 13 : diff -r acf346c00e56 https://code.google.com/p/go #

Total comments: 12

Patch Set 14 : diff -r e4248ed0037c https://code.google.com/p/go #

Unified diffs Side-by-side diffs Delta from patch set Stats (+66 lines, -8 lines) Patch
M src/cmd/5g/cgen.c View 1 2 3 4 5 6 7 8 9 10 1 chunk +1 line, -0 lines 0 comments Download
M src/cmd/5g/gsubr.c View 1 2 3 4 5 6 7 8 9 10 2 chunks +2 lines, -1 line 0 comments Download
M src/cmd/6g/cgen.c View 1 2 3 4 5 6 1 chunk +1 line, -0 lines 0 comments Download
M src/cmd/6g/gsubr.c View 1 2 3 4 5 6 7 8 2 chunks +3 lines, -1 line 0 comments Download
M src/cmd/8g/cgen.c View 1 2 3 4 5 6 7 8 9 10 1 chunk +1 line, -0 lines 0 comments Download
M src/cmd/8g/gsubr.c View 1 2 3 4 5 6 7 8 9 10 3 chunks +2 lines, -2 lines 0 comments Download
M src/cmd/gc/bits.c View 1 1 chunk +1 line, -1 line 0 comments Download
M src/cmd/gc/gen.c View 1 2 3 4 5 6 7 3 chunks +4 lines, -3 lines 0 comments Download
M src/cmd/gc/go.h View 1 2 3 4 5 6 1 chunk +1 line, -0 lines 0 comments Download
M src/cmd/gc/typecheck.c View 1 2 3 4 5 6 7 8 9 10 11 12 13 1 chunk +13 lines, -0 lines 0 comments Download
A test/fixedbugs/issue7316.go View 1 2 3 4 5 6 7 8 9 10 11 12 13 1 chunk +37 lines, -0 lines 0 comments Download

Messages

Total messages: 17
rsc
I'm a little scared of this. It would be better for the temporaries to have ...
10 years ago (2014-04-28 16:59:47 UTC) #1
josharian
> What is generating UINT64 instead of PTR64 or vice versa? In the case of ...
10 years ago (2014-04-28 17:22:19 UTC) #2
DMorsing
On 2014/04/28 16:59:47, rsc wrote: > I'm a little scared of this. It would be ...
10 years ago (2014-04-28 17:24:08 UTC) #3
DMorsing
On 2014/04/28 17:24:08, DMorsing wrote: > In hindsight, there might be a problem if a ...
10 years ago (2014-04-28 17:37:33 UTC) #4
rsc
The last time this came up (when I was doing 8g) I found it useful ...
10 years ago (2014-04-29 03:07:28 UTC) #5
josharian
> The last time this came up (when I was doing 8g) I found it ...
10 years ago (2014-04-29 03:19:47 UTC) #6
rsc
Existing code doesn't deal with mismatches. The fix is to remove the code that is ...
10 years ago (2014-04-29 04:18:02 UTC) #7
josharian
> Existing code doesn't deal with mismatches. The fix is to remove the code > ...
9 years, 12 months ago (2014-04-30 00:14:25 UTC) #8
josharian
Quick update and a question. I've fixed the two primary causes: cgen_slice and OSPTR's simtype ...
9 years, 12 months ago (2014-04-30 21:21:01 UTC) #9
rsc
Please remove the changes in 6g/reg.c and then make the corresponding changes for what's left ...
9 years, 12 months ago (2014-05-01 00:54:10 UTC) #10
josharian
Hello rsc@golang.org, daniel.morsing@gmail.com (cc: dave@cheney.net, golang-codereviews@googlegroups.com), I'd like you to review this change to https://code.google.com/p/go
9 years, 12 months ago (2014-05-02 01:02:10 UTC) #11
bradfitz
Ping. Looks like Russ left comments and a new patch arrived. This ready? On May ...
9 years, 11 months ago (2014-05-09 17:03:36 UTC) #12
josharian
> Ping. Looks like Russ left comments and a new patch arrived. This ready? Yes. ...
9 years, 11 months ago (2014-05-09 17:11:00 UTC) #13
rsc
please revert the debugging code (marked below). the actual changes are trivial and can go ...
9 years, 11 months ago (2014-05-09 19:48:30 UTC) #14
josharian
PTAL All done, and description updated accordingly. Thanks! https://codereview.appspot.com/91850043/diff/230001/src/cmd/5g/reg.c File src/cmd/5g/reg.c (right): https://codereview.appspot.com/91850043/diff/230001/src/cmd/5g/reg.c#newcode782 src/cmd/5g/reg.c:782: if(v->width ...
9 years, 11 months ago (2014-05-10 00:07:51 UTC) #15
rsc
LGTM
9 years, 11 months ago (2014-05-12 21:10:21 UTC) #16
rsc
9 years, 11 months ago (2014-05-12 21:10:40 UTC) #17
*** Submitted as https://code.google.com/p/go/source/detail?r=b6591f566db4 ***

cmd/gc: alias more variables during register allocation

This is joint work with Daniel Morsing.

In order for the register allocator to alias two variables, they must have the
same width, stack offset, and etype. Code generation was altering a variable's
etype in a few places. This prevented the variable from being moved to a
register, which in turn prevented peephole optimization. This failure to alias
was very common, with almost 23,000 instances just running make.bash.

This phenomenon was not visible in the register allocation debug output because
the variables that failed to alias had the same name. The debugging-only change
to bits.c fixes this by printing the variable number with its name.

This CL fixes the source of all etype mismatches for 6g, all but one case for
8g, and depressingly few cases for 5g. (I believe that extending CL 6819083 to
5g is a prerequisite.) Fixing the remaining cases in 8g and 5g is work for the
future.

The etype mismatch fixes are:

* [gc] Slicing changed the type of the base pointer into a uintptr in order to
perform arithmetic on it. Instead, support addition directly on pointers.

* [*g] OSPTR was giving type uintptr to slice base pointers; undo that. This
arose, for example, while compiling copy(dst, src).

* [8g] 64 bit float conversion was assigning int64 type during codegen,
overwriting the existing uint64 type.

Note that some etype mismatches are appropriate, such as a struct with a single
field or an array with a single element.

With these fixes, the number of registerizations that occur while running
make.bash for 6g increases ~10%. Hello world binary size shrinks ~1.5%. Running
all benchmarks in the standard library show performance improvements ranging
from nominal to substantive (>10%); a full comparison using 6g on my laptop is
available at https://gist.github.com/josharian/8f9b5beb46667c272064. The
microbenchmarks must be taken with a grain of salt; see issue 7920. The few
benchmarks that show real regressions are likely due to issue 7920. I manually
examined the generated code for the top few regressions and none had any
assembly output changes. The few benchmarks that show extraordinary improvements
are likely also due to issue 7920.

Performance results from 8g appear similar to 6g.

5g shows no performance improvements. This is not surprising, given the
discussion above.

Update issue 7316

LGTM=rsc
R=rsc, daniel.morsing, bradfitz
CC=dave, golang-codereviews
https://codereview.appspot.com/91850043

Committer: Russ Cox <rsc@golang.org>
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b