]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: optimize Add64carry with unused carries into plain Add64
authorJorropo <jorropo.pgm@gmail.com>
Mon, 10 Mar 2025 08:27:39 +0000 (09:27 +0100)
committerGopher Robot <gobot@golang.org>
Tue, 28 Oct 2025 02:07:38 +0000 (19:07 -0700)
Change-Id: I8a63f567cfc574bb066ad6269eec6929760cb9c3
Reviewed-on: https://go-review.googlesource.com/c/go/+/656338
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Auto-Submit: Jorropo <jorropo.pgm@gmail.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>
src/cmd/compile/internal/ssa/_gen/generic.rules
src/cmd/compile/internal/ssa/rewritegeneric.go

index af9c24f53fd245024fd74093f00bc95c91c61534..5cc7c52f6e58b06fe1f91d08a79911e4692fd10c 100644 (file)
 (Sub(64|32|16|8) (Com(64|32|16|8) x) (Neg(64|32|16|8) x)) => (Const(64|32|16|8) [-1])
 (Add(64|32|16|8) (Com(64|32|16|8) x)                  x)  => (Const(64|32|16|8) [-1])
 
+// Prove does not simplify this because x + y might overflow into carry,
+// however if no one care about the carry, let it overflow in a normal add.
+(Select0 a:(Add64carry x y (Const64 [0]))) && a.Uses == 1 => (Add64 x y)
+
 // Simplification when involving common integer
 // (t + x) - (t + y) == x - y
 // (t + x) - (y + t) == x - y
index 79c444a86b29df1f2f926c00b05b240d705ea362..27c17e36e07a925e23b8e2fae9a833e2e98304a9 100644 (file)
@@ -30274,6 +30274,25 @@ func rewriteValuegeneric_OpRsh8x8(v *Value) bool {
 }
 func rewriteValuegeneric_OpSelect0(v *Value) bool {
        v_0 := v.Args[0]
+       // match: (Select0 a:(Add64carry x y (Const64 [0])))
+       // cond: a.Uses == 1
+       // result: (Add64 x y)
+       for {
+               a := v_0
+               if a.Op != OpAdd64carry {
+                       break
+               }
+               _ = a.Args[2]
+               x := a.Args[0]
+               y := a.Args[1]
+               a_2 := a.Args[2]
+               if a_2.Op != OpConst64 || auxIntToInt64(a_2.AuxInt) != 0 || !(a.Uses == 1) {
+                       break
+               }
+               v.reset(OpAdd64)
+               v.AddArg2(x, y)
+               return true
+       }
        // match: (Select0 (MakeTuple x y))
        // result: x
        for {