aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCherry Mui <cherryyz@google.com>2022-05-10 10:49:33 -0400
committerThan McIntosh <thanm@google.com>2022-08-08 16:24:50 +0000
commit21befdc0c4d2cb784907b09d1d8b35eb3521437f (patch)
treed0b272d14225bdcb6ea81d88b87fb73bc9507ce5
parent276a7bfff88be7bb52db2f4e207a9a89f3de72cb (diff)
downloadgo-21befdc0c4d2cb784907b09d1d8b35eb3521437f.tar.gz
go-21befdc0c4d2cb784907b09d1d8b35eb3521437f.zip
[release-branch.go1.18] cmd/compile: fix boolean comparison on RISCV64
Following CL 421457, for RISCV64. May fix RISCV64 builds. Updates #52788. Updates #53397. Change-Id: Ifc34658703d1e8b97665e7b862060152e3005d71 Reviewed-on: https://go-review.googlesource.com/c/go/+/405553 Reviewed-by: David Chase <drchase@google.com> Run-TryBot: Cherry Mui <cherryyz@google.com> Reviewed-on: https://go-review.googlesource.com/c/go/+/421460 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
-rw-r--r--src/cmd/compile/internal/ssa/gen/RISCV64.rules6
-rw-r--r--src/cmd/compile/internal/ssa/rewriteRISCV64.go47
2 files changed, 50 insertions, 3 deletions
diff --git a/src/cmd/compile/internal/ssa/gen/RISCV64.rules b/src/cmd/compile/internal/ssa/gen/RISCV64.rules
index 96b24a63808..7aea622c5e8 100644
--- a/src/cmd/compile/internal/ssa/gen/RISCV64.rules
+++ b/src/cmd/compile/internal/ssa/gen/RISCV64.rules
@@ -583,7 +583,7 @@
(AtomicOr32 ...) => (LoweredAtomicOr32 ...)
// Conditional branches
-(If cond yes no) => (BNEZ cond yes no)
+(If cond yes no) => (BNEZ (MOVBUreg <typ.UInt64> cond) yes no)
// Optimizations
@@ -621,6 +621,10 @@
(MOVWstore [off] {sym} ptr (MOVDconst [0]) mem) => (MOVWstorezero [off] {sym} ptr mem)
(MOVDstore [off] {sym} ptr (MOVDconst [0]) mem) => (MOVDstorezero [off] {sym} ptr mem)
+// Boolean ops are already extended.
+(MOVBUreg x:((SEQZ|SNEZ) _)) => x
+(MOVBUreg x:((SLT|SLTU) _ _)) => x
+
// Avoid sign/zero extension for consts.
(MOVBreg (MOVDconst [c])) => (MOVDconst [int64(int8(c))])
(MOVHreg (MOVDconst [c])) => (MOVDconst [int64(int16(c))])
diff --git a/src/cmd/compile/internal/ssa/rewriteRISCV64.go b/src/cmd/compile/internal/ssa/rewriteRISCV64.go
index a67d13e0da9..6828d97ff8f 100644
--- a/src/cmd/compile/internal/ssa/rewriteRISCV64.go
+++ b/src/cmd/compile/internal/ssa/rewriteRISCV64.go
@@ -3152,6 +3152,46 @@ func rewriteValueRISCV64_OpRISCV64MOVBUload(v *Value) bool {
func rewriteValueRISCV64_OpRISCV64MOVBUreg(v *Value) bool {
v_0 := v.Args[0]
b := v.Block
+ // match: (MOVBUreg x:(SEQZ _))
+ // result: x
+ for {
+ x := v_0
+ if x.Op != OpRISCV64SEQZ {
+ break
+ }
+ v.copyOf(x)
+ return true
+ }
+ // match: (MOVBUreg x:(SNEZ _))
+ // result: x
+ for {
+ x := v_0
+ if x.Op != OpRISCV64SNEZ {
+ break
+ }
+ v.copyOf(x)
+ return true
+ }
+ // match: (MOVBUreg x:(SLT _ _))
+ // result: x
+ for {
+ x := v_0
+ if x.Op != OpRISCV64SLT {
+ break
+ }
+ v.copyOf(x)
+ return true
+ }
+ // match: (MOVBUreg x:(SLTU _ _))
+ // result: x
+ for {
+ x := v_0
+ if x.Op != OpRISCV64SLTU {
+ break
+ }
+ v.copyOf(x)
+ return true
+ }
// match: (MOVBUreg (MOVDconst [c]))
// result: (MOVDconst [int64(uint8(c))])
for {
@@ -6483,6 +6523,7 @@ func rewriteValueRISCV64_OpZero(v *Value) bool {
}
}
func rewriteBlockRISCV64(b *Block) bool {
+ typ := &b.Func.Config.Types
switch b.Kind {
case BlockRISCV64BEQ:
// match: (BEQ (MOVDconst [0]) cond yes no)
@@ -6690,10 +6731,12 @@ func rewriteBlockRISCV64(b *Block) bool {
}
case BlockIf:
// match: (If cond yes no)
- // result: (BNEZ cond yes no)
+ // result: (BNEZ (MOVBUreg <typ.UInt64> cond) yes no)
for {
cond := b.Controls[0]
- b.resetWithControl(BlockRISCV64BNEZ, cond)
+ v0 := b.NewValue0(cond.Pos, OpRISCV64MOVBUreg, typ.UInt64)
+ v0.AddArg(cond)
+ b.resetWithControl(BlockRISCV64BNEZ, v0)
return true
}
}