aboutsummaryrefslogtreecommitdiff
path: root/test/codegen
diff options
context:
space:
mode:
authorJorropo <jorropo.pgm@gmail.com>2026-03-29 06:24:53 +0200
committerGopher Robot <gobot@golang.org>2026-04-06 10:04:56 -0700
commit68ee544e8704b657e0adab5d3c2af38212f3d6c4 (patch)
treeffe1087696d06263b34feb5cbb2f5ef5ec2cdccb /test/codegen
parent9956aca06ab9d3083fa0afaebb640a1a25dde77f (diff)
downloadgo-68ee544e8704b657e0adab5d3c2af38212f3d6c4.tar.xz
cmd/compile: extend condselect into math code to handle other constants than 1
On amd64 along: if b { x += 1 } => x += b We can also implement constants 2 4 and 8: if b { x += 2 } => x += b * 2 This compiles to a displacement LEA. Change-Id: Ib00fcc5059acb0ebb346e056c4a656f164cc63df Reviewed-on: https://go-review.googlesource.com/c/go/+/760841 Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org> Auto-Submit: Jorropo <jorropo.pgm@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com>
Diffstat (limited to 'test/codegen')
-rw-r--r--test/codegen/condmove.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/test/codegen/condmove.go b/test/codegen/condmove.go
index ec1b971ed7..2b28077758 100644
--- a/test/codegen/condmove.go
+++ b/test/codegen/condmove.go
@@ -475,6 +475,51 @@ func cmovmathaddelse(a uint, b bool) uint {
return a
}
+func cmovmathadd2(a uint, b bool) uint {
+ if b {
+ a += 2
+ }
+ // amd64:"LEAQ" -"CMOV" -"MUL"
+ return a
+}
+func cmovmathadd2else(a uint, b bool) uint {
+ if !b {
+ a += 2
+ }
+ // amd64:"LEAQ" -"CMOV" -"MUL"
+ return a
+}
+
+func cmovmathadd4(a uint, b bool) uint {
+ if b {
+ a += 4
+ }
+ // amd64:"LEAQ" -"CMOV" -"MUL"
+ return a
+}
+func cmovmathadd4else(a uint, b bool) uint {
+ if !b {
+ a += 4
+ }
+ // amd64:"LEAQ" -"CMOV" -"MUL"
+ return a
+}
+
+func cmovmathadd8(a uint, b bool) uint {
+ if b {
+ a += 8
+ }
+ // amd64:"LEAQ" -"CMOV" -"MUL"
+ return a
+}
+func cmovmathadd8else(a uint, b bool) uint {
+ if !b {
+ a += 8
+ }
+ // amd64:"LEAQ" -"CMOV" -"MUL"
+ return a
+}
+
func cmovmathsub(a uint, b bool) uint {
if b {
a--