diff options
| author | Yi Yang <y1yang0x@gmail.com> | 2023-03-19 07:24:04 +0000 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-03-20 15:42:09 +0000 |
| commit | da4687923b8c2d42c23f61fa3db9f4d3ce0c5f54 (patch) | |
| tree | 1ef4b8154e95c82e6150b25cb9abaa256a32652e /test/codegen | |
| parent | b414ba4c993e38b0c5241f9d36021423afeb05ed (diff) | |
| download | go-da4687923b8c2d42c23f61fa3db9f4d3ce0c5f54.tar.xz | |
cmd/compile: add rewrite rules for arithmetic operations
Add the following common local transformations
(t + x) - (t + y) == x - y
(t + x) - (y + t) == x - y
(x + t) - (y + t) == x - y
(x + t) - (t + y) == x - y
(x - t) + (t + y) == x + y
(x - t) + (y + t) == x + y
The compiler itself matches such patterns many times. This also aligns with other popular compilers.
Fixes #59111
Change-Id: Ibdfdb414782f8fcaa20b84ac5d43d0d9ae2c7b60
GitHub-Last-Rev: 1aad82e62e61e89789932c2070851a023f130dd8
GitHub-Pull-Request: golang/go#59119
Reviewed-on: https://go-review.googlesource.com/c/go/+/477555
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
Diffstat (limited to 'test/codegen')
| -rw-r--r-- | test/codegen/arithmetic.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/test/codegen/arithmetic.go b/test/codegen/arithmetic.go index 2f06ac58d6..f381b34ade 100644 --- a/test/codegen/arithmetic.go +++ b/test/codegen/arithmetic.go @@ -92,6 +92,22 @@ func SubAddSimplify(a, b int) int { return r } +func SubAddSimplify2(a, b, c int) (int, int, int, int, int, int) { + // amd64:-"ADDQ" + r := (a + b) - (a + c) + // amd64:-"ADDQ" + r1 := (a + b) - (c + a) + // amd64:-"ADDQ" + r2 := (b + a) - (a + c) + // amd64:-"ADDQ" + r3 := (b + a) - (c + a) + // amd64:-"SUBQ" + r4 := (a - c) + (c + b) + // amd64:-"SUBQ" + r5 := (a - c) + (b + c) + return r, r1, r2, r3, r4, r5 +} + func SubAddNegSimplify(a, b int) int { // amd64:"NEGQ",-"ADDQ",-"SUBQ" // ppc64x:"NEG",-"ADD",-"SUB" |
