]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: optimize unsigned comparisons to 0/1 on arm64
authorJunchen Li <junchen.li@arm.com>
Fri, 10 Jul 2020 03:39:23 +0000 (11:39 +0800)
committerKeith Randall <khr@golang.org>
Tue, 18 Aug 2020 04:09:13 +0000 (04:09 +0000)
commit06337823ef4d9c57b1b01f9b97a348a47277a9df
tree1b12a842aa7e03ad816ba4083ef711f33886badf
parent7fbd8c75c6c57e713069a3a405e5cde26cfae090
cmd/compile: optimize unsigned comparisons to 0/1 on arm64

For an unsigned integer, it's useful to convert its order test with 0/1
to its equality test with 0. We can save a comparison instruction that
followed by a conditional branch on arm64 since it supports
compare-with-zero-and-branch instructions. For example,

  if x > 0 { ... } else { ... }

the original version:
  CMP $0, R0
  BLS 9

the optimized version:
  CBZ R0, 8

Updates #21439

Change-Id: Id1de6f865f6aa72c5d45b29f7894818857288425
Reviewed-on: https://go-review.googlesource.com/c/go/+/246857
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/ssa/gen/ARM64.rules
src/cmd/compile/internal/ssa/rewriteARM64.go
test/codegen/comparisons.go