[go] cmd/compile: add subtraction cancellation rule x-(x-y)==y

5 views
Skip to first unread message

Gerrit Bot (Gerrit)

unread,
Jul 9, 2026, 8:17:02 AM (13 days ago) Jul 9
to goph...@pubsubhelper.golang.org, Khashayar Fereidani, golang-co...@googlegroups.com

Gerrit Bot has uploaded the change for review

Commit message

cmd/compile: add subtraction cancellation rule x-(x-y)==y

cmd/compile: add subtraction cancellation rule x-(x-y)==y closes #80320
Change-Id: I5bde48776bab75d147c6612fa3c98c3463d3c8fb
GitHub-Last-Rev: c6f35f91e9dfa6b61d6eac42f0dda1da778cd96b
GitHub-Pull-Request: golang/go#80321

Change diff

diff --git a/src/cmd/compile/internal/ssa/_gen/generic.rules b/src/cmd/compile/internal/ssa/_gen/generic.rules
index 84cf50a..c6bcc8f 100644
--- a/src/cmd/compile/internal/ssa/_gen/generic.rules
+++ b/src/cmd/compile/internal/ssa/_gen/generic.rules
@@ -212,6 +212,9 @@
(And(8|16|32|64) x (Or(8|16|32|64) x y)) => x
(Or(8|16|32|64) x (And(8|16|32|64) x y)) => x

+// Subtraction cancellation: x - (x - y) == y
+(Sub(8|16|32|64) x (Sub(8|16|32|64) x y)) => y
+
(Mod8 (Const8 [c]) (Const8 [d])) && d != 0 => (Const8 [c % d])
(Mod16 (Const16 [c]) (Const16 [d])) && d != 0 => (Const16 [c % d])
(Mod32 (Const32 [c]) (Const32 [d])) && d != 0 => (Const32 [c % d])
diff --git a/src/cmd/compile/internal/ssa/rewritegeneric.go b/src/cmd/compile/internal/ssa/rewritegeneric.go
index e39e08d..f43594a 100644
--- a/src/cmd/compile/internal/ssa/rewritegeneric.go
+++ b/src/cmd/compile/internal/ssa/rewritegeneric.go
@@ -35627,6 +35627,20 @@
v.AuxInt = int16ToAuxInt(c - d)
return true
}
+ // match: (Sub16 x (Sub16 x y))
+ // result: y
+ for {
+ x := v_0
+ if v_1.Op != OpSub16 {
+ break
+ }
+ y := v_1.Args[1]
+ if x != v_1.Args[0] {
+ break
+ }
+ v.copyOf(y)
+ return true
+ }
// match: (Sub16 x (Const16 <t> [c]))
// cond: x.Op != OpConst16
// result: (Add16 (Const16 <t> [-c]) x)
@@ -36000,6 +36014,20 @@
v.AuxInt = int32ToAuxInt(c - d)
return true
}
+ // match: (Sub32 x (Sub32 x y))
+ // result: y
+ for {
+ x := v_0
+ if v_1.Op != OpSub32 {
+ break
+ }
+ y := v_1.Args[1]
+ if x != v_1.Args[0] {
+ break
+ }
+ v.copyOf(y)
+ return true
+ }
// match: (Sub32 x (Const32 <t> [c]))
// cond: x.Op != OpConst32
// result: (Add32 (Const32 <t> [-c]) x)
@@ -36397,6 +36425,20 @@
v.AuxInt = int64ToAuxInt(c - d)
return true
}
+ // match: (Sub64 x (Sub64 x y))
+ // result: y
+ for {
+ x := v_0
+ if v_1.Op != OpSub64 {
+ break
+ }
+ y := v_1.Args[1]
+ if x != v_1.Args[0] {
+ break
+ }
+ v.copyOf(y)
+ return true
+ }
// match: (Sub64 x (Const64 <t> [c]))
// cond: x.Op != OpConst64
// result: (Add64 (Const64 <t> [-c]) x)
@@ -36794,6 +36836,20 @@
v.AuxInt = int8ToAuxInt(c - d)
return true
}
+ // match: (Sub8 x (Sub8 x y))
+ // result: y
+ for {
+ x := v_0
+ if v_1.Op != OpSub8 {
+ break
+ }
+ y := v_1.Args[1]
+ if x != v_1.Args[0] {
+ break
+ }
+ v.copyOf(y)
+ return true
+ }
// match: (Sub8 x (Const8 <t> [c]))
// cond: x.Op != OpConst8
// result: (Add8 (Const8 <t> [-c]) x)

Change information

Files:
  • M src/cmd/compile/internal/ssa/_gen/generic.rules
  • M src/cmd/compile/internal/ssa/rewritegeneric.go
Change size: M
Delta: 2 files changed, 59 insertions(+), 0 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I5bde48776bab75d147c6612fa3c98c3463d3c8fb
Gerrit-Change-Number: 798780
Gerrit-PatchSet: 1
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-CC: Khashayar Fereidani <in...@fereidani.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Gopher Robot (Gerrit)

unread,
Jul 9, 2026, 8:17:05 AM (13 days ago) Jul 9
to Khashayar Fereidani, Gerrit Bot, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Gopher Robot added 1 comment

Patchset-level comments
File-level comment, Patchset 1 (Latest):
Gopher Robot . unresolved

I spotted some possible problems with your PR:

  1. Do you have the right bug reference format? For this repo, the format is usually 'Fixes #12345' or 'Updates #12345' at the end of the commit message.

Please address any problems by updating the GitHub PR.

When complete, mark this comment as 'Done' and click the [blue 'Reply' button](https://go.dev/wiki/GerritBot#i-left-a-reply-to-a-comment-in-gerrit-but-no-one-but-me-can-see-it) above. These findings are based on heuristics; if a finding does not apply, briefly reply here saying so.

To update the commit title or commit message body shown here in Gerrit, you must edit the GitHub PR title and PR description (the first comment) in the GitHub web interface using the 'Edit' button or 'Edit' menu entry there. Note: pushing a new commit to the PR will not automatically update the commit message used by Gerrit.

For more details, see:

(In general for Gerrit code reviews, the change author is expected to [log in to Gerrit](https://go-review.googlesource.com/login/) with a Gmail or other Google account and then close out each piece of feedback by marking it as 'Done' if implemented as suggested or otherwise reply to each review comment. See the [Review](https://go.dev/doc/contribute#review) section of the Contributing Guide for details.)

Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I5bde48776bab75d147c6612fa3c98c3463d3c8fb
    Gerrit-Change-Number: 798780
    Gerrit-PatchSet: 1
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-CC: Khashayar Fereidani <in...@fereidani.com>
    Gerrit-Comment-Date: Thu, 09 Jul 2026 12:16:58 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    open
    diffy

    Jorropo (Gerrit)

    unread,
    Jul 9, 2026, 8:39:16 AM (13 days ago) Jul 9
    to Khashayar Fereidani, Gerrit Bot, goph...@pubsubhelper.golang.org, Keith Randall, Martin Möhrmann, Gopher Robot, golang-co...@googlegroups.com
    Attention needed from Keith Randall and Martin Möhrmann

    Jorropo voted and added 1 comment

    Votes added by Jorropo

    Auto-Submit+1
    Code-Review+2
    Commit-Queue+1

    1 comment

    Patchset-level comments
    Gopher Robot . resolved

    I spotted some possible problems with your PR:

      1. Do you have the right bug reference format? For this repo, the format is usually 'Fixes #12345' or 'Updates #12345' at the end of the commit message.

    Please address any problems by updating the GitHub PR.

    When complete, mark this comment as 'Done' and click the [blue 'Reply' button](https://go.dev/wiki/GerritBot#i-left-a-reply-to-a-comment-in-gerrit-but-no-one-but-me-can-see-it) above. These findings are based on heuristics; if a finding does not apply, briefly reply here saying so.

    To update the commit title or commit message body shown here in Gerrit, you must edit the GitHub PR title and PR description (the first comment) in the GitHub web interface using the 'Edit' button or 'Edit' menu entry there. Note: pushing a new commit to the PR will not automatically update the commit message used by Gerrit.

    For more details, see:

    (In general for Gerrit code reviews, the change author is expected to [log in to Gerrit](https://go-review.googlesource.com/login/) with a Gmail or other Google account and then close out each piece of feedback by marking it as 'Done' if implemented as suggested or otherwise reply to each review comment. See the [Review](https://go.dev/doc/contribute#review) section of the Contributing Guide for details.)

    Jorropo

    Done

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Keith Randall
    • Martin Möhrmann
    Submit Requirements:
    • requirement satisfiedCode-Review
    • requirement satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I5bde48776bab75d147c6612fa3c98c3463d3c8fb
    Gerrit-Change-Number: 798780
    Gerrit-PatchSet: 1
    Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
    Gerrit-Reviewer: Jorropo <jorro...@gmail.com>
    Gerrit-Reviewer: Keith Randall <k...@golang.org>
    Gerrit-Reviewer: Martin Möhrmann <moeh...@google.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-CC: Khashayar Fereidani <in...@fereidani.com>
    Gerrit-Attention: Keith Randall <k...@golang.org>
    Gerrit-Attention: Martin Möhrmann <moeh...@google.com>
    Gerrit-Comment-Date: Thu, 09 Jul 2026 12:39:08 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: Yes
    Comment-In-Reply-To: Gopher Robot <go...@golang.org>
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Gerrit Bot (Gerrit)

    unread,
    Jul 9, 2026, 8:51:16 AM (13 days ago) Jul 9
    to Khashayar Fereidani, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
    Attention needed from Jorropo, Keith Randall and Martin Möhrmann

    Gerrit Bot uploaded new patchset

    Gerrit Bot uploaded patch set #2 to this change.
    Open in Gerrit

    Related details

    Attention is currently required from:
    • Jorropo
    • Keith Randall
    • Martin Möhrmann
    Submit Requirements:
      • requirement satisfiedCode-Review
      • requirement satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedNo-Wait-Release
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: newpatchset
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I5bde48776bab75d147c6612fa3c98c3463d3c8fb
      Gerrit-Change-Number: 798780
      Gerrit-PatchSet: 2
      Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
      Gerrit-Reviewer: Jorropo <jorro...@gmail.com>
      Gerrit-Reviewer: Keith Randall <k...@golang.org>
      Gerrit-Reviewer: Martin Möhrmann <moeh...@google.com>
      Gerrit-CC: Gopher Robot <go...@golang.org>
      Gerrit-CC: Khashayar Fereidani <in...@fereidani.com>
      Gerrit-Attention: Keith Randall <k...@golang.org>
      Gerrit-Attention: Jorropo <jorro...@gmail.com>
      Gerrit-Attention: Martin Möhrmann <moeh...@google.com>
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Jorropo (Gerrit)

      unread,
      Jul 9, 2026, 10:53:22 AM (12 days ago) Jul 9
      to Khashayar Fereidani, Gerrit Bot, goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Keith Randall, Martin Möhrmann, Gopher Robot, golang-co...@googlegroups.com
      Attention needed from Keith Randall and Martin Möhrmann

      Jorropo voted and added 1 comment

      Votes added by Jorropo

      Code-Review+2

      1 comment

      Patchset-level comments
      File-level comment, Patchset 2 (Latest):
      Jorropo . unresolved

      You need to rebase on latest master to fix the CI failure.

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Keith Randall
      • Martin Möhrmann
      Submit Requirements:
      • requirement satisfiedCode-Review
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedNo-Wait-Release
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I5bde48776bab75d147c6612fa3c98c3463d3c8fb
      Gerrit-Change-Number: 798780
      Gerrit-PatchSet: 2
      Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
      Gerrit-Reviewer: Jorropo <jorro...@gmail.com>
      Gerrit-Reviewer: Keith Randall <k...@golang.org>
      Gerrit-Reviewer: Martin Möhrmann <moeh...@google.com>
      Gerrit-CC: Gopher Robot <go...@golang.org>
      Gerrit-CC: Khashayar Fereidani <in...@fereidani.com>
      Gerrit-Attention: Keith Randall <k...@golang.org>
      Gerrit-Attention: Martin Möhrmann <moeh...@google.com>
      Gerrit-Comment-Date: Thu, 09 Jul 2026 14:53:14 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: Yes
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Keith Randall (Gerrit)

      unread,
      Jul 9, 2026, 12:18:53 PM (12 days ago) Jul 9
      to Khashayar Fereidani, Gerrit Bot, goph...@pubsubhelper.golang.org, Keith Randall, golang...@luci-project-accounts.iam.gserviceaccount.com, Jorropo, Martin Möhrmann, Gopher Robot, golang-co...@googlegroups.com
      Attention needed from Martin Möhrmann

      Keith Randall voted and added 1 comment

      Votes added by Keith Randall

      Code-Review+2

      1 comment

      File src/cmd/compile/internal/ssa/_gen/generic.rules
      Line 656, Patchset 2 (Parent):
      Keith Randall . unresolved

      Maybe move the new rules down here somewhere?

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Martin Möhrmann
      Submit Requirements:
      • requirement satisfiedCode-Review
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedNo-Wait-Release
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I5bde48776bab75d147c6612fa3c98c3463d3c8fb
      Gerrit-Change-Number: 798780
      Gerrit-PatchSet: 2
      Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
      Gerrit-Reviewer: Jorropo <jorro...@gmail.com>
      Gerrit-Reviewer: Keith Randall <k...@golang.org>
      Gerrit-Reviewer: Martin Möhrmann <moeh...@google.com>
      Gerrit-CC: Gopher Robot <go...@golang.org>
      Gerrit-CC: Khashayar Fereidani <in...@fereidani.com>
      Gerrit-Attention: Martin Möhrmann <moeh...@google.com>
      Gerrit-Comment-Date: Thu, 09 Jul 2026 16:18:47 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: Yes
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Keith Randall (Gerrit)

      unread,
      Jul 9, 2026, 12:19:01 PM (12 days ago) Jul 9
      to Khashayar Fereidani, Gerrit Bot, goph...@pubsubhelper.golang.org, Keith Randall, golang...@luci-project-accounts.iam.gserviceaccount.com, Jorropo, Martin Möhrmann, Gopher Robot, golang-co...@googlegroups.com
      Attention needed from Martin Möhrmann

      Keith Randall voted Code-Review+1

      Code-Review+1
      Open in Gerrit

      Related details

      Attention is currently required from:
      • Martin Möhrmann
      Submit Requirements:
      • requirement satisfiedCode-Review
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedNo-Wait-Release
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I5bde48776bab75d147c6612fa3c98c3463d3c8fb
      Gerrit-Change-Number: 798780
      Gerrit-PatchSet: 2
      Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
      Gerrit-Reviewer: Jorropo <jorro...@gmail.com>
      Gerrit-Reviewer: Keith Randall <k...@golang.org>
      Gerrit-Reviewer: Keith Randall <k...@google.com>
      Gerrit-Reviewer: Martin Möhrmann <moeh...@google.com>
      Gerrit-CC: Gopher Robot <go...@golang.org>
      Gerrit-CC: Khashayar Fereidani <in...@fereidani.com>
      Gerrit-Attention: Martin Möhrmann <moeh...@google.com>
      Gerrit-Comment-Date: Thu, 09 Jul 2026 16:18:56 +0000
      Gerrit-HasComments: No
      Gerrit-Has-Labels: Yes
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Gerrit Bot (Gerrit)

      unread,
      Jul 9, 2026, 4:13:17 PM (12 days ago) Jul 9
      to Khashayar Fereidani, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
      Attention needed from Jorropo, Keith Randall, Keith Randall and Martin Möhrmann

      Gerrit Bot uploaded new patchset

      Gerrit Bot uploaded patch set #3 to this change.
      Following approvals got outdated and were removed:
      Open in Gerrit

      Related details

      Attention is currently required from:
      • Jorropo
      • Keith Randall
      • Keith Randall
      • Martin Möhrmann
      Submit Requirements:
      • requirement satisfiedCode-Review
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedNo-Wait-Release
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: newpatchset
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I5bde48776bab75d147c6612fa3c98c3463d3c8fb
      Gerrit-Change-Number: 798780
      Gerrit-PatchSet: 3
      Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
      Gerrit-Reviewer: Jorropo <jorro...@gmail.com>
      Gerrit-Reviewer: Keith Randall <k...@golang.org>
      Gerrit-Reviewer: Keith Randall <k...@google.com>
      Gerrit-Reviewer: Martin Möhrmann <moeh...@google.com>
      Gerrit-CC: Gopher Robot <go...@golang.org>
      Gerrit-CC: Khashayar Fereidani <in...@fereidani.com>
      Gerrit-Attention: Keith Randall <k...@golang.org>
      Gerrit-Attention: Jorropo <jorro...@gmail.com>
      Gerrit-Attention: Martin Möhrmann <moeh...@google.com>
      Gerrit-Attention: Keith Randall <k...@google.com>
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Khashayar Fereidani (Gerrit)

      unread,
      Jul 9, 2026, 5:21:05 PM (12 days ago) Jul 9
      to Gerrit Bot, goph...@pubsubhelper.golang.org, Keith Randall, Keith Randall, golang...@luci-project-accounts.iam.gserviceaccount.com, Jorropo, Martin Möhrmann, Gopher Robot, golang-co...@googlegroups.com
      Attention needed from Jorropo, Keith Randall, Keith Randall and Martin Möhrmann

      Khashayar Fereidani added 2 comments

      Patchset-level comments

      You need to rebase on latest master to fix the CI failure.

      Khashayar Fereidani

      Done.

      File src/cmd/compile/internal/ssa/_gen/generic.rules
      Keith Randall . unresolved

      Maybe move the new rules down here somewhere?

      Khashayar Fereidani

      Sure. Should I keep the comment, or is it better to remove it?

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Jorropo
      • Keith Randall
      • Keith Randall
      • Martin Möhrmann
      Submit Requirements:
      • requirement satisfiedCode-Review
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedNo-Wait-Release
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I5bde48776bab75d147c6612fa3c98c3463d3c8fb
      Gerrit-Change-Number: 798780
      Gerrit-PatchSet: 3
      Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
      Gerrit-Reviewer: Jorropo <jorro...@gmail.com>
      Gerrit-Reviewer: Keith Randall <k...@golang.org>
      Gerrit-Reviewer: Keith Randall <k...@google.com>
      Gerrit-Reviewer: Martin Möhrmann <moeh...@google.com>
      Gerrit-CC: Gopher Robot <go...@golang.org>
      Gerrit-CC: Khashayar Fereidani <in...@fereidani.com>
      Gerrit-Attention: Keith Randall <k...@golang.org>
      Gerrit-Attention: Jorropo <jorro...@gmail.com>
      Gerrit-Attention: Martin Möhrmann <moeh...@google.com>
      Gerrit-Attention: Keith Randall <k...@google.com>
      Gerrit-Comment-Date: Thu, 09 Jul 2026 21:20:55 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      Comment-In-Reply-To: Keith Randall <k...@golang.org>
      Comment-In-Reply-To: Jorropo <jorro...@gmail.com>
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Keith Randall (Gerrit)

      unread,
      Jul 9, 2026, 6:19:24 PM (12 days ago) Jul 9
      to Khashayar Fereidani, Gerrit Bot, goph...@pubsubhelper.golang.org, Keith Randall, Keith Randall, golang...@luci-project-accounts.iam.gserviceaccount.com, Jorropo, Martin Möhrmann, Gopher Robot, golang-co...@googlegroups.com
      Attention needed from Jorropo, Keith Randall and Martin Möhrmann

      Keith Randall voted and added 1 comment

      Votes added by Keith Randall

      Code-Review+2

      1 comment

      File src/cmd/compile/internal/ssa/_gen/generic.rules
      Keith Randall . unresolved

      Maybe move the new rules down here somewhere?

      Khashayar Fereidani

      Sure. Should I keep the comment, or is it better to remove it?

      Keith Randall

      The comment is good. More of these rules should have comments.

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Jorropo
      • Keith Randall
      • Martin Möhrmann
      Submit Requirements:
      • requirement satisfiedCode-Review
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedNo-Wait-Release
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I5bde48776bab75d147c6612fa3c98c3463d3c8fb
      Gerrit-Change-Number: 798780
      Gerrit-PatchSet: 3
      Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
      Gerrit-Reviewer: Jorropo <jorro...@gmail.com>
      Gerrit-Reviewer: Keith Randall <k...@golang.org>
      Gerrit-Reviewer: Keith Randall <k...@google.com>
      Gerrit-Reviewer: Martin Möhrmann <moeh...@google.com>
      Gerrit-CC: Gopher Robot <go...@golang.org>
      Gerrit-CC: Khashayar Fereidani <in...@fereidani.com>
      Gerrit-Attention: Jorropo <jorro...@gmail.com>
      Gerrit-Attention: Martin Möhrmann <moeh...@google.com>
      Gerrit-Attention: Keith Randall <k...@google.com>
      Gerrit-Comment-Date: Thu, 09 Jul 2026 22:19:19 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: Yes
      Comment-In-Reply-To: Keith Randall <k...@golang.org>
      Comment-In-Reply-To: Khashayar Fereidani <in...@fereidani.com>
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Gerrit Bot (Gerrit)

      unread,
      Jul 20, 2026, 10:45:44 PM (24 hours ago) Jul 20
      to Khashayar Fereidani, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
      Attention needed from Jorropo, Keith Randall, Keith Randall and Martin Möhrmann

      Gerrit Bot uploaded new patchset

      Gerrit Bot uploaded patch set #4 to this change.
      Following approvals got outdated and were removed:
      • Code-Review: +2 by Jorropo, +1 by Keith Randall, +2 by Keith Randall
      Open in Gerrit

      Related details

      Attention is currently required from:
      • Jorropo
      • Keith Randall
      • Keith Randall
      • Martin Möhrmann
      Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: newpatchset
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I5bde48776bab75d147c6612fa3c98c3463d3c8fb
      Gerrit-Change-Number: 798780
      Gerrit-PatchSet: 4
      Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
      Gerrit-Reviewer: Jorropo <jorro...@gmail.com>
      Gerrit-Reviewer: Keith Randall <k...@golang.org>
      Gerrit-Reviewer: Keith Randall <k...@google.com>
      Gerrit-Reviewer: Martin Möhrmann <moeh...@google.com>
      Gerrit-CC: Gopher Robot <go...@golang.org>
      Gerrit-CC: Khashayar Fereidani <in...@fereidani.com>
      Gerrit-Attention: Keith Randall <k...@golang.org>
      unsatisfied_requirement
      open
      diffy

      Gerrit Bot (Gerrit)

      unread,
      Jul 20, 2026, 11:52:04 PM (23 hours ago) Jul 20
      to Khashayar Fereidani, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
      Attention needed from Jorropo, Keith Randall, Keith Randall and Martin Möhrmann

      Gerrit Bot uploaded new patchset

      Gerrit Bot uploaded patch set #5 to this change.
      Open in Gerrit

      Related details

      Attention is currently required from:
      • Jorropo
      • Keith Randall
      • Keith Randall
      • Martin Möhrmann
      Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: newpatchset
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I5bde48776bab75d147c6612fa3c98c3463d3c8fb
      Gerrit-Change-Number: 798780
      Gerrit-PatchSet: 5
      unsatisfied_requirement
      open
      diffy

      Keith Randall (Gerrit)

      unread,
      4:26 PM (6 hours ago) 4:26 PM
      to Khashayar Fereidani, Gerrit Bot, goph...@pubsubhelper.golang.org, Keith Randall, Keith Randall, golang...@luci-project-accounts.iam.gserviceaccount.com, Jorropo, Martin Möhrmann, Gopher Robot, golang-co...@googlegroups.com
      Attention needed from Jorropo, Keith Randall and Martin Möhrmann

      Keith Randall added 1 comment

      Patchset-level comments
      File-level comment, Patchset 5 (Latest):
      Keith Randall . unresolved

      This seems to have gotten a whole bunch more rules in patch set 4. Was that intentional?

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Jorropo
      • Keith Randall
      • Martin Möhrmann
      Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I5bde48776bab75d147c6612fa3c98c3463d3c8fb
      Gerrit-Change-Number: 798780
      Gerrit-PatchSet: 5
      Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
      Gerrit-Reviewer: Jorropo <jorro...@gmail.com>
      Gerrit-Reviewer: Keith Randall <k...@golang.org>
      Gerrit-Reviewer: Keith Randall <k...@google.com>
      Gerrit-Reviewer: Martin Möhrmann <moeh...@google.com>
      Gerrit-CC: Gopher Robot <go...@golang.org>
      Gerrit-CC: Khashayar Fereidani <in...@fereidani.com>
      Gerrit-Attention: Jorropo <jorro...@gmail.com>
      Gerrit-Attention: Martin Möhrmann <moeh...@google.com>
      Gerrit-Attention: Keith Randall <k...@google.com>
      Gerrit-Comment-Date: Tue, 21 Jul 2026 20:25:57 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      unsatisfied_requirement
      open
      diffy

      Khashayar Fereidani (Gerrit)

      unread,
      6:51 PM (4 hours ago) 6:51 PM
      to Gerrit Bot, goph...@pubsubhelper.golang.org, Keith Randall, Keith Randall, golang...@luci-project-accounts.iam.gserviceaccount.com, Jorropo, Martin Möhrmann, Gopher Robot, golang-co...@googlegroups.com
      Attention needed from Jorropo, Keith Randall, Keith Randall and Martin Möhrmann

      Khashayar Fereidani added 1 comment

      Patchset-level comments
      Keith Randall . resolved

      This seems to have gotten a whole bunch more rules in patch set 4. Was that intentional?

      Khashayar Fereidani

      Yes, These are result of 3000+ popular go programs/libraries super-optimizer harvest, I'll send the exact samples to the issue for each added rule so we can discuss them.

      Gerrit-Attention: Keith Randall <k...@golang.org>
      Gerrit-Attention: Jorropo <jorro...@gmail.com>
      Gerrit-Attention: Martin Möhrmann <moeh...@google.com>
      Gerrit-Attention: Keith Randall <k...@google.com>
      Gerrit-Comment-Date: Tue, 21 Jul 2026 22:51:47 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      Comment-In-Reply-To: Keith Randall <k...@golang.org>
      unsatisfied_requirement
      open
      diffy

      Khashayar Fereidani (Gerrit)

      unread,
      6:52 PM (4 hours ago) 6:52 PM
      to Gerrit Bot, goph...@pubsubhelper.golang.org, Keith Randall, Keith Randall, golang...@luci-project-accounts.iam.gserviceaccount.com, Jorropo, Martin Möhrmann, Gopher Robot, golang-co...@googlegroups.com
      Attention needed from Jorropo, Keith Randall, Keith Randall and Martin Möhrmann

      Khashayar Fereidani added 1 comment

      File src/cmd/compile/internal/ssa/_gen/generic.rules
      Keith Randall . resolved

      Maybe move the new rules down here somewhere?

      Khashayar Fereidani

      Sure. Should I keep the comment, or is it better to remove it?

      Keith Randall

      The comment is good. More of these rules should have comments.

      Khashayar Fereidani

      Done

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Jorropo
      • Keith Randall
      • Keith Randall
      • Martin Möhrmann
      Submit Requirements:
        • requirement is not satisfiedCode-Review
        • requirement satisfiedNo-Unresolved-Comments
        • requirement is not satisfiedReview-Enforcement
        • requirement is not satisfiedTryBots-Pass
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: comment
        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: I5bde48776bab75d147c6612fa3c98c3463d3c8fb
        Gerrit-Change-Number: 798780
        Gerrit-PatchSet: 5
        Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
        Gerrit-Reviewer: Jorropo <jorro...@gmail.com>
        Gerrit-Reviewer: Keith Randall <k...@golang.org>
        Gerrit-Reviewer: Keith Randall <k...@google.com>
        Gerrit-Reviewer: Martin Möhrmann <moeh...@google.com>
        Gerrit-CC: Gopher Robot <go...@golang.org>
        Gerrit-CC: Khashayar Fereidani <in...@fereidani.com>
        Gerrit-Attention: Keith Randall <k...@golang.org>
        Gerrit-Attention: Jorropo <jorro...@gmail.com>
        Gerrit-Attention: Martin Möhrmann <moeh...@google.com>
        Gerrit-Attention: Keith Randall <k...@google.com>
        Gerrit-Comment-Date: Tue, 21 Jul 2026 22:52:24 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: No
        Comment-In-Reply-To: Keith Randall <k...@golang.org>
        Comment-In-Reply-To: Khashayar Fereidani <in...@fereidani.com>
        unsatisfied_requirement
        satisfied_requirement
        open
        diffy

        Jorropo (Gerrit)

        unread,
        7:16 PM (3 hours ago) 7:16 PM
        to Khashayar Fereidani, Gerrit Bot, goph...@pubsubhelper.golang.org, Keith Randall, Keith Randall, golang...@luci-project-accounts.iam.gserviceaccount.com, Martin Möhrmann, Gopher Robot, golang-co...@googlegroups.com
        Attention needed from Keith Randall, Keith Randall and Martin Möhrmann

        Jorropo voted and added 2 comments

        Votes added by Jorropo

        Commit-Queue+1

        2 comments

        Commit Message
        Line 7, Patchset 5 (Latest):cmd/compile: add subtraction cancellation rule x-(x-y)==y
        Jorropo . unresolved

        That not accurate

        File src/cmd/compile/internal/ssa/_gen/generic.rules
        Line 2566, Patchset 5 (Latest):
        // ----------------------------------------------------------------------------
        // Disabled example rules (https://github.com/golang/go/issues/80320).
        //
        // The identities below are correct (SMT-verified over all inputs at every
        // width) and are implemented in the rule DSL, but they are intentionally
        // left commented out. Rules of this kind have not been proven useful in
        // practice: a survey of real Go code found no natural occurrence of these
        // patterns, and the bar for enabling a rewrite rule in this file is at
        // least one real-world Go program that demonstrably benefits. Speculative
        // rules add matching work to every compilation and a permanent maintenance
        // and testing burden without demonstrated payoff.
        //
        // They are recorded here as reference implementations. If you find Go code
        // in the wild that would naturally be improved by one of these rules, please
        // open a pull request enabling that rule, citing the motivating code and the
        // issue above.
        //
        // x | (^x & y) == x | y
        //(Or(64|32|16|8) x (And(64|32|16|8) (Com(64|32|16|8) x) y)) => (Or(64|32|16|8) x y)
        //
        // x & (^x | y) == x & y
        //(And(64|32|16|8) x (Or(64|32|16|8) (Com(64|32|16|8) x) y)) => (And(64|32|16|8) x y)
        //
        // (x & y) | (x & ^y) == x
        //(Or(64|32|16|8) (And(64|32|16|8) x y) (And(64|32|16|8) x (Com(64|32|16|8) y))) => x
        //
        // (x | y) & (x | ^y) == x
        //(And(64|32|16|8) (Or(64|32|16|8) x y) (Or(64|32|16|8) x (Com(64|32|16|8) y))) => x
        //
        // (x | y) - (x & y) == x ^ y
        //(Sub(64|32|16|8) (Or(64|32|16|8) x y) (And(64|32|16|8) x y)) => (Xor(64|32|16|8) x y)
        //
        // (x ^ y) ^ (x | y) == x & y
        //(Xor(64|32|16|8) (Xor(64|32|16|8) x y) (Or(64|32|16|8) x y)) => (And(64|32|16|8) x y)
        //
        // (x ^ y) ^ (x & y) == x | y
        //(Xor(64|32|16|8) (Xor(64|32|16|8) x y) (And(64|32|16|8) x y)) => (Or(64|32|16|8) x y)
        //
        // (x & y) + (x | y) == x + y
        //(Add(64|32|16|8) (And(64|32|16|8) x y) (Or(64|32|16|8) x y)) => (Add(64|32|16|8) x y)
        Jorropo . unresolved

        Please don't add commented out code.

        Open in Gerrit

        Related details

        Attention is currently required from:
        • Keith Randall
        • Keith Randall
        • Martin Möhrmann
        Submit Requirements:
          • requirement is not satisfiedCode-Review
          • requirement is not satisfiedNo-Unresolved-Comments
          • requirement is not satisfiedReview-Enforcement
          • requirement is not satisfiedTryBots-Pass
          Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
          Gerrit-MessageType: comment
          Gerrit-Project: go
          Gerrit-Branch: master
          Gerrit-Change-Id: I5bde48776bab75d147c6612fa3c98c3463d3c8fb
          Gerrit-Change-Number: 798780
          Gerrit-PatchSet: 5
          Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
          Gerrit-Reviewer: Jorropo <jorro...@gmail.com>
          Gerrit-Reviewer: Keith Randall <k...@golang.org>
          Gerrit-Reviewer: Keith Randall <k...@google.com>
          Gerrit-Reviewer: Martin Möhrmann <moeh...@google.com>
          Gerrit-CC: Gopher Robot <go...@golang.org>
          Gerrit-CC: Khashayar Fereidani <in...@fereidani.com>
          Gerrit-Attention: Keith Randall <k...@golang.org>
          Gerrit-Attention: Martin Möhrmann <moeh...@google.com>
          Gerrit-Attention: Keith Randall <k...@google.com>
          Gerrit-Comment-Date: Tue, 21 Jul 2026 23:16:51 +0000
          Gerrit-HasComments: Yes
          Gerrit-Has-Labels: Yes
          unsatisfied_requirement
          open
          diffy
          Reply all
          Reply to author
          Forward
          0 new messages