Skip to content

Commit

Permalink
cmd/compile: optimize BSRQ with nonzero input
Browse files Browse the repository at this point in the history
Same as BSFQ, if the input is known to be nonzero we don't need a CMOV
to correct for the weird all-zero behavior of the BSRQ instruction.

Fixes #51964

Change-Id: Ic1d14fdf3e7e698ff2f47efecfd761d8a036012a
Reviewed-on: https://go-review.googlesource.com/c/go/+/396034
Trust: Keith Randall <[email protected]>
Run-TryBot: Keith Randall <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: David Chase <[email protected]>
  • Loading branch information
randall77 committed Mar 27, 2022
1 parent 56400fc commit 7d3b64a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/ssa/gen/AMD64.rules
Original file line number Diff line number Diff line change
Expand Up @@ -2073,7 +2073,7 @@
(CMPXCHGLlock [off1+off2] {sym} ptr old new_ mem)

// We don't need the conditional move if we know the arg of BSF is not zero.
(CMOVQEQ x _ (Select1 (BSFQ (ORQconst [c] _)))) && c != 0 => x
(CMOVQEQ x _ (Select1 (BS(F|R)Q (ORQconst [c] _)))) && c != 0 => x
// Extension is unnecessary for trailing zeros.
(BSFQ (ORQconst <t> [1<<8] (MOVBQZX x))) => (BSFQ (ORQconst <t> [1<<8] x))
(BSFQ (ORQconst <t> [1<<16] (MOVWQZX x))) => (BSFQ (ORQconst <t> [1<<16] x))
Expand Down
23 changes: 23 additions & 0 deletions src/cmd/compile/internal/ssa/rewriteAMD64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7d3b64a

Please sign in to comment.