diff options
author | Lynn Boger <laboger@linux.vnet.ibm.com> | 2023-09-27 12:15:04 -0500 |
---|---|---|
committer | Lynn Boger <laboger@linux.vnet.ibm.com> | 2023-10-18 15:56:53 +0000 |
commit | 80834af2063962bad87a56f0f45546cc18f30a9c (patch) | |
tree | 75067a8427e75b5d88b445dc7db38fa986f9219c /test | |
parent | 144252d2e64c9f375760f98d6a04d20601b6d3a0 (diff) | |
download | go-80834af2063962bad87a56f0f45546cc18f30a9c.tar.gz go-80834af2063962bad87a56f0f45546cc18f30a9c.zip |
cmd/compile: avoid ANDCCconst on PPC64 if condition not needed
In the PPC64 ISA, the instruction to do an 'and' operation
using an immediate constant is only available in the form that
also sets CR0 (i.e. clobbers the condition register.) This means
CR0 is being clobbered unnecessarily in many cases. That
affects some decisions made during some compiler passes
that check for it.
In those cases when the constant used by the ANDCC is a right
justified consecutive set of bits, a shift instruction can
be used which has the same effect if CR0 does not need to be
set. The rule to do that has been added to the late rules file
after other rules using ANDCCconst have been processed in the
main rules file.
Some codegen tests had to be updated since ANDCC is no
longer generated for some cases. A new test case was added to
verify the ANDCC is present if the results for both the AND
and CR0 are used.
Change-Id: I304f607c039a458e2d67d25351dd00aea72ba542
Reviewed-on: https://go-review.googlesource.com/c/go/+/531435
Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com>
Reviewed-by: Paul Murphy <murp@ibm.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
Reviewed-by: Jayanth Krishnamurthy <jayanth.krishnamurthy@ibm.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/codegen/arithmetic.go | 12 | ||||
-rw-r--r-- | test/codegen/bool.go | 24 | ||||
-rw-r--r-- | test/codegen/shift.go | 18 |
3 files changed, 31 insertions, 23 deletions
diff --git a/test/codegen/arithmetic.go b/test/codegen/arithmetic.go index f381b34ade..b91a904be9 100644 --- a/test/codegen/arithmetic.go +++ b/test/codegen/arithmetic.go @@ -260,7 +260,7 @@ func Pow2Mods(n1 uint, n2 int) (uint, int) { // amd64:"ANDL\t[$]31",-"DIVQ" // arm:"AND\t[$]31",-".*udiv" // arm64:"AND\t[$]31",-"UDIV" - // ppc64x:"ANDCC\t[$]31" + // ppc64x:"RLDICL" a := n1 % 32 // unsigned // 386:"SHRL",-"IDIVL" @@ -279,14 +279,14 @@ func Pow2DivisibleSigned(n1, n2 int) (bool, bool) { // amd64:"TESTQ\t[$]63",-"DIVQ",-"SHRQ" // arm:"AND\t[$]63",-".*udiv",-"SRA" // arm64:"TST\t[$]63",-"UDIV",-"ASR",-"AND" - // ppc64x:"ANDCC\t[$]63",-"SRAD" + // ppc64x:"RLDICL",-"SRAD" a := n1%64 == 0 // signed divisible // 386:"TESTL\t[$]63",-"DIVL",-"SHRL" // amd64:"TESTQ\t[$]63",-"DIVQ",-"SHRQ" // arm:"AND\t[$]63",-".*udiv",-"SRA" // arm64:"TST\t[$]63",-"UDIV",-"ASR",-"AND" - // ppc64x:"ANDCC\t[$]63",-"SRAD" + // ppc64x:"RLDICL",-"SRAD" b := n2%64 != 0 // signed indivisible return a, b @@ -464,7 +464,7 @@ func LenMod1(a []int) int { // arm64:"AND\t[$]1023",-"SDIV" // arm/6:"AND",-".*udiv" // arm/7:"BFC",-".*udiv",-"AND" - // ppc64x:"ANDCC\t[$]1023" + // ppc64x:"RLDICL" return len(a) % 1024 } @@ -474,7 +474,7 @@ func LenMod2(s string) int { // arm64:"AND\t[$]2047",-"SDIV" // arm/6:"AND",-".*udiv" // arm/7:"BFC",-".*udiv",-"AND" - // ppc64x:"ANDCC\t[$]2047" + // ppc64x:"RLDICL" return len(s) % (4097 >> 1) } @@ -493,7 +493,7 @@ func CapMod(a []int) int { // arm64:"AND\t[$]4095",-"SDIV" // arm/6:"AND",-".*udiv" // arm/7:"BFC",-".*udiv",-"AND" - // ppc64x:"ANDCC\t[$]4095" + // ppc64x:"RLDICL" return cap(a) % ((1 << 11) + 2048) } diff --git a/test/codegen/bool.go b/test/codegen/bool.go index faf7033a2a..109c3aa0cd 100644 --- a/test/codegen/bool.go +++ b/test/codegen/bool.go @@ -10,49 +10,49 @@ package codegen func convertNeq0B(x uint8, c bool) bool { // amd64:"ANDL\t[$]1",-"SETNE" - // ppc64x:"ANDCC",-"CMPW",-"ISEL" + // ppc64x:"RLDICL",-"CMPW",-"ISEL" b := x&1 != 0 return c && b } func convertNeq0W(x uint16, c bool) bool { // amd64:"ANDL\t[$]1",-"SETNE" - // ppc64x:"ANDCC",-"CMPW",-"ISEL" + // ppc64x:"RLDICL",-"CMPW",-"ISEL" b := x&1 != 0 return c && b } func convertNeq0L(x uint32, c bool) bool { // amd64:"ANDL\t[$]1",-"SETB" - // ppc64x:"ANDCC",-"CMPW",-"ISEL" + // ppc64x:"RLDICL",-"CMPW",-"ISEL" b := x&1 != 0 return c && b } func convertNeq0Q(x uint64, c bool) bool { // amd64:"ANDL\t[$]1",-"SETB" - // ppc64x:"ANDCC",-"CMP",-"ISEL" + // ppc64x:"RLDICL",-"CMP",-"ISEL" b := x&1 != 0 return c && b } func convertNeqBool32(x uint32) bool { - // ppc64x:"ANDCC",-"CMPW",-"ISEL" + // ppc64x:"RLDICL",-"CMPW",-"ISEL" return x&1 != 0 } func convertEqBool32(x uint32) bool { - // ppc64x:"ANDCC",-"CMPW","XOR",-"ISEL" + // ppc64x:"RLDICL",-"CMPW","XOR",-"ISEL" return x&1 == 0 } func convertNeqBool64(x uint64) bool { - // ppc64x:"ANDCC",-"CMP",-"ISEL" + // ppc64x:"RLDICL",-"CMP",-"ISEL" return x&1 != 0 } func convertEqBool64(x uint64) bool { - // ppc64x:"ANDCC","XOR",-"CMP",-"ISEL" + // ppc64x:"RLDICL","XOR",-"CMP",-"ISEL" return x&1 == 0 } @@ -211,3 +211,11 @@ func TestSetInvGeFp64(x float64, y float64) bool { b := !(x >= y) return b } +func TestAndCompareZero(x uint64, y uint64) uint64 { + // ppc64x:"ANDCC" + b := x&3 + if b!=0 { + return b + } + return b+8 +} diff --git a/test/codegen/shift.go b/test/codegen/shift.go index 302560d5b0..bf8b633905 100644 --- a/test/codegen/shift.go +++ b/test/codegen/shift.go @@ -70,7 +70,7 @@ func rshConst64x32(v int64) int64 { func lshMask64x64(v int64, s uint64) int64 { // arm64:"LSL",-"AND" - // ppc64x:"ANDCC",-"ORN",-"ISEL" + // ppc64x:"RLDICL",-"ORN",-"ISEL" // riscv64:"SLL",-"AND\t",-"SLTIU" // s390x:-"RISBGZ",-"AND",-"LOCGR" return v << (s & 63) @@ -78,7 +78,7 @@ func lshMask64x64(v int64, s uint64) int64 { func rshMask64Ux64(v uint64, s uint64) uint64 { // arm64:"LSR",-"AND",-"CSEL" - // ppc64x:"ANDCC",-"ORN",-"ISEL" + // ppc64x:"RLDICL",-"ORN",-"ISEL" // riscv64:"SRL\t",-"AND\t",-"SLTIU" // s390x:-"RISBGZ",-"AND",-"LOCGR" return v >> (s & 63) @@ -86,7 +86,7 @@ func rshMask64Ux64(v uint64, s uint64) uint64 { func rshMask64x64(v int64, s uint64) int64 { // arm64:"ASR",-"AND",-"CSEL" - // ppc64x:"ANDCC",-"ORN",-"ISEL" + // ppc64x:"RLDICL",-"ORN",-"ISEL" // riscv64:"SRA",-"OR",-"SLTIU" // s390x:-"RISBGZ",-"AND",-"LOCGR" return v >> (s & 63) @@ -123,7 +123,7 @@ func rshMask32x64(v int32, s uint64) int32 { func lshMask64x32(v int64, s uint32) int64 { // arm64:"LSL",-"AND" - // ppc64x:"ANDCC",-"ORN" + // ppc64x:"RLDICL",-"ORN" // riscv64:"SLL",-"AND\t",-"SLTIU" // s390x:-"RISBGZ",-"AND",-"LOCGR" return v << (s & 63) @@ -131,7 +131,7 @@ func lshMask64x32(v int64, s uint32) int64 { func rshMask64Ux32(v uint64, s uint32) uint64 { // arm64:"LSR",-"AND",-"CSEL" - // ppc64x:"ANDCC",-"ORN" + // ppc64x:"RLDICL",-"ORN" // riscv64:"SRL\t",-"AND\t",-"SLTIU" // s390x:-"RISBGZ",-"AND",-"LOCGR" return v >> (s & 63) @@ -139,28 +139,28 @@ func rshMask64Ux32(v uint64, s uint32) uint64 { func rshMask64x32(v int64, s uint32) int64 { // arm64:"ASR",-"AND",-"CSEL" - // ppc64x:"ANDCC",-"ORN",-"ISEL" + // ppc64x:"RLDICL",-"ORN",-"ISEL" // riscv64:"SRA",-"OR",-"SLTIU" // s390x:-"RISBGZ",-"AND",-"LOCGR" return v >> (s & 63) } func lshMask64x32Ext(v int64, s int32) int64 { - // ppc64x:"ANDCC",-"ORN",-"ISEL" + // ppc64x:"RLDICL",-"ORN",-"ISEL" // riscv64:"SLL",-"AND\t",-"SLTIU" // s390x:-"RISBGZ",-"AND",-"LOCGR" return v << uint(s&63) } func rshMask64Ux32Ext(v uint64, s int32) uint64 { - // ppc64x:"ANDCC",-"ORN",-"ISEL" + // ppc64x:"RLDICL",-"ORN",-"ISEL" // riscv64:"SRL\t",-"AND\t",-"SLTIU" // s390x:-"RISBGZ",-"AND",-"LOCGR" return v >> uint(s&63) } func rshMask64x32Ext(v int64, s int32) int64 { - // ppc64x:"ANDCC",-"ORN",-"ISEL" + // ppc64x:"RLDICL",-"ORN",-"ISEL" // riscv64:"SRA",-"OR",-"SLTIU" // s390x:-"RISBGZ",-"AND",-"LOCGR" return v >> uint(s&63) |