From: limeidan Date: Mon, 28 Jul 2025 06:46:45 +0000 (+0800) Subject: cmd/compile/internal/ssa: use BEQ/BNE to optimize the combination of XOR and EQ/NE... X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b266318cf714ab34be01e32d7338053ca6dcb294;p=gostls13.git cmd/compile/internal/ssa: use BEQ/BNE to optimize the combination of XOR and EQ/NE on loong64 Reduce the number of go toolchain instructions on loong64 as follows: file before after Δ % go 1599056 1590560 -8496 -0.5313% gofmt 326188 326104 -84 -0.0258% asm 563482 561250 -2232 -0.3961% cgo 488644 485252 -3392 -0.6942% compile 2504614 2486388 -18226 -0.7277% cover 526322 523270 -3052 -0.5799% link 714532 711124 -3408 -0.4770% preprofile 242316 241112 -1204 -0.4969% vet 794446 786118 -8328 -1.0483% Change-Id: I0914889119a28ea672b694529ef54513fbb3f3b5 Reviewed-on: https://go-review.googlesource.com/c/go/+/693875 LUCI-TryBot-Result: Go LUCI Reviewed-by: abner chenc Reviewed-by: Dmitri Shuralyov Reviewed-by: Keith Randall --- diff --git a/src/cmd/compile/internal/ssa/_gen/LOONG64latelower.rules b/src/cmd/compile/internal/ssa/_gen/LOONG64latelower.rules index 95844381c2..44583e8e34 100644 --- a/src/cmd/compile/internal/ssa/_gen/LOONG64latelower.rules +++ b/src/cmd/compile/internal/ssa/_gen/LOONG64latelower.rules @@ -4,3 +4,6 @@ // Prefer addition when shifting left by one. (SLLVconst [1] x) => (ADDV x x) + +(EQZ (XOR x y) yes no) => (BEQ x y yes no) +(NEZ (XOR x y) yes no) => (BNE x y yes no) diff --git a/src/cmd/compile/internal/ssa/rewriteLOONG64latelower.go b/src/cmd/compile/internal/ssa/rewriteLOONG64latelower.go index ef9b83192c..60ba120e48 100644 --- a/src/cmd/compile/internal/ssa/rewriteLOONG64latelower.go +++ b/src/cmd/compile/internal/ssa/rewriteLOONG64latelower.go @@ -25,5 +25,37 @@ func rewriteValueLOONG64latelower_OpLOONG64SLLVconst(v *Value) bool { return false } func rewriteBlockLOONG64latelower(b *Block) bool { + switch b.Kind { + case BlockLOONG64EQZ: + // match: (EQZ (XOR x y) yes no) + // result: (BEQ x y yes no) + for b.Controls[0].Op == OpLOONG64XOR { + v_0 := b.Controls[0] + _ = v_0.Args[1] + v_0_0 := v_0.Args[0] + v_0_1 := v_0.Args[1] + for _i0 := 0; _i0 <= 1; _i0, v_0_0, v_0_1 = _i0+1, v_0_1, v_0_0 { + x := v_0_0 + y := v_0_1 + b.resetWithControl2(BlockLOONG64BEQ, x, y) + return true + } + } + case BlockLOONG64NEZ: + // match: (NEZ (XOR x y) yes no) + // result: (BNE x y yes no) + for b.Controls[0].Op == OpLOONG64XOR { + v_0 := b.Controls[0] + _ = v_0.Args[1] + v_0_0 := v_0.Args[0] + v_0_1 := v_0.Args[1] + for _i0 := 0; _i0 <= 1; _i0, v_0_0, v_0_1 = _i0+1, v_0_1, v_0_0 { + x := v_0_0 + y := v_0_1 + b.resetWithControl2(BlockLOONG64BNE, x, y) + return true + } + } + } return false }