cmd/compile: fix boolean comparison on PPC64

Following CL 405114, for PPC64.

Should fix PPC64 builds.

Updates #52788.

Change-Id: I193ac31cfba18b4f907dd2523b51368251fd6fad
Reviewed-on: https://go-review.googlesource.com/c/go/+/405116
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Cherry Mui <cherryyz@google.com>
Reviewed-by: David Chase <drchase@google.com>
This commit is contained in:
Cherry Mui 2022-05-09 14:56:14 -04:00 committed by David Chase
parent 482669db62
commit 7a574ff23f
3 changed files with 88 additions and 44 deletions

View File

@ -446,19 +446,19 @@
(If (FGreaterThan cc) yes no) => (FGT cc yes no)
(If (FGreaterEqual cc) yes no) => (FGE cc yes no)
(If cond yes no) => (NE (CMPWconst [0] cond) yes no)
(If cond yes no) => (NE (CMPWconst [0] (ANDconst <typ.UInt32> [1] cond)) yes no)
// Absorb boolean tests into block
(NE (CMPWconst [0] (Equal cc)) yes no) => (EQ cc yes no)
(NE (CMPWconst [0] (NotEqual cc)) yes no) => (NE cc yes no)
(NE (CMPWconst [0] (LessThan cc)) yes no) => (LT cc yes no)
(NE (CMPWconst [0] (LessEqual cc)) yes no) => (LE cc yes no)
(NE (CMPWconst [0] (GreaterThan cc)) yes no) => (GT cc yes no)
(NE (CMPWconst [0] (GreaterEqual cc)) yes no) => (GE cc yes no)
(NE (CMPWconst [0] (FLessThan cc)) yes no) => (FLT cc yes no)
(NE (CMPWconst [0] (FLessEqual cc)) yes no) => (FLE cc yes no)
(NE (CMPWconst [0] (FGreaterThan cc)) yes no) => (FGT cc yes no)
(NE (CMPWconst [0] (FGreaterEqual cc)) yes no) => (FGE cc yes no)
(NE (CMPWconst [0] (ANDconst [1] (Equal cc))) yes no) => (EQ cc yes no)
(NE (CMPWconst [0] (ANDconst [1] (NotEqual cc))) yes no) => (NE cc yes no)
(NE (CMPWconst [0] (ANDconst [1] (LessThan cc))) yes no) => (LT cc yes no)
(NE (CMPWconst [0] (ANDconst [1] (LessEqual cc))) yes no) => (LE cc yes no)
(NE (CMPWconst [0] (ANDconst [1] (GreaterThan cc))) yes no) => (GT cc yes no)
(NE (CMPWconst [0] (ANDconst [1] (GreaterEqual cc))) yes no) => (GE cc yes no)
(NE (CMPWconst [0] (ANDconst [1] (FLessThan cc))) yes no) => (FLT cc yes no)
(NE (CMPWconst [0] (ANDconst [1] (FLessEqual cc))) yes no) => (FLE cc yes no)
(NE (CMPWconst [0] (ANDconst [1] (FGreaterThan cc))) yes no) => (FGT cc yes no)
(NE (CMPWconst [0] (ANDconst [1] (FGreaterEqual cc))) yes no) => (FGE cc yes no)
// Elide compares of bit tests // TODO need to make both CC and result of ANDCC available.
(EQ (CMPconst [0] (ANDconst [c] x)) yes no) => (EQ (ANDCCconst [c] x) yes no)

View File

@ -17215,6 +17215,7 @@ func rewriteValuePPC64_OpZero(v *Value) bool {
return false
}
func rewriteBlockPPC64(b *Block) bool {
typ := &b.Func.Config.Types
switch b.Kind {
case BlockPPC64EQ:
// match: (EQ (CMPconst [0] (ANDconst [c] x)) yes no)
@ -17788,12 +17789,15 @@ func rewriteBlockPPC64(b *Block) bool {
return true
}
// match: (If cond yes no)
// result: (NE (CMPWconst [0] cond) yes no)
// result: (NE (CMPWconst [0] (ANDconst <typ.UInt32> [1] cond)) yes no)
for {
cond := b.Controls[0]
v0 := b.NewValue0(cond.Pos, OpPPC64CMPWconst, types.TypeFlags)
v0.AuxInt = int32ToAuxInt(0)
v0.AddArg(cond)
v1 := b.NewValue0(cond.Pos, OpPPC64ANDconst, typ.UInt32)
v1.AuxInt = int64ToAuxInt(1)
v1.AddArg(cond)
v0.AddArg(v1)
b.resetWithControl(BlockPPC64NE, v0)
return true
}
@ -18099,7 +18103,7 @@ func rewriteBlockPPC64(b *Block) bool {
break
}
case BlockPPC64NE:
// match: (NE (CMPWconst [0] (Equal cc)) yes no)
// match: (NE (CMPWconst [0] (ANDconst [1] (Equal cc))) yes no)
// result: (EQ cc yes no)
for b.Controls[0].Op == OpPPC64CMPWconst {
v_0 := b.Controls[0]
@ -18107,14 +18111,18 @@ func rewriteBlockPPC64(b *Block) bool {
break
}
v_0_0 := v_0.Args[0]
if v_0_0.Op != OpPPC64Equal {
if v_0_0.Op != OpPPC64ANDconst || auxIntToInt64(v_0_0.AuxInt) != 1 {
break
}
cc := v_0_0.Args[0]
v_0_0_0 := v_0_0.Args[0]
if v_0_0_0.Op != OpPPC64Equal {
break
}
cc := v_0_0_0.Args[0]
b.resetWithControl(BlockPPC64EQ, cc)
return true
}
// match: (NE (CMPWconst [0] (NotEqual cc)) yes no)
// match: (NE (CMPWconst [0] (ANDconst [1] (NotEqual cc))) yes no)
// result: (NE cc yes no)
for b.Controls[0].Op == OpPPC64CMPWconst {
v_0 := b.Controls[0]
@ -18122,14 +18130,18 @@ func rewriteBlockPPC64(b *Block) bool {
break
}
v_0_0 := v_0.Args[0]
if v_0_0.Op != OpPPC64NotEqual {
if v_0_0.Op != OpPPC64ANDconst || auxIntToInt64(v_0_0.AuxInt) != 1 {
break
}
cc := v_0_0.Args[0]
v_0_0_0 := v_0_0.Args[0]
if v_0_0_0.Op != OpPPC64NotEqual {
break
}
cc := v_0_0_0.Args[0]
b.resetWithControl(BlockPPC64NE, cc)
return true
}
// match: (NE (CMPWconst [0] (LessThan cc)) yes no)
// match: (NE (CMPWconst [0] (ANDconst [1] (LessThan cc))) yes no)
// result: (LT cc yes no)
for b.Controls[0].Op == OpPPC64CMPWconst {
v_0 := b.Controls[0]
@ -18137,14 +18149,18 @@ func rewriteBlockPPC64(b *Block) bool {
break
}
v_0_0 := v_0.Args[0]
if v_0_0.Op != OpPPC64LessThan {
if v_0_0.Op != OpPPC64ANDconst || auxIntToInt64(v_0_0.AuxInt) != 1 {
break
}
cc := v_0_0.Args[0]
v_0_0_0 := v_0_0.Args[0]
if v_0_0_0.Op != OpPPC64LessThan {
break
}
cc := v_0_0_0.Args[0]
b.resetWithControl(BlockPPC64LT, cc)
return true
}
// match: (NE (CMPWconst [0] (LessEqual cc)) yes no)
// match: (NE (CMPWconst [0] (ANDconst [1] (LessEqual cc))) yes no)
// result: (LE cc yes no)
for b.Controls[0].Op == OpPPC64CMPWconst {
v_0 := b.Controls[0]
@ -18152,14 +18168,18 @@ func rewriteBlockPPC64(b *Block) bool {
break
}
v_0_0 := v_0.Args[0]
if v_0_0.Op != OpPPC64LessEqual {
if v_0_0.Op != OpPPC64ANDconst || auxIntToInt64(v_0_0.AuxInt) != 1 {
break
}
cc := v_0_0.Args[0]
v_0_0_0 := v_0_0.Args[0]
if v_0_0_0.Op != OpPPC64LessEqual {
break
}
cc := v_0_0_0.Args[0]
b.resetWithControl(BlockPPC64LE, cc)
return true
}
// match: (NE (CMPWconst [0] (GreaterThan cc)) yes no)
// match: (NE (CMPWconst [0] (ANDconst [1] (GreaterThan cc))) yes no)
// result: (GT cc yes no)
for b.Controls[0].Op == OpPPC64CMPWconst {
v_0 := b.Controls[0]
@ -18167,14 +18187,18 @@ func rewriteBlockPPC64(b *Block) bool {
break
}
v_0_0 := v_0.Args[0]
if v_0_0.Op != OpPPC64GreaterThan {
if v_0_0.Op != OpPPC64ANDconst || auxIntToInt64(v_0_0.AuxInt) != 1 {
break
}
cc := v_0_0.Args[0]
v_0_0_0 := v_0_0.Args[0]
if v_0_0_0.Op != OpPPC64GreaterThan {
break
}
cc := v_0_0_0.Args[0]
b.resetWithControl(BlockPPC64GT, cc)
return true
}
// match: (NE (CMPWconst [0] (GreaterEqual cc)) yes no)
// match: (NE (CMPWconst [0] (ANDconst [1] (GreaterEqual cc))) yes no)
// result: (GE cc yes no)
for b.Controls[0].Op == OpPPC64CMPWconst {
v_0 := b.Controls[0]
@ -18182,14 +18206,18 @@ func rewriteBlockPPC64(b *Block) bool {
break
}
v_0_0 := v_0.Args[0]
if v_0_0.Op != OpPPC64GreaterEqual {
if v_0_0.Op != OpPPC64ANDconst || auxIntToInt64(v_0_0.AuxInt) != 1 {
break
}
cc := v_0_0.Args[0]
v_0_0_0 := v_0_0.Args[0]
if v_0_0_0.Op != OpPPC64GreaterEqual {
break
}
cc := v_0_0_0.Args[0]
b.resetWithControl(BlockPPC64GE, cc)
return true
}
// match: (NE (CMPWconst [0] (FLessThan cc)) yes no)
// match: (NE (CMPWconst [0] (ANDconst [1] (FLessThan cc))) yes no)
// result: (FLT cc yes no)
for b.Controls[0].Op == OpPPC64CMPWconst {
v_0 := b.Controls[0]
@ -18197,14 +18225,18 @@ func rewriteBlockPPC64(b *Block) bool {
break
}
v_0_0 := v_0.Args[0]
if v_0_0.Op != OpPPC64FLessThan {
if v_0_0.Op != OpPPC64ANDconst || auxIntToInt64(v_0_0.AuxInt) != 1 {
break
}
cc := v_0_0.Args[0]
v_0_0_0 := v_0_0.Args[0]
if v_0_0_0.Op != OpPPC64FLessThan {
break
}
cc := v_0_0_0.Args[0]
b.resetWithControl(BlockPPC64FLT, cc)
return true
}
// match: (NE (CMPWconst [0] (FLessEqual cc)) yes no)
// match: (NE (CMPWconst [0] (ANDconst [1] (FLessEqual cc))) yes no)
// result: (FLE cc yes no)
for b.Controls[0].Op == OpPPC64CMPWconst {
v_0 := b.Controls[0]
@ -18212,14 +18244,18 @@ func rewriteBlockPPC64(b *Block) bool {
break
}
v_0_0 := v_0.Args[0]
if v_0_0.Op != OpPPC64FLessEqual {
if v_0_0.Op != OpPPC64ANDconst || auxIntToInt64(v_0_0.AuxInt) != 1 {
break
}
cc := v_0_0.Args[0]
v_0_0_0 := v_0_0.Args[0]
if v_0_0_0.Op != OpPPC64FLessEqual {
break
}
cc := v_0_0_0.Args[0]
b.resetWithControl(BlockPPC64FLE, cc)
return true
}
// match: (NE (CMPWconst [0] (FGreaterThan cc)) yes no)
// match: (NE (CMPWconst [0] (ANDconst [1] (FGreaterThan cc))) yes no)
// result: (FGT cc yes no)
for b.Controls[0].Op == OpPPC64CMPWconst {
v_0 := b.Controls[0]
@ -18227,14 +18263,18 @@ func rewriteBlockPPC64(b *Block) bool {
break
}
v_0_0 := v_0.Args[0]
if v_0_0.Op != OpPPC64FGreaterThan {
if v_0_0.Op != OpPPC64ANDconst || auxIntToInt64(v_0_0.AuxInt) != 1 {
break
}
cc := v_0_0.Args[0]
v_0_0_0 := v_0_0.Args[0]
if v_0_0_0.Op != OpPPC64FGreaterThan {
break
}
cc := v_0_0_0.Args[0]
b.resetWithControl(BlockPPC64FGT, cc)
return true
}
// match: (NE (CMPWconst [0] (FGreaterEqual cc)) yes no)
// match: (NE (CMPWconst [0] (ANDconst [1] (FGreaterEqual cc))) yes no)
// result: (FGE cc yes no)
for b.Controls[0].Op == OpPPC64CMPWconst {
v_0 := b.Controls[0]
@ -18242,10 +18282,14 @@ func rewriteBlockPPC64(b *Block) bool {
break
}
v_0_0 := v_0.Args[0]
if v_0_0.Op != OpPPC64FGreaterEqual {
if v_0_0.Op != OpPPC64ANDconst || auxIntToInt64(v_0_0.AuxInt) != 1 {
break
}
cc := v_0_0.Args[0]
v_0_0_0 := v_0_0.Args[0]
if v_0_0_0.Op != OpPPC64FGreaterEqual {
break
}
cc := v_0_0_0.Args[0]
b.resetWithControl(BlockPPC64FGE, cc)
return true
}

View File

@ -102,7 +102,7 @@ var ppcNeed = []string{
var ppcGnuNeed = []string{
"mflr",
"lbz",
"cmpw",
"beq",
}
func mustHaveDisasm(t *testing.T) {