]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: rewrite cmov(x, x, cond) into x
authorJorropo <jorropo.pgm@gmail.com>
Sat, 26 Jul 2025 01:36:15 +0000 (03:36 +0200)
committerGopher Robot <gobot@golang.org>
Mon, 28 Jul 2025 18:06:07 +0000 (11:06 -0700)
I don't think branchelim will intentionally generate theses.
But at the time where branchelim is generating them they might different,
and through opt process they become the same value.

Change-Id: I4a19f1db14c08057b7e782a098f4c18ca36ab7fe
Reviewed-on: https://go-review.googlesource.com/c/go/+/690519
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Mark Freeman <mark@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/ssa/_gen/generic.rules
src/cmd/compile/internal/ssa/rewritegeneric.go

index b98dfae2d588163fee047bf4d052faaa1a222896..72d9677c5f226ee60b91f46d74b2acfb4eb3a08c 100644 (file)
 
 (CondSelect x _ (ConstBool [true ])) => x
 (CondSelect _ y (ConstBool [false])) => y
+(CondSelect x x _) => x
 
 // signed integer range: ( c <= x && x (<|<=) d ) -> ( unsigned(x-c) (<|<=) unsigned(d-c) )
 (AndB (Leq64 (Const64 [c]) x) ((Less|Leq)64 x (Const64 [d]))) && d >= c => ((Less|Leq)64U (Sub64 <x.Type> x (Const64 <x.Type> [c])) (Const64 <x.Type> [d-c]))
index 0b9f9c09f9e002c735fe544d23d4447eff37474a..bdde103a1f3e061e44bcf14889645c8d298e89b4 100644 (file)
@@ -5722,6 +5722,16 @@ func rewriteValuegeneric_OpCondSelect(v *Value) bool {
                v.copyOf(y)
                return true
        }
+       // match: (CondSelect x x _)
+       // result: x
+       for {
+               x := v_0
+               if x != v_1 {
+                       break
+               }
+               v.copyOf(x)
+               return true
+       }
        // match: (CondSelect (Add8 <t> x (Const8 [1])) x bool)
        // cond: config.arch != "arm64"
        // result: (Add8 x (CvtBoolToUint8 <t> bool))