]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: optimize cmp to cmn under conditions < and >= on arm64
authorerifan01 <eric.fang@arm.com>
Tue, 14 Mar 2023 01:25:07 +0000 (09:25 +0800)
committerEric Fang <eric.fang@arm.com>
Fri, 24 Mar 2023 01:19:09 +0000 (01:19 +0000)
commit42f99b203d2990429ba9d13bd1b71d31057ce30a
tree0ba36c9e028f4bc94d818186374f81fed1a55310
parente81cc9119f7906ebded91f4cdc149866ac2acc0d
cmd/compile: optimize cmp to cmn under conditions < and >= on arm64

Under the right conditions we can optimize cmp comparisons to cmn
comparisons, such as:
func foo(a, b int) int {
  var c int
  if a + b < 0 {
   c = 1
  }
  return c
}

Previously it's compiled as:
  ADD     R1, R0, R1
  CMP     $0, R1
  CSET    LT, R0
With this CL it's compiled as:
  CMN     R1, R0
  CSET    MI, R0
Here we need to pay attention to the overflow situation of a+b, the MI
flag means N==1, which doesn't honor the overflow flag V, its value
depends only on the sign of the result. So it has the same semantic of
the Go code, so it's correct.

Similarly, this CL also optimizes the case of >= comparison
using the PL conditional flag.

Change-Id: I47179faba5b30cca84ea69bafa2ad5241bf6dfba
Reviewed-on: https://go-review.googlesource.com/c/go/+/476116
Run-TryBot: Eric Fang <eric.fang@arm.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
src/cmd/compile/internal/arm64/ssa.go
src/cmd/compile/internal/ssa/_gen/ARM64.rules
src/cmd/compile/internal/ssa/_gen/ARM64Ops.go
src/cmd/compile/internal/ssa/opGen.go
src/cmd/compile/internal/ssa/rewriteARM64.go
src/cmd/compile/internal/ssa/rewriteCond_test.go
test/codegen/comparisons.go