From: Guoqi Chen Date: Wed, 16 Aug 2023 02:22:13 +0000 (+0800) Subject: cmd/compile: fix If lowering on loong64 X-Git-Tag: go1.22rc1~209 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b3b442449b0b979a035b5a26b8e62d8f6158fa69;p=gostls13.git cmd/compile: fix If lowering on loong64 Update #40724 Co-authored-by: Xiaolin Zhao Change-Id: I44477e32db765e0299d8361bd2b8d2c95564ed28 Reviewed-on: https://go-review.googlesource.com/c/go/+/521788 Reviewed-by: Meidan Li Reviewed-by: David Chase Auto-Submit: David Chase TryBot-Result: Gopher Robot Run-TryBot: David Chase Reviewed-by: Cherry Mui --- diff --git a/src/cmd/compile/internal/ssa/_gen/LOONG64.rules b/src/cmd/compile/internal/ssa/_gen/LOONG64.rules index b9aaa3ff7f..2af9519113 100644 --- a/src/cmd/compile/internal/ssa/_gen/LOONG64.rules +++ b/src/cmd/compile/internal/ssa/_gen/LOONG64.rules @@ -416,7 +416,7 @@ (GetCallerSP ...) => (LoweredGetCallerSP ...) (GetCallerPC ...) => (LoweredGetCallerPC ...) -(If cond yes no) => (NE cond yes no) +(If cond yes no) => (NE (MOVBUreg cond) yes no) // Write barrier. (WB ...) => (LoweredWB ...) @@ -450,6 +450,7 @@ (EQ (SGTconst [0] x) yes no) => (GEZ x yes no) (NE (SGT x (MOVVconst [0])) yes no) => (GTZ x yes no) (EQ (SGT x (MOVVconst [0])) yes no) => (LEZ x yes no) +(MOVBUreg x:((SGT|SGTU) _ _)) => x // fold offset into address (ADDVconst [off1] (MOVVaddr [off2] {sym} ptr)) && is32Bit(off1+int64(off2)) => (MOVVaddr [int32(off1)+int32(off2)] {sym} ptr) diff --git a/src/cmd/compile/internal/ssa/rewriteLOONG64.go b/src/cmd/compile/internal/ssa/rewriteLOONG64.go index 757524bdbb..edd3ffe6b9 100644 --- a/src/cmd/compile/internal/ssa/rewriteLOONG64.go +++ b/src/cmd/compile/internal/ssa/rewriteLOONG64.go @@ -1773,6 +1773,26 @@ func rewriteValueLOONG64_OpLOONG64MOVBUload(v *Value) bool { } func rewriteValueLOONG64_OpLOONG64MOVBUreg(v *Value) bool { v_0 := v.Args[0] + // match: (MOVBUreg x:(SGT _ _)) + // result: x + for { + x := v_0 + if x.Op != OpLOONG64SGT { + break + } + v.copyOf(x) + return true + } + // match: (MOVBUreg x:(SGTU _ _)) + // result: x + for { + x := v_0 + if x.Op != OpLOONG64SGTU { + break + } + v.copyOf(x) + return true + } // match: (MOVBUreg x:(MOVBUload _ _)) // result: (MOVVreg x) for { @@ -7608,6 +7628,7 @@ func rewriteValueLOONG64_OpZero(v *Value) bool { return false } func rewriteBlockLOONG64(b *Block) bool { + typ := &b.Func.Config.Types switch b.Kind { case BlockLOONG64EQ: // match: (EQ (FPFlagTrue cmp) yes no) @@ -7807,10 +7828,12 @@ func rewriteBlockLOONG64(b *Block) bool { } case BlockIf: // match: (If cond yes no) - // result: (NE cond yes no) + // result: (NE (MOVBUreg cond) yes no) for { cond := b.Controls[0] - b.resetWithControl(BlockLOONG64NE, cond) + v0 := b.NewValue0(cond.Pos, OpLOONG64MOVBUreg, typ.UInt64) + v0.AddArg(cond) + b.resetWithControl(BlockLOONG64NE, v0) return true } case BlockLOONG64LEZ: