Junyang Shao 4d6722a8fd cmd/compile: match more patterns for shortcircuit
This CL tries to generalize the pattern matching of certain
shortcircuit-able CFGs a bit more:
For a shortcircuit-able CFG:
p   q
 \ /
  b
 / \
t   u
Where the constant branch is t, and b has multiple phi values
other than the control phi.

For the non-constant branch target u, we try to match the
"diamond" shape CFG:
p   q
 \ /
  b
 / \
t   u
 \ /
  m

or

p   q
 \ /
  b
  |\
  | u
  |/
  m

Instead of matching u as a single block, we know try to
generalize it as a subgraph that satisfy condition:
it's a DAG that has a single entry point u, and has a
path to m.

compilebench stats:
                         │   old.txt   │              new.txt               │
                         │   sec/op    │   sec/op     vs base               │
Template                   109.4m ± 3%   109.8m ± 3%       ~ (p=0.796 n=10)
Unicode                    94.23m ± 1%   93.85m ± 1%       ~ (p=0.631 n=10)
GoTypes                    538.2m ± 1%   538.8m ± 1%       ~ (p=0.912 n=10)
Compiler                   90.21m ± 1%   90.02m ± 1%       ~ (p=0.436 n=10)
SSA                         3.318 ± 1%    3.323 ± 1%       ~ (p=1.000 n=10)
Flate                      69.38m ± 1%   69.57m ± 2%       ~ (p=0.529 n=10)
GoParser                   128.5m ± 1%   127.4m ± 1%       ~ (p=0.075 n=10)
Reflect                    267.4m ± 1%   267.2m ± 2%       ~ (p=0.739 n=10)
Tar                        127.7m ± 2%   126.4m ± 1%       ~ (p=0.353 n=10)
XML                        149.5m ± 1%   149.6m ± 2%       ~ (p=0.684 n=10)
LinkCompiler               390.0m ± 1%   388.4m ± 2%       ~ (p=0.353 n=10)
ExternalLinkCompiler        1.296 ± 0%    1.296 ± 1%       ~ (p=0.971 n=10)
LinkWithoutDebugCompiler   226.3m ± 1%   225.5m ± 1%       ~ (p=0.393 n=10)
StdCmd                      13.26 ± 0%    13.25 ± 1%       ~ (p=0.529 n=10)
geomean                    319.3m        318.8m       -0.17%

                         │   old.txt   │               new.txt               │
                         │ user-sec/op │ user-sec/op   vs base               │
Template                   293.1m ± 3%   291.4m ± 11%       ~ (p=0.436 n=10)
Unicode                    91.09m ± 5%   87.61m ±  7%       ~ (p=0.165 n=10)
GoTypes                     1.932 ± 3%    1.926 ±  3%       ~ (p=0.739 n=10)
Compiler                   125.8m ± 3%   121.5m ± 10%       ~ (p=0.481 n=10)
SSA                         18.93 ± 3%    18.89 ±  1%       ~ (p=0.684 n=10)
Flate                      158.5m ± 5%   160.0m ±  7%       ~ (p=0.971 n=10)
GoParser                   316.0m ± 9%   327.4m ±  7%       ~ (p=0.052 n=10)
Reflect                    845.6m ± 6%   861.6m ±  3%       ~ (p=0.579 n=10)
Tar                        358.1m ± 5%   348.5m ±  4%       ~ (p=0.089 n=10)
XML                        382.4m ± 4%   392.2m ±  3%       ~ (p=0.143 n=10)
LinkCompiler               609.1m ± 4%   627.9m ±  3%       ~ (p=0.123 n=10)
ExternalLinkCompiler        1.336 ± 2%    1.343 ±  4%       ~ (p=0.565 n=10)
LinkWithoutDebugCompiler   248.7m ± 3%   248.0m ±  1%       ~ (p=0.853 n=10)
geomean                    506.4m        506.8m        +0.08%

          │   old.txt    │               new.txt               │
          │  text-bytes  │  text-bytes   vs base               │
HelloSize   965.8Ki ± 0%   965.0Ki ± 0%  -0.08% (p=0.000 n=10)
CmdGoSize   12.30Mi ± 0%   12.29Mi ± 0%  -0.08% (p=0.000 n=10)
geomean     3.406Mi        3.403Mi       -0.08%

          │   old.txt    │                new.txt                │
          │  data-bytes  │  data-bytes   vs base                 │
HelloSize   15.08Ki ± 0%   15.08Ki ± 0%       ~ (p=1.000 n=10) ¹
CmdGoSize   408.5Ki ± 0%   408.5Ki ± 0%       ~ (p=1.000 n=10) ¹
geomean     78.49Ki        78.49Ki       +0.00%
¹ all samples are equal

          │   old.txt    │                new.txt                │
          │  bss-bytes   │  bss-bytes    vs base                 │
HelloSize   142.0Ki ± 0%   142.0Ki ± 0%       ~ (p=1.000 n=10) ¹
CmdGoSize   206.4Ki ± 0%   206.4Ki ± 0%       ~ (p=1.000 n=10) ¹
geomean     171.2Ki        171.2Ki       +0.00%
¹ all samples are equal

          │   old.txt    │               new.txt               │
          │  exe-bytes   │  exe-bytes    vs base               │
HelloSize   1.466Mi ± 0%   1.462Mi ± 0%  -0.27% (p=0.000 n=10)
CmdGoSize   18.19Mi ± 0%   18.17Mi ± 0%  -0.10% (p=0.000 n=10)
geomean     5.164Mi        5.154Mi       -0.18%

Fixes #72132

Change-Id: I3d1cb10b6a158c5750adc23c79709d63dbd771f3
Reviewed-on: https://go-review.googlesource.com/c/go/+/656255
Auto-Submit: Junyang Shao <shaojunyang@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
2025-03-27 12:30:03 -07:00
2025-03-20 04:38:55 -07:00
2024-08-09 14:54:31 +00:00
2010-12-06 16:31:59 -05:00
2024-07-22 17:45:27 +00:00

The Go Programming Language

Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.

Gopher image Gopher image by Renee French, licensed under Creative Commons 4.0 Attribution license.

Our canonical Git repository is located at https://go.googlesource.com/go. There is a mirror of the repository at https://github.com/golang/go.

Unless otherwise noted, the Go source files are distributed under the BSD-style license found in the LICENSE file.

Download and Install

Binary Distributions

Official binary distributions are available at https://go.dev/dl/.

After downloading a binary release, visit https://go.dev/doc/install for installation instructions.

Install From Source

If a binary distribution is not available for your combination of operating system and architecture, visit https://go.dev/doc/install/source for source installation instructions.

Contributing

Go is the work of thousands of contributors. We appreciate your help!

To contribute, please read the contribution guidelines at https://go.dev/doc/contribute.

Note that the Go project uses the issue tracker for bug reports and proposals only. See https://go.dev/wiki/Questions for a list of places to ask questions about the Go language.

Description
Languages
Go 94.1%
Assembly 5.5%
C 0.2%
Shell 0.1%