Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: add rewrite rules for arithmetic operations #59111

Closed
y1yang0 opened this issue Mar 18, 2023 · 2 comments
Closed

cmd/compile: add rewrite rules for arithmetic operations #59111

y1yang0 opened this issue Mar 18, 2023 · 2 comments
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge Performance
Milestone

Comments

@y1yang0
Copy link
Contributor

y1yang0 commented Mar 18, 2023

What version of Go are you using (go version)?

$ go version

Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

What did you do?

Hi, I found that we have a potential local optimization for subtraction involving common integers, which is also implemented in other compilers. i.e. (t + x) - (t + y) ==> x - y. The compiler itself matches such a pattern 303 times after a quick try, it seems that this could be a candidate for generic rules. I'd like to add it if you think it's worth doing. Thanks for your patience.

What did you expect to see?

What did you see instead?

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Mar 18, 2023
@randall77 randall77 added this to the Unplanned milestone Mar 18, 2023
@randall77
Copy link
Contributor

Sure.

@y1yang0 y1yang0 changed the title cmd/compile: rewrite rules to simplify subtraction when involving common integer cmd/compile: add rewrite rules for arithmetic operations Mar 19, 2023
y1yang0 added a commit to y1yang0/go that referenced this issue Mar 19, 2023
To align other popular compilers, 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

Fixes golang#59111
y1yang0 added a commit to y1yang0/go that referenced this issue Mar 19, 2023
To align other popular compilers, 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

Fixes golang#59111
y1yang0 added a commit to y1yang0/go that referenced this issue Mar 19, 2023
To align other popular compilers, 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

Fixes golang#59111
y1yang0 added a commit to y1yang0/go that referenced this issue Mar 19, 2023
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 golang#59111
@gopherbot
Copy link

Change https://go.dev/cl/477555 mentions this issue: cmd/compile: add rewrite rules for arithmetic operations

@golang golang locked and limited conversation to collaborators Mar 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge Performance
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants