aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCherry Mui <cherryyz@google.com>2022-05-09 14:56:14 -0400
committerThan McIntosh <thanm@google.com>2022-08-08 16:24:45 +0000
commit276a7bfff88be7bb52db2f4e207a9a89f3de72cb (patch)
tree158b6687a4b1d6afe801777416a886a54f0cc682
parente1099eb289a3da3bfb9f69527e9931d75ff9799b (diff)
downloadgo-276a7bfff88be7bb52db2f4e207a9a89f3de72cb.tar.gz
go-276a7bfff88be7bb52db2f4e207a9a89f3de72cb.zip
[release-branch.go1.18] cmd/compile: fix boolean comparison on PPC64
Following CL 421457, for PPC64. Should fix PPC64 builds. Updates #52788. Updates #53397. 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> Reviewed-on: https://go-review.googlesource.com/c/go/+/421459 Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
-rw-r--r--src/cmd/compile/internal/ssa/gen/PPC64.rules22
-rw-r--r--src/cmd/compile/internal/ssa/rewritePPC64.go108
-rw-r--r--src/cmd/objdump/objdump_test.go2
3 files changed, 88 insertions, 44 deletions
diff --git a/src/cmd/compile/internal/ssa/gen/PPC64.rules b/src/cmd/compile/internal/ssa/gen/PPC64.rules
index c3f07a4e22c..a90a3d0937d 100644
--- a/src/cmd/compile/internal/ssa/gen/PPC64.rules
+++ b/src/cmd/compile/internal/ssa/gen/PPC64.rules
@@ -445,19 +445,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)
diff --git a/src/cmd/compile/internal/ssa/rewritePPC64.go b/src/cmd/compile/internal/ssa/rewritePPC64.go
index 7592b4f5058..5a28b9d4f76 100644
--- a/src/cmd/compile/internal/ssa/rewritePPC64.go
+++ b/src/cmd/compile/internal/ssa/rewritePPC64.go
@@ -17194,6 +17194,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)
@@ -17767,12 +17768,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
}
@@ -18078,7 +18082,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]
@@ -18086,14 +18090,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
+ }
+ v_0_0_0 := v_0_0.Args[0]
+ if v_0_0_0.Op != OpPPC64Equal {
break
}
- cc := v_0_0.Args[0]
+ 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]
@@ -18101,14 +18109,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
+ }
+ v_0_0_0 := v_0_0.Args[0]
+ if v_0_0_0.Op != OpPPC64NotEqual {
break
}
- cc := v_0_0.Args[0]
+ 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]
@@ -18116,14 +18128,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]
@@ -18131,14 +18147,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]
@@ -18146,14 +18166,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
+ }
+ v_0_0_0 := v_0_0.Args[0]
+ if v_0_0_0.Op != OpPPC64GreaterThan {
break
}
- cc := v_0_0.Args[0]
+ 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]
@@ -18161,14 +18185,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
+ }
+ v_0_0_0 := v_0_0.Args[0]
+ if v_0_0_0.Op != OpPPC64GreaterEqual {
break
}
- cc := v_0_0.Args[0]
+ 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]
@@ -18176,14 +18204,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]
@@ -18191,14 +18223,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]
@@ -18206,14 +18242,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
+ }
+ v_0_0_0 := v_0_0.Args[0]
+ if v_0_0_0.Op != OpPPC64FGreaterThan {
break
}
- cc := v_0_0.Args[0]
+ 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]
@@ -18221,10 +18261,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
+ }
+ v_0_0_0 := v_0_0.Args[0]
+ if v_0_0_0.Op != OpPPC64FGreaterEqual {
break
}
- cc := v_0_0.Args[0]
+ cc := v_0_0_0.Args[0]
b.resetWithControl(BlockPPC64FGE, cc)
return true
}
diff --git a/src/cmd/objdump/objdump_test.go b/src/cmd/objdump/objdump_test.go
index ff431610308..f5743970be4 100644
--- a/src/cmd/objdump/objdump_test.go
+++ b/src/cmd/objdump/objdump_test.go
@@ -102,7 +102,7 @@ var ppcNeed = []string{
var ppcGnuNeed = []string{
"mflr",
"lbz",
- "cmpw",
+ "beq",
}
func mustHaveDisasm(t *testing.T) {