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>
This commit is contained in:
Lynn Boger 2023-09-27 12:15:04 -05:00
parent 144252d2e6
commit 80834af206
7 changed files with 120 additions and 249 deletions

View file

@ -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)
}