diff options
| author | Jorropo <jorropo.pgm@gmail.com> | 2025-07-03 02:57:25 +0200 |
|---|---|---|
| committer | Jorropo <jorropo.pgm@gmail.com> | 2025-07-24 14:42:15 -0700 |
| commit | ce05ad448fe6ea3b9b33c0eab1143dcb40e3bbc3 (patch) | |
| tree | 70236648e475e034764fd106f6717b913587cc8d /test/codegen | |
| parent | fcd28070fe4fe86b04c760dd7ce5fff2aa63bad5 (diff) | |
| download | go-ce05ad448fe6ea3b9b33c0eab1143dcb40e3bbc3.tar.xz | |
cmd/compile: rewrite condselects into doublings and halvings
For performance see CL 685676.
This allows something like:
if y { x *= 2 }
To be compiled to:
SHLXQ BX, AX, AX
Instead of:
MOVQ AX, CX
SHLQ $1, CX
MOVBLZX BL, DX
TESTQ DX, DX
CMOVQNE CX, AX
While ./make.bash uniqued per LOC, there is 2 doublings and 4 halvings.
Change-Id: Ic0727cbf429528a2dbf17cbfc3b0121db8387444
Reviewed-on: https://go-review.googlesource.com/c/go/+/685695
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'test/codegen')
| -rw-r--r-- | test/codegen/condmove.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/codegen/condmove.go b/test/codegen/condmove.go index 95a9d2cd23..5659972eed 100644 --- a/test/codegen/condmove.go +++ b/test/codegen/condmove.go @@ -473,3 +473,36 @@ func cmovmathsub(a uint, b bool) uint { // wasm:"Sub", "-Select" return a } + +func cmovmathdouble(a uint, b bool) uint { + if b { + a *= 2 + } + // amd64:"SHL", -"CMOV" + // amd64/v3:"SHL", -"CMOV", -"MOV" + // arm64:"LSL", -"CSEL" + // wasm:"Shl", "-Select" + return a +} + +func cmovmathhalvei(a int, b bool) int { + if b { + // For some reason on arm64 it attributes the ASR to inside this block rather than where the Phi node is. + // arm64:"ASR", -"CSEL" + a /= 2 + } + // arm64:-"CSEL" + // wasm:"Shr", "-Select" + return a +} + +func cmovmathhalveu(a uint, b bool) uint { + if b { + a /= 2 + } + // amd64:"SHR", -"CMOV" + // amd64/v3:"SHR", -"CMOV", -"MOV" + // arm64:"LSR", -"CSEL" + // wasm:"Shr", "-Select" + return a +} |
