]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: add rewrite rules for arithmetic operations
authorYi Yang <y1yang0x@gmail.com>
Sun, 19 Mar 2023 07:24:04 +0000 (07:24 +0000)
committerGopher Robot <gobot@golang.org>
Mon, 20 Mar 2023 15:42:09 +0000 (15:42 +0000)
commitda4687923b8c2d42c23f61fa3db9f4d3ce0c5f54
tree1ef4b8154e95c82e6150b25cb9abaa256a32652e
parentb414ba4c993e38b0c5241f9d36021423afeb05ed
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>
src/cmd/compile/internal/ssa/_gen/generic.rules
src/cmd/compile/internal/ssa/rewritegeneric.go
test/codegen/arithmetic.go