]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: cleanup SelectN rules by indexing into args
authorJorropo <jorropo.pgm@gmail.com>
Sat, 26 Jul 2025 02:04:05 +0000 (04:04 +0200)
committerGopher Robot <gobot@golang.org>
Mon, 28 Jul 2025 18:06:11 +0000 (11:06 -0700)
Change-Id: I7b8e8cd88c4d6d562aa25df91593d35d331ef63c
Reviewed-on: https://go-review.googlesource.com/c/go/+/690595
Reviewed-by: Mark Freeman <mark@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/cmd/compile/internal/ssa/_gen/generic.rules
src/cmd/compile/internal/ssa/rewritegeneric.go

index 72d9677c5f226ee60b91f46d74b2acfb4eb3a08c..40966063d7dcd8052533d1cc3491c8d09ee88488 100644 (file)
 (Select1 (MakeTuple x y)) => y
 
 // for rewriting results of some late-expanded rewrites (below)
-(SelectN [0] (MakeResult x ___)) => x
-(SelectN [1] (MakeResult x y ___)) => y
-(SelectN [2] (MakeResult x y z ___)) => z
+(SelectN [n] m:(MakeResult ___)) => m.Args[n]
 
 // for late-expanded calls, recognize newobject and remove zeroing and nilchecks
 (Zero (SelectN [0] call:(StaticLECall _ _)) mem:(SelectN [1] call))
index bdde103a1f3e061e44bcf14889645c8d298e89b4..f36e0b270fd5976973a3aba58c4c532759dd8e40 100644 (file)
@@ -29886,34 +29886,15 @@ func rewriteValuegeneric_OpSelectN(v *Value) bool {
        b := v.Block
        config := b.Func.Config
        typ := &b.Func.Config.Types
-       // match: (SelectN [0] (MakeResult x ___))
-       // result: x
-       for {
-               if auxIntToInt64(v.AuxInt) != 0 || v_0.Op != OpMakeResult || len(v_0.Args) < 1 {
-                       break
-               }
-               x := v_0.Args[0]
-               v.copyOf(x)
-               return true
-       }
-       // match: (SelectN [1] (MakeResult x y ___))
-       // result: y
+       // match: (SelectN [n] m:(MakeResult ___))
+       // result: m.Args[n]
        for {
-               if auxIntToInt64(v.AuxInt) != 1 || v_0.Op != OpMakeResult || len(v_0.Args) < 2 {
-                       break
-               }
-               y := v_0.Args[1]
-               v.copyOf(y)
-               return true
-       }
-       // match: (SelectN [2] (MakeResult x y z ___))
-       // result: z
-       for {
-               if auxIntToInt64(v.AuxInt) != 2 || v_0.Op != OpMakeResult || len(v_0.Args) < 3 {
+               n := auxIntToInt64(v.AuxInt)
+               m := v_0
+               if m.Op != OpMakeResult {
                        break
                }
-               z := v_0.Args[2]
-               v.copyOf(z)
+               v.copyOf(m.Args[n])
                return true
        }
        // match: (SelectN [0] call:(StaticCall {sym} sptr (Const64 [c]) mem))