From: Jorropo Date: Mon, 10 Mar 2025 08:27:39 +0000 (+0100) Subject: cmd/compile: optimize Add64carry with unused carries into plain Add64 X-Git-Tag: go1.26rc1~456 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=5453b788fd;p=gostls13.git cmd/compile: optimize Add64carry with unused carries into plain Add64 Change-Id: I8a63f567cfc574bb066ad6269eec6929760cb9c3 Reviewed-on: https://go-review.googlesource.com/c/go/+/656338 Reviewed-by: Michael Knyszek Auto-Submit: Jorropo LUCI-TryBot-Result: Go LUCI Reviewed-by: Keith Randall Reviewed-by: Keith Randall --- diff --git a/src/cmd/compile/internal/ssa/_gen/generic.rules b/src/cmd/compile/internal/ssa/_gen/generic.rules index af9c24f53f..5cc7c52f6e 100644 --- a/src/cmd/compile/internal/ssa/_gen/generic.rules +++ b/src/cmd/compile/internal/ssa/_gen/generic.rules @@ -629,6 +629,10 @@ (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 diff --git a/src/cmd/compile/internal/ssa/rewritegeneric.go b/src/cmd/compile/internal/ssa/rewritegeneric.go index 79c444a86b..27c17e36e0 100644 --- a/src/cmd/compile/internal/ssa/rewritegeneric.go +++ b/src/cmd/compile/internal/ssa/rewritegeneric.go @@ -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 {