aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile
diff options
context:
space:
mode:
authorJorropo <jorropo.pgm@gmail.com>2025-07-26 03:36:15 +0200
committerGopher Robot <gobot@golang.org>2025-07-28 11:06:07 -0700
commit94645d241320fe0617a4f158a4e1b64a643bb10f (patch)
tree32e92cd7df7f8205f0308ee19dcbb2ec787b50e0 /src/cmd/compile
parent10c5cf68d40e2b26336e4b4e59d4c2f3fc3f03b9 (diff)
downloadgo-94645d241320fe0617a4f158a4e1b64a643bb10f.tar.xz
cmd/compile: rewrite cmov(x, x, cond) into x
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>
Diffstat (limited to 'src/cmd/compile')
-rw-r--r--src/cmd/compile/internal/ssa/_gen/generic.rules1
-rw-r--r--src/cmd/compile/internal/ssa/rewritegeneric.go10
2 files changed, 11 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/ssa/_gen/generic.rules b/src/cmd/compile/internal/ssa/_gen/generic.rules
index b98dfae2d5..72d9677c5f 100644
--- a/src/cmd/compile/internal/ssa/_gen/generic.rules
+++ b/src/cmd/compile/internal/ssa/_gen/generic.rules
@@ -297,6 +297,7 @@
(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]))
diff --git a/src/cmd/compile/internal/ssa/rewritegeneric.go b/src/cmd/compile/internal/ssa/rewritegeneric.go
index 0b9f9c09f9..bdde103a1f 100644
--- a/src/cmd/compile/internal/ssa/rewritegeneric.go
+++ b/src/cmd/compile/internal/ssa/rewritegeneric.go
@@ -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))