From a2d8f8d5d459c05429c9903321529ad149cb2ac4 Mon Sep 17 00:00:00 2001 From: lxq015 <1824368278@qq.com> Date: Mon, 15 Sep 2025 13:50:03 +0800 Subject: [PATCH 1/8] cmd/compile/internal/ssa: add codegen for Zicond extension on riscv64 This patch adds code generation support for the Zicond extension. We convert branches into CondSelect operations in branchelim and rewrite them into Zicond instructions. Additionally, optimization rules have been added to optimize more conditional branch scenarios based on the riscv-isa-manual. Follow-up to CL 631595 Updates #75350 Change-Id: If3f6dbff2fc165addfb4e511e0ac618419d59103 --- src/cmd/compile/internal/riscv64/ssa.go | 3 +- .../compile/internal/ssa/_gen/RISCV64Ops.go | 4 + .../internal/ssa/_gen/RISCV64latelower.rules | 30 ++ src/cmd/compile/internal/ssa/branchelim.go | 9 +- src/cmd/compile/internal/ssa/opGen.go | 30 ++ .../internal/ssa/rewriteRISCV64latelower.go | 371 ++++++++++++++++++ test/codegen/zicond.go | 180 +++++++++ 7 files changed, 625 insertions(+), 2 deletions(-) create mode 100644 test/codegen/zicond.go diff --git a/src/cmd/compile/internal/riscv64/ssa.go b/src/cmd/compile/internal/riscv64/ssa.go index 61de983bb02c00..5c664e01397d1f 100644 --- a/src/cmd/compile/internal/riscv64/ssa.go +++ b/src/cmd/compile/internal/riscv64/ssa.go @@ -294,7 +294,8 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) { ssa.OpRISCV64FADDD, ssa.OpRISCV64FSUBD, ssa.OpRISCV64FMULD, ssa.OpRISCV64FDIVD, ssa.OpRISCV64FEQD, ssa.OpRISCV64FNED, ssa.OpRISCV64FLTD, ssa.OpRISCV64FLED, ssa.OpRISCV64FSGNJD, ssa.OpRISCV64MIN, ssa.OpRISCV64MAX, ssa.OpRISCV64MINU, ssa.OpRISCV64MAXU, - ssa.OpRISCV64SH1ADD, ssa.OpRISCV64SH2ADD, ssa.OpRISCV64SH3ADD: + ssa.OpRISCV64SH1ADD, ssa.OpRISCV64SH2ADD, ssa.OpRISCV64SH3ADD, + ssa.OpRISCV64CZEROEQZ, ssa.OpRISCV64CZERONEZ: r := v.Reg() r1 := v.Args[0].Reg() r2 := v.Args[1].Reg() diff --git a/src/cmd/compile/internal/ssa/_gen/RISCV64Ops.go b/src/cmd/compile/internal/ssa/_gen/RISCV64Ops.go index dc433ff9749150..db27665be54b73 100644 --- a/src/cmd/compile/internal/ssa/_gen/RISCV64Ops.go +++ b/src/cmd/compile/internal/ssa/_gen/RISCV64Ops.go @@ -520,6 +520,10 @@ func init() { // ====+============================= {name: "FCLASSS", argLength: 1, reg: fpgp, asm: "FCLASSS", typ: "Int64"}, // classify float32 {name: "FCLASSD", argLength: 1, reg: fpgp, asm: "FCLASSD", typ: "Int64"}, // classify float64 + + // RISC-V Integer Conditional (Zicond) operations extension + {name: "CZEROEQZ", argLength: 2, reg: gp21, asm: "CZEROEQZ"}, + {name: "CZERONEZ", argLength: 2, reg: gp21, asm: "CZERONEZ"}, } RISCV64blocks := []blockData{ diff --git a/src/cmd/compile/internal/ssa/_gen/RISCV64latelower.rules b/src/cmd/compile/internal/ssa/_gen/RISCV64latelower.rules index 7acaa2f3fec546..2f9b8808920fe7 100644 --- a/src/cmd/compile/internal/ssa/_gen/RISCV64latelower.rules +++ b/src/cmd/compile/internal/ssa/_gen/RISCV64latelower.rules @@ -23,3 +23,33 @@ (SRAI [0] x) => x (SRLI [0] x) => x (SLLI [0] x) => x + +// "Zicond" Extension for Integer Conditional Operations +// (x == 0) ? x : y +(CondSelect x y (SEQZ x)) && buildcfg.GORISCV64 >= 23 => (CZEROEQZ y x) +// (z == 0) ? (x + y) : y +(CondSelect (ADD x y) x (SEQZ z)) && buildcfg.GORISCV64 >= 23 => (ADD x (CZERONEZ y z)) +// (z != 0) ? (x + y) : y +(CondSelect (ADD x y) x (SNEZ z)) && buildcfg.GORISCV64 >= 23 => (ADD x (CZEROEQZ y z)) +// (z == 0) ? (x - y) : y +(CondSelect (SUB x y) x (SEQZ z)) && buildcfg.GORISCV64 >= 23 => (SUB x (CZERONEZ y z)) +// (z != 0) ? (x - y) : y +(CondSelect (SUB x y) x (SNEZ z)) && buildcfg.GORISCV64 >= 23 => (SUB x (CZEROEQZ y z)) +// (z == 0) ? (x | y) : y +(CondSelect (OR x y) x (SEQZ z)) && buildcfg.GORISCV64 >= 23 => (OR x (CZERONEZ y z)) +// (z != 0) ? (x | y) : y +(CondSelect (OR x y) x (SNEZ z)) && buildcfg.GORISCV64 >= 23 => (OR x (CZEROEQZ y z)) +// (z == 0) ? (x ^ y) : y +(CondSelect (XOR x y) x (SEQZ z)) && buildcfg.GORISCV64 >= 23 => (XOR x (CZERONEZ y z)) +// (z != 0) ? (x ^ y) : y +(CondSelect (XOR x y) x (SNEZ z)) && buildcfg.GORISCV64 >= 23 => (XOR x (CZEROEQZ y z)) +// (z == 0) ? (x & y) : y +(CondSelect (AND x y) x (SEQZ z)) && buildcfg.GORISCV64 >= 23 => (OR (AND x y) (CZEROEQZ x z)) +// (z != 0) ? (x & y) : y +(CondSelect (AND x y) x (SNEZ z)) && buildcfg.GORISCV64 >= 23 => (OR (AND x y) (CZERONEZ x z)) +// (z == 0) ? x : y +(CondSelect x y (SEQZ z)) && buildcfg.GORISCV64 >= 23 => (OR (CZERONEZ x z) (CZEROEQZ y z)) +// (z != 0) ? x : y +(CondSelect x y (SNEZ z)) && buildcfg.GORISCV64 >= 23 => (OR (CZEROEQZ x z) (CZERONEZ y z)) +// Make sure we can rewrite all CondSelects. +(CondSelect x y cond) && buildcfg.GORISCV64 >= 23 => (OR (CZEROEQZ x cond) (CZERONEZ y cond)) diff --git a/src/cmd/compile/internal/ssa/branchelim.go b/src/cmd/compile/internal/ssa/branchelim.go index a7d339cad064ac..66922b7ab09fba 100644 --- a/src/cmd/compile/internal/ssa/branchelim.go +++ b/src/cmd/compile/internal/ssa/branchelim.go @@ -4,7 +4,10 @@ package ssa -import "cmd/internal/src" +import ( + "cmd/internal/src" + "internal/buildcfg" +) // branchelim tries to eliminate branches by // generating CondSelect instructions. @@ -24,6 +27,10 @@ func branchelim(f *Func) { switch f.Config.arch { case "arm64", "ppc64le", "ppc64", "amd64", "wasm", "loong64": // implemented + case "riscv64": + if buildcfg.GORISCV64 < 23 { + return + } default: return } diff --git a/src/cmd/compile/internal/ssa/opGen.go b/src/cmd/compile/internal/ssa/opGen.go index b4aae50b895ff8..76df7d999bee11 100644 --- a/src/cmd/compile/internal/ssa/opGen.go +++ b/src/cmd/compile/internal/ssa/opGen.go @@ -2648,6 +2648,8 @@ const ( OpRISCV64LoweredFMAXD OpRISCV64FCLASSS OpRISCV64FCLASSD + OpRISCV64CZEROEQZ + OpRISCV64CZERONEZ OpS390XFADDS OpS390XFADD @@ -35662,6 +35664,34 @@ var opcodeTable = [...]opInfo{ }, }, }, + { + name: "CZEROEQZ", + argLen: 2, + asm: riscv.ACZEROEQZ, + reg: regInfo{ + inputs: []inputInfo{ + {0, 1006632944}, // X5 X6 X7 X8 X9 X10 X11 X12 X13 X14 X15 X16 X17 X18 X19 X20 X21 X22 X23 X24 X25 X26 X28 X29 X30 + {1, 1006632944}, // X5 X6 X7 X8 X9 X10 X11 X12 X13 X14 X15 X16 X17 X18 X19 X20 X21 X22 X23 X24 X25 X26 X28 X29 X30 + }, + outputs: []outputInfo{ + {0, 1006632944}, // X5 X6 X7 X8 X9 X10 X11 X12 X13 X14 X15 X16 X17 X18 X19 X20 X21 X22 X23 X24 X25 X26 X28 X29 X30 + }, + }, + }, + { + name: "CZERONEZ", + argLen: 2, + asm: riscv.ACZERONEZ, + reg: regInfo{ + inputs: []inputInfo{ + {0, 1006632944}, // X5 X6 X7 X8 X9 X10 X11 X12 X13 X14 X15 X16 X17 X18 X19 X20 X21 X22 X23 X24 X25 X26 X28 X29 X30 + {1, 1006632944}, // X5 X6 X7 X8 X9 X10 X11 X12 X13 X14 X15 X16 X17 X18 X19 X20 X21 X22 X23 X24 X25 X26 X28 X29 X30 + }, + outputs: []outputInfo{ + {0, 1006632944}, // X5 X6 X7 X8 X9 X10 X11 X12 X13 X14 X15 X16 X17 X18 X19 X20 X21 X22 X23 X24 X25 X26 X28 X29 X30 + }, + }, + }, { name: "FADDS", diff --git a/src/cmd/compile/internal/ssa/rewriteRISCV64latelower.go b/src/cmd/compile/internal/ssa/rewriteRISCV64latelower.go index d2c3a8f73df2e9..e7336e4d489b2e 100644 --- a/src/cmd/compile/internal/ssa/rewriteRISCV64latelower.go +++ b/src/cmd/compile/internal/ssa/rewriteRISCV64latelower.go @@ -2,8 +2,12 @@ package ssa +import "internal/buildcfg" + func rewriteValueRISCV64latelower(v *Value) bool { switch v.Op { + case OpCondSelect: + return rewriteValueRISCV64latelower_OpCondSelect(v) case OpRISCV64AND: return rewriteValueRISCV64latelower_OpRISCV64AND(v) case OpRISCV64NOT: @@ -21,6 +25,373 @@ func rewriteValueRISCV64latelower(v *Value) bool { } return false } +func rewriteValueRISCV64latelower_OpCondSelect(v *Value) bool { + v_2 := v.Args[2] + v_1 := v.Args[1] + v_0 := v.Args[0] + b := v.Block + // match: (CondSelect x y (SEQZ x)) + // cond: buildcfg.GORISCV64 >= 23 + // result: (CZEROEQZ y x) + for { + t := v.Type + x := v_0 + y := v_1 + if v_2.Op != OpRISCV64SEQZ || x != v_2.Args[0] || !(buildcfg.GORISCV64 >= 23) { + break + } + v.reset(OpRISCV64CZEROEQZ) + v.Type = t + v.AddArg2(y, x) + return true + } + // match: (CondSelect (ADD x y) x (SEQZ z)) + // cond: buildcfg.GORISCV64 >= 23 + // result: (ADD x (CZERONEZ y z)) + for { + t := v.Type + if v_0.Op != OpRISCV64ADD { + break + } + _ = 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 + if x != v_1 || v_2.Op != OpRISCV64SEQZ { + continue + } + z := v_2.Args[0] + if !(buildcfg.GORISCV64 >= 23) { + continue + } + v.reset(OpRISCV64ADD) + v0 := b.NewValue0(v.Pos, OpRISCV64CZERONEZ, t) + v0.AddArg2(y, z) + v.AddArg2(x, v0) + return true + } + break + } + // match: (CondSelect (ADD x y) x (SNEZ z)) + // cond: buildcfg.GORISCV64 >= 23 + // result: (ADD x (CZEROEQZ y z)) + for { + t := v.Type + if v_0.Op != OpRISCV64ADD { + break + } + _ = 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 + if x != v_1 || v_2.Op != OpRISCV64SNEZ { + continue + } + z := v_2.Args[0] + if !(buildcfg.GORISCV64 >= 23) { + continue + } + v.reset(OpRISCV64ADD) + v0 := b.NewValue0(v.Pos, OpRISCV64CZEROEQZ, t) + v0.AddArg2(y, z) + v.AddArg2(x, v0) + return true + } + break + } + // match: (CondSelect (SUB x y) x (SEQZ z)) + // cond: buildcfg.GORISCV64 >= 23 + // result: (SUB x (CZERONEZ y z)) + for { + t := v.Type + if v_0.Op != OpRISCV64SUB { + break + } + y := v_0.Args[1] + x := v_0.Args[0] + if x != v_1 || v_2.Op != OpRISCV64SEQZ { + break + } + z := v_2.Args[0] + if !(buildcfg.GORISCV64 >= 23) { + break + } + v.reset(OpRISCV64SUB) + v0 := b.NewValue0(v.Pos, OpRISCV64CZERONEZ, t) + v0.AddArg2(y, z) + v.AddArg2(x, v0) + return true + } + // match: (CondSelect (SUB x y) x (SNEZ z)) + // cond: buildcfg.GORISCV64 >= 23 + // result: (SUB x (CZEROEQZ y z)) + for { + t := v.Type + if v_0.Op != OpRISCV64SUB { + break + } + y := v_0.Args[1] + x := v_0.Args[0] + if x != v_1 || v_2.Op != OpRISCV64SNEZ { + break + } + z := v_2.Args[0] + if !(buildcfg.GORISCV64 >= 23) { + break + } + v.reset(OpRISCV64SUB) + v0 := b.NewValue0(v.Pos, OpRISCV64CZEROEQZ, t) + v0.AddArg2(y, z) + v.AddArg2(x, v0) + return true + } + // match: (CondSelect (OR x y) x (SEQZ z)) + // cond: buildcfg.GORISCV64 >= 23 + // result: (OR x (CZERONEZ y z)) + for { + t := v.Type + if v_0.Op != OpRISCV64OR { + break + } + _ = 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 + if x != v_1 || v_2.Op != OpRISCV64SEQZ { + continue + } + z := v_2.Args[0] + if !(buildcfg.GORISCV64 >= 23) { + continue + } + v.reset(OpRISCV64OR) + v0 := b.NewValue0(v.Pos, OpRISCV64CZERONEZ, t) + v0.AddArg2(y, z) + v.AddArg2(x, v0) + return true + } + break + } + // match: (CondSelect (OR x y) x (SNEZ z)) + // cond: buildcfg.GORISCV64 >= 23 + // result: (OR x (CZEROEQZ y z)) + for { + t := v.Type + if v_0.Op != OpRISCV64OR { + break + } + _ = 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 + if x != v_1 || v_2.Op != OpRISCV64SNEZ { + continue + } + z := v_2.Args[0] + if !(buildcfg.GORISCV64 >= 23) { + continue + } + v.reset(OpRISCV64OR) + v0 := b.NewValue0(v.Pos, OpRISCV64CZEROEQZ, t) + v0.AddArg2(y, z) + v.AddArg2(x, v0) + return true + } + break + } + // match: (CondSelect (XOR x y) x (SEQZ z)) + // cond: buildcfg.GORISCV64 >= 23 + // result: (XOR x (CZERONEZ y z)) + for { + t := v.Type + if v_0.Op != OpRISCV64XOR { + break + } + _ = 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 + if x != v_1 || v_2.Op != OpRISCV64SEQZ { + continue + } + z := v_2.Args[0] + if !(buildcfg.GORISCV64 >= 23) { + continue + } + v.reset(OpRISCV64XOR) + v0 := b.NewValue0(v.Pos, OpRISCV64CZERONEZ, t) + v0.AddArg2(y, z) + v.AddArg2(x, v0) + return true + } + break + } + // match: (CondSelect (XOR x y) x (SNEZ z)) + // cond: buildcfg.GORISCV64 >= 23 + // result: (XOR x (CZEROEQZ y z)) + for { + t := v.Type + if v_0.Op != OpRISCV64XOR { + break + } + _ = 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 + if x != v_1 || v_2.Op != OpRISCV64SNEZ { + continue + } + z := v_2.Args[0] + if !(buildcfg.GORISCV64 >= 23) { + continue + } + v.reset(OpRISCV64XOR) + v0 := b.NewValue0(v.Pos, OpRISCV64CZEROEQZ, t) + v0.AddArg2(y, z) + v.AddArg2(x, v0) + return true + } + break + } + // match: (CondSelect (AND x y) x (SEQZ z)) + // cond: buildcfg.GORISCV64 >= 23 + // result: (OR (AND x y) (CZEROEQZ x z)) + for { + t := v.Type + if v_0.Op != OpRISCV64AND { + break + } + _ = 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 + if x != v_1 || v_2.Op != OpRISCV64SEQZ { + continue + } + z := v_2.Args[0] + if !(buildcfg.GORISCV64 >= 23) { + continue + } + v.reset(OpRISCV64OR) + v0 := b.NewValue0(v.Pos, OpRISCV64AND, t) + v0.AddArg2(x, y) + v1 := b.NewValue0(v.Pos, OpRISCV64CZEROEQZ, t) + v1.AddArg2(x, z) + v.AddArg2(v0, v1) + return true + } + break + } + // match: (CondSelect (AND x y) x (SNEZ z)) + // cond: buildcfg.GORISCV64 >= 23 + // result: (OR (AND x y) (CZERONEZ x z)) + for { + t := v.Type + if v_0.Op != OpRISCV64AND { + break + } + _ = 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 + if x != v_1 || v_2.Op != OpRISCV64SNEZ { + continue + } + z := v_2.Args[0] + if !(buildcfg.GORISCV64 >= 23) { + continue + } + v.reset(OpRISCV64OR) + v0 := b.NewValue0(v.Pos, OpRISCV64AND, t) + v0.AddArg2(x, y) + v1 := b.NewValue0(v.Pos, OpRISCV64CZERONEZ, t) + v1.AddArg2(x, z) + v.AddArg2(v0, v1) + return true + } + break + } + // match: (CondSelect x y (SEQZ z)) + // cond: buildcfg.GORISCV64 >= 23 + // result: (OR (CZERONEZ x z) (CZEROEQZ y z)) + for { + t := v.Type + x := v_0 + y := v_1 + if v_2.Op != OpRISCV64SEQZ { + break + } + z := v_2.Args[0] + if !(buildcfg.GORISCV64 >= 23) { + break + } + v.reset(OpRISCV64OR) + v0 := b.NewValue0(v.Pos, OpRISCV64CZERONEZ, t) + v0.AddArg2(x, z) + v1 := b.NewValue0(v.Pos, OpRISCV64CZEROEQZ, t) + v1.AddArg2(y, z) + v.AddArg2(v0, v1) + return true + } + // match: (CondSelect x y (SNEZ z)) + // cond: buildcfg.GORISCV64 >= 23 + // result: (OR (CZEROEQZ x z) (CZERONEZ y z)) + for { + t := v.Type + x := v_0 + y := v_1 + if v_2.Op != OpRISCV64SNEZ { + break + } + z := v_2.Args[0] + if !(buildcfg.GORISCV64 >= 23) { + break + } + v.reset(OpRISCV64OR) + v0 := b.NewValue0(v.Pos, OpRISCV64CZEROEQZ, t) + v0.AddArg2(x, z) + v1 := b.NewValue0(v.Pos, OpRISCV64CZERONEZ, t) + v1.AddArg2(y, z) + v.AddArg2(v0, v1) + return true + } + // match: (CondSelect x y cond) + // cond: buildcfg.GORISCV64 >= 23 + // result: (OR (CZEROEQZ x cond) (CZERONEZ y cond)) + for { + t := v.Type + x := v_0 + y := v_1 + cond := v_2 + if !(buildcfg.GORISCV64 >= 23) { + break + } + v.reset(OpRISCV64OR) + v0 := b.NewValue0(v.Pos, OpRISCV64CZEROEQZ, t) + v0.AddArg2(x, cond) + v1 := b.NewValue0(v.Pos, OpRISCV64CZERONEZ, t) + v1.AddArg2(y, cond) + v.AddArg2(v0, v1) + return true + } + return false +} func rewriteValueRISCV64latelower_OpRISCV64AND(v *Value) bool { v_1 := v.Args[1] v_0 := v.Args[0] diff --git a/test/codegen/zicond.go b/test/codegen/zicond.go new file mode 100644 index 00000000000000..c3c6b65bc972e3 --- /dev/null +++ b/test/codegen/zicond.go @@ -0,0 +1,180 @@ +// asmcheck + +// Copyright 2025 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package codegen + +//go:noinline +func testIfxZero(a, b int) int { + r := b + if a == 0 { + r = a + } + // riscv64/rva23u64:`CZEROEQZ`, -`CZERONEZ` + return r +} + +//go:noinline +func testZicond(a, b int) int { + var c int + if a > b { + c = a + } else { + c = b + } + // riscv64/rva23u64:`CZERONEZ`,`CZEROEQZ` + return c +} + +//go:noinline +func selectIfZero(cond, a, b int) int { + r := a + if cond == 0 { + r = b + } + // riscv64/rva23u64:`CZERONEZ`,`CZEROEQZ`, `OR` + // riscv64/rva23u64:-`SEQZ` + return r +} + +//go:noinline +func testSelectIfNotZero(cond, a, b int) int { + r := a + if cond != 0 { + r = b + } + // riscv64/rva23u64:`CZERONEZ`,`CZEROEQZ`, `OR` + // riscv64/rva23u64:-`SNEZ` + return r +} + +//go:noinline +func testCondAddZero(cond, a, b int) int { + result := a + if cond == 0 { + result = a + b + } + // riscv64/rva23u64:`CZERONEZ`, `ADD` + // riscv64/rva23u64:-`SEQZ`, -`CZEROEQZ`, -`OR` + return result +} + +//go:noinline +func testCondAddNonZero(cond, a, b int) int { + var result int + if cond != 0 { + result = a + b + } else { + result = a + } + // riscv64/rva23u64:`CZEROEQZ`, `ADD` + // riscv64/rva23u64:-`SNEZ`, -`CZERONEZ`, -`OR` + return result +} + +//go:noinline +func testCondSubZero(cond, a, b int) int { + var result int + if cond == 0 { + result = a - b + } else { + result = a + } + // riscv64/rva23u64:`CZERONEZ`, `SUB` + // riscv64/rva23u64:-`SEQZ`, -`CZEROEQZ`, -`OR` + return result +} + +//go:noinline +func testCondSubNonZero(cond, a, b int) int { + var result int + if cond != 0 { + result = a - b + } else { + result = a + } + // riscv64/rva23u64:`CZEROEQZ`, `SUB` + // riscv64/rva23u64:-`SNEZ`, -`CZERONEZ`, -`OR` + return result +} + +//go:noinline +func testCondOrZero(cond, a, b int) int { + var result int + if cond == 0 { + result = a | b + } else { + result = a + } + // riscv64/rva23u64:`CZERONEZ`, `OR` + // riscv64/rva23u64:-`SEQZ`, -`CZEROEQZ` + return result +} + +//go:noinline +func testCondOrNonZero(cond, a, b int) int { + var result int + if cond != 0 { + result = a | b + } else { + result = a + } + // riscv64/rva23u64:`CZEROEQZ`, `OR` + // riscv64/rva23u64:-`SNEZ`, -`CZERONEZ` + return result +} + +//go:noinline +func testCondXorZero(cond, a, b int) int { + var result int + if cond == 0 { + result = a ^ b + } else { + result = a + } + // riscv64/rva23u64:`CZERONEZ`, `XOR` + // riscv64/rva23u64:-`SEQZ`, -`CZEROEQZ`, -`OR` + return result +} + +//go:noinline +func testCondXorNonZero(cond, a, b int) int { + var result int + if cond != 0 { + result = a ^ b + } else { + result = a + } + // riscv64/rva23u64:`CZEROEQZ`, `XOR` + // riscv64/rva23u64:-`SNEZ`, -`CZERONEZ`, -`OR` + return result +} + +//go:noinline +func testCondAndZero(cond, a, b int) int { + var result int + if cond == 0 { + result = a & b + } else { + result = a + } + // riscv64/rva23u64:`CZEROEQZ`, `AND`, `OR` + // riscv64/rva23u64:-`SEQZ`, -`CZERONEZ` + return result +} + +//go:noinline +func testCondAndNonZero(cond, a, b int) int { + var result int + if cond != 0 { + result = a & b + } else { + result = a + } + // riscv64/rva23u64:`CZERONEZ`, `AND`, `OR` + // riscv64/rva23u64:-`SNEZ`, -`CZEROEQZ` + return result +} + \ No newline at end of file From f5f9d07332ea4ccbafa96c8dcfd94a7fa9fef18a Mon Sep 17 00:00:00 2001 From: lxq015 <1824368278@qq.com> Date: Wed, 24 Sep 2025 12:34:15 +0800 Subject: [PATCH 2/8] add tests --- test/codegen/zicond.go | 75 ++++++++++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 28 deletions(-) diff --git a/test/codegen/zicond.go b/test/codegen/zicond.go index c3c6b65bc972e3..788bfe8fa764e2 100644 --- a/test/codegen/zicond.go +++ b/test/codegen/zicond.go @@ -7,47 +7,67 @@ package codegen //go:noinline -func testIfxZero(a, b int) int { - r := b +func testNoZicondUnderRva20u64(a, b int) int { + result := b if a == 0 { - r = a + result = a + } + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + return result +} + +//go:noinline +func testNoZicondUnderRva22u64(a, b int) int { + result := b + if a == 0 { + result = a + } + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + return result +} + +//go:noinline +func testGenZicondUnderRva23u64(a, b int) int { + result := b + if a == 0 { + result = a } // riscv64/rva23u64:`CZEROEQZ`, -`CZERONEZ` - return r + return result } //go:noinline -func testZicond(a, b int) int { - var c int +func testGenZicond(a, b int) int { + var result int if a > b { - c = a + result = a } else { - c = b + result = b } // riscv64/rva23u64:`CZERONEZ`,`CZEROEQZ` - return c + return result } //go:noinline func selectIfZero(cond, a, b int) int { - r := a + result := a if cond == 0 { - r = b + result = b } // riscv64/rva23u64:`CZERONEZ`,`CZEROEQZ`, `OR` // riscv64/rva23u64:-`SEQZ` - return r + return result } //go:noinline func testSelectIfNotZero(cond, a, b int) int { - r := a + result := a if cond != 0 { - r = b + result = b } // riscv64/rva23u64:`CZERONEZ`,`CZEROEQZ`, `OR` // riscv64/rva23u64:-`SNEZ` - return r + return result } //go:noinline @@ -60,7 +80,7 @@ func testCondAddZero(cond, a, b int) int { // riscv64/rva23u64:-`SEQZ`, -`CZEROEQZ`, -`OR` return result } - + //go:noinline func testCondAddNonZero(cond, a, b int) int { var result int @@ -102,11 +122,11 @@ func testCondSubNonZero(cond, a, b int) int { //go:noinline func testCondOrZero(cond, a, b int) int { - var result int - if cond == 0 { + var result int + if cond == 0 { result = a | b - } else { - result = a + } else { + result = a } // riscv64/rva23u64:`CZERONEZ`, `OR` // riscv64/rva23u64:-`SEQZ`, -`CZEROEQZ` @@ -115,16 +135,16 @@ func testCondOrZero(cond, a, b int) int { //go:noinline func testCondOrNonZero(cond, a, b int) int { - var result int - if cond != 0 { + var result int + if cond != 0 { result = a | b - } else { - result = a + } else { + result = a } // riscv64/rva23u64:`CZEROEQZ`, `OR` // riscv64/rva23u64:-`SNEZ`, -`CZERONEZ` return result -} +} //go:noinline func testCondXorZero(cond, a, b int) int { @@ -138,7 +158,7 @@ func testCondXorZero(cond, a, b int) int { // riscv64/rva23u64:-`SEQZ`, -`CZEROEQZ`, -`OR` return result } - + //go:noinline func testCondXorNonZero(cond, a, b int) int { var result int @@ -164,7 +184,7 @@ func testCondAndZero(cond, a, b int) int { // riscv64/rva23u64:-`SEQZ`, -`CZERONEZ` return result } - + //go:noinline func testCondAndNonZero(cond, a, b int) int { var result int @@ -177,4 +197,3 @@ func testCondAndNonZero(cond, a, b int) int { // riscv64/rva23u64:-`SNEZ`, -`CZEROEQZ` return result } - \ No newline at end of file From 58e1e0c7ed56a4a41de8a685f603b4b0f8f7c515 Mon Sep 17 00:00:00 2001 From: lxq015 <1824368278@qq.com> Date: Thu, 25 Sep 2025 16:40:16 +0800 Subject: [PATCH 3/8] move tests in zicond.go to condmove.go --- test/codegen/condmove.go | 228 +++++++++++++++++++++++++++++++++++++++ test/codegen/zicond.go | 199 ---------------------------------- 2 files changed, 228 insertions(+), 199 deletions(-) delete mode 100644 test/codegen/zicond.go diff --git a/test/codegen/condmove.go b/test/codegen/condmove.go index 97be0ced75d19d..8670d0e65c71e3 100644 --- a/test/codegen/condmove.go +++ b/test/codegen/condmove.go @@ -15,6 +15,9 @@ func cmovint(c int) int { // arm64:"CSEL\tLT" // ppc64x:"ISEL\t[$]0" // wasm:"Select" + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` return x } @@ -26,6 +29,9 @@ func cmovchan(x, y chan int) chan int { // arm64:"CSEL\tNE" // ppc64x:"ISEL\t[$]2" // wasm:"Select" + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` return x } @@ -37,6 +43,9 @@ func cmovuintptr(x, y uintptr) uintptr { // arm64:"CSNEG\tLS" // ppc64x:"ISEL\t[$]1" // wasm:"Select" + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` return x } @@ -48,6 +57,9 @@ func cmov32bit(x, y uint32) uint32 { // arm64:"CSNEG\t(LS|HS)" // ppc64x:"ISEL\t[$]1" // wasm:"Select" + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` return x } @@ -59,6 +71,9 @@ func cmov16bit(x, y uint16) uint16 { // arm64:"CSNEG\t(LS|HS)" // ppc64x:"ISEL\t[$][01]" // wasm:"Select" + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` return x } @@ -73,6 +88,9 @@ func cmovfloateq(x, y float64) int { // arm64:"CSEL\tEQ" // ppc64x:"ISEL\t[$]2" // wasm:"Select" + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` return a } @@ -85,6 +103,9 @@ func cmovfloatne(x, y float64) int { // arm64:"CSEL\tNE" // ppc64x:"ISEL\t[$]2" // wasm:"Select" + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` return a } @@ -112,6 +133,9 @@ func cmovfloatint2(x, y float64) float64 { // arm64:"CSEL\tMI" // ppc64x:"ISEL\t[$]0" // wasm:"Select" + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` r = r - ldexp(y, rexp-yexp) } return r @@ -127,6 +151,9 @@ func cmovloaded(x [4]int, y int) int { // arm64:"CSEL\tNE" // ppc64x:"ISEL\t[$]2" // wasm:"Select" + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR`, -`SNEZ` return y } @@ -139,6 +166,9 @@ func cmovuintptr2(x, y uintptr) uintptr { // arm64:"CSEL\tEQ" // ppc64x:"ISEL\t[$]2" // wasm:"Select" + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR`, -`SEQZ` return a } @@ -165,6 +195,9 @@ func cmovinvert1(x, y int64) int64 { y = -y } // amd64:"CMOVQGT" + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` return y } func cmovinvert2(x, y int64) int64 { @@ -179,6 +212,9 @@ func cmovinvert3(x, y int64) int64 { y = -y } // amd64:"CMOVQEQ" + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` return y } func cmovinvert4(x, y int64) int64 { @@ -186,6 +222,9 @@ func cmovinvert4(x, y int64) int64 { y = -y } // amd64:"CMOVQNE" + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` return y } func cmovinvert5(x, y uint64) uint64 { @@ -193,6 +232,9 @@ func cmovinvert5(x, y uint64) uint64 { y = -y } // amd64:"CMOVQCS" + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` return y } func cmovinvert6(x, y uint64) uint64 { @@ -200,6 +242,9 @@ func cmovinvert6(x, y uint64) uint64 { y = -y } // amd64:"CMOVQLS" + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` return y } @@ -217,6 +262,9 @@ func cmovstore(a []int, i int, b bool) { i += 42 } // amd64:"CMOVQNE" + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` a[i] = 7 } @@ -231,6 +279,9 @@ func cmovinc(cond bool, a, b, c int) { x0 = b + 1 } // arm64:"CSINC\tNE", -"CSEL" + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` r0 = x0 if cond { @@ -239,6 +290,9 @@ func cmovinc(cond bool, a, b, c int) { x1 = a } // arm64:"CSINC\tEQ", -"CSEL" + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` r1 = x1 if cond { @@ -257,6 +311,9 @@ func cmovinv(cond bool, a, b int) { x0 = ^b } // arm64:"CSINV\tNE", -"CSEL" + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` r0 = x0 if cond { @@ -265,6 +322,9 @@ func cmovinv(cond bool, a, b int) { x1 = a } // arm64:"CSINV\tEQ", -"CSEL" + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` r1 = x1 } @@ -277,6 +337,9 @@ func cmovneg(cond bool, a, b, c int) { x0 = -b } // arm64:"CSNEG\tNE", -"CSEL" + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` r0 = x0 if cond { @@ -285,6 +348,9 @@ func cmovneg(cond bool, a, b, c int) { x1 = a } // arm64:"CSNEG\tEQ", -"CSEL" + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` r1 = x1 } @@ -297,6 +363,9 @@ func cmovsetm(cond bool, x int) { x0 = 0 } // arm64:"CSETM\tNE", -"CSEL" + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` r0 = x0 if cond { @@ -305,6 +374,9 @@ func cmovsetm(cond bool, x int) { x1 = -1 } // arm64:"CSETM\tEQ", -"CSEL" + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` r1 = x1 } @@ -317,6 +389,9 @@ func cmovFcmp0(s, t float64, a, b int) { x0 = b + 1 } // arm64:"CSINC\tMI", -"CSEL" + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` r0 = x0 if s <= t { @@ -325,6 +400,9 @@ func cmovFcmp0(s, t float64, a, b int) { x1 = ^b } // arm64:"CSINV\tLS", -"CSEL" + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` r1 = x1 if s > t { @@ -333,6 +411,9 @@ func cmovFcmp0(s, t float64, a, b int) { x2 = -b } // arm64:"CSNEG\tMI", -"CSEL" + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` r2 = x2 if s >= t { @@ -341,6 +422,9 @@ func cmovFcmp0(s, t float64, a, b int) { x3 = 0 } // arm64:"CSETM\tLS", -"CSEL" + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` r3 = x3 if s == t { @@ -349,6 +433,9 @@ func cmovFcmp0(s, t float64, a, b int) { x4 = b + 1 } // arm64:"CSINC\tEQ", -"CSEL" + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` r4 = x4 if s != t { @@ -357,6 +444,9 @@ func cmovFcmp0(s, t float64, a, b int) { x5 = b + 1 } // arm64:"CSINC\tNE", -"CSEL" + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` r5 = x5 } @@ -369,6 +459,9 @@ func cmovFcmp1(s, t float64, a, b int) { x0 = a } // arm64:"CSINC\tPL", -"CSEL" + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` r0 = x0 if s <= t { @@ -377,6 +470,9 @@ func cmovFcmp1(s, t float64, a, b int) { x1 = a } // arm64:"CSINV\tHI", -"CSEL" + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` r1 = x1 if s > t { @@ -385,6 +481,9 @@ func cmovFcmp1(s, t float64, a, b int) { x2 = a } // arm64:"CSNEG\tPL", -"CSEL" + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` r2 = x2 if s >= t { @@ -393,6 +492,9 @@ func cmovFcmp1(s, t float64, a, b int) { x3 = -1 } // arm64:"CSETM\tHI", -"CSEL" + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` r3 = x3 if s == t { @@ -401,6 +503,9 @@ func cmovFcmp1(s, t float64, a, b int) { x4 = a } // arm64:"CSINC\tNE", -"CSEL" + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` r4 = x4 if s != t { @@ -409,6 +514,9 @@ func cmovFcmp1(s, t float64, a, b int) { x5 = a } // arm64:"CSINC\tEQ", -"CSEL" + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` r5 = x5 } @@ -418,6 +526,9 @@ func cmovzero1(c bool) int { x = 182 } // loong64:"MASKEQZ", -"MASKNEZ" + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` return x } @@ -427,6 +538,9 @@ func cmovzero2(c bool) int { x = 182 } // loong64:"MASKNEZ", -"MASKEQZ" + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` return x } @@ -440,6 +554,9 @@ func cmovzeroreg0(a, b int) int { x = a } // ppc64x:"ISEL\t[$]2, R[0-9]+, R0, R[0-9]+" + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` return x } @@ -449,6 +566,9 @@ func cmovzeroreg1(a, b int) int { x = 0 } // ppc64x:"ISEL\t[$]2, R0, R[0-9]+, R[0-9]+" + // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` return x } @@ -507,3 +627,111 @@ func cmovmathhalveu(a uint, b bool) uint { // wasm:"I64ShrU", -"Select" return a } + +func cmoveAddZero(cond, a, b int) int { + result := a + if cond == 0 { + result = a + b + } + // riscv64/rva23u64:`CZERONEZ`, `ADD`, -`SEQZ`, -`CZEROEQZ`, -`OR` + return result +} + +func cmoveAddNonZero(cond, a, b int) int { + var result int + if cond != 0 { + result = a + b + } else { + result = a + } + // riscv64/rva23u64:`CZEROEQZ`, `ADD`, -`SNEZ`, -`CZERONEZ`, -`OR` + return result +} + +func cmoveSubZero(cond, a, b int) int { + var result int + if cond == 0 { + result = a - b + } else { + result = a + } + // riscv64/rva23u64:`CZERONEZ`, `SUB`, -`SEQZ`, -`CZEROEQZ`, -`OR` + return result +} + +func cmoveSubNonZero(cond, a, b int) int { + var result int + if cond != 0 { + result = a - b + } else { + result = a + } + // riscv64/rva23u64:`CZEROEQZ`, `SUB`, -`SNEZ`, -`CZERONEZ`, -`OR` + return result +} + +func cmoveOrZero(cond, a, b int) int { + var result int + if cond == 0 { + result = a | b + } else { + result = a + } + // riscv64/rva23u64:`CZERONEZ`, `OR`, -`SEQZ`, -`CZEROEQZ` + return result +} + +func cmoveOrNonZero(cond, a, b int) int { + var result int + if cond != 0 { + result = a | b + } else { + result = a + } + // riscv64/rva23u64:`CZEROEQZ`, `OR`, -`SNEZ`, -`CZERONEZ` + return result +} + +func cmoveXorZero(cond, a, b int) int { + var result int + if cond == 0 { + result = a ^ b + } else { + result = a + } + // riscv64/rva23u64:`CZERONEZ`, `XOR`, -`SEQZ`, -`CZEROEQZ`, -`OR` + return result +} + +func cmoveXorNonZero(cond, a, b int) int { + var result int + if cond != 0 { + result = a ^ b + } else { + result = a + } + // riscv64/rva23u64:`CZEROEQZ`, `XOR`, -`SNEZ`, -`CZERONEZ`, -`OR` + return result +} + +func cmoveAndZero(cond, a, b int) int { + var result int + if cond == 0 { + result = a & b + } else { + result = a + } + // riscv64/rva23u64:`CZEROEQZ`, `AND`, `OR`, -`SEQZ`, -`CZERONEZ` + return result +} + +func CondAndNonZero(cond, a, b int) int { + var result int + if cond != 0 { + result = a & b + } else { + result = a + } + // riscv64/rva23u64:`CZERONEZ`, `AND`, `OR`, -`SNEZ`, -`CZEROEQZ` + return result +} diff --git a/test/codegen/zicond.go b/test/codegen/zicond.go deleted file mode 100644 index 788bfe8fa764e2..00000000000000 --- a/test/codegen/zicond.go +++ /dev/null @@ -1,199 +0,0 @@ -// asmcheck - -// Copyright 2025 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package codegen - -//go:noinline -func testNoZicondUnderRva20u64(a, b int) int { - result := b - if a == 0 { - result = a - } - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - return result -} - -//go:noinline -func testNoZicondUnderRva22u64(a, b int) int { - result := b - if a == 0 { - result = a - } - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` - return result -} - -//go:noinline -func testGenZicondUnderRva23u64(a, b int) int { - result := b - if a == 0 { - result = a - } - // riscv64/rva23u64:`CZEROEQZ`, -`CZERONEZ` - return result -} - -//go:noinline -func testGenZicond(a, b int) int { - var result int - if a > b { - result = a - } else { - result = b - } - // riscv64/rva23u64:`CZERONEZ`,`CZEROEQZ` - return result -} - -//go:noinline -func selectIfZero(cond, a, b int) int { - result := a - if cond == 0 { - result = b - } - // riscv64/rva23u64:`CZERONEZ`,`CZEROEQZ`, `OR` - // riscv64/rva23u64:-`SEQZ` - return result -} - -//go:noinline -func testSelectIfNotZero(cond, a, b int) int { - result := a - if cond != 0 { - result = b - } - // riscv64/rva23u64:`CZERONEZ`,`CZEROEQZ`, `OR` - // riscv64/rva23u64:-`SNEZ` - return result -} - -//go:noinline -func testCondAddZero(cond, a, b int) int { - result := a - if cond == 0 { - result = a + b - } - // riscv64/rva23u64:`CZERONEZ`, `ADD` - // riscv64/rva23u64:-`SEQZ`, -`CZEROEQZ`, -`OR` - return result -} - -//go:noinline -func testCondAddNonZero(cond, a, b int) int { - var result int - if cond != 0 { - result = a + b - } else { - result = a - } - // riscv64/rva23u64:`CZEROEQZ`, `ADD` - // riscv64/rva23u64:-`SNEZ`, -`CZERONEZ`, -`OR` - return result -} - -//go:noinline -func testCondSubZero(cond, a, b int) int { - var result int - if cond == 0 { - result = a - b - } else { - result = a - } - // riscv64/rva23u64:`CZERONEZ`, `SUB` - // riscv64/rva23u64:-`SEQZ`, -`CZEROEQZ`, -`OR` - return result -} - -//go:noinline -func testCondSubNonZero(cond, a, b int) int { - var result int - if cond != 0 { - result = a - b - } else { - result = a - } - // riscv64/rva23u64:`CZEROEQZ`, `SUB` - // riscv64/rva23u64:-`SNEZ`, -`CZERONEZ`, -`OR` - return result -} - -//go:noinline -func testCondOrZero(cond, a, b int) int { - var result int - if cond == 0 { - result = a | b - } else { - result = a - } - // riscv64/rva23u64:`CZERONEZ`, `OR` - // riscv64/rva23u64:-`SEQZ`, -`CZEROEQZ` - return result -} - -//go:noinline -func testCondOrNonZero(cond, a, b int) int { - var result int - if cond != 0 { - result = a | b - } else { - result = a - } - // riscv64/rva23u64:`CZEROEQZ`, `OR` - // riscv64/rva23u64:-`SNEZ`, -`CZERONEZ` - return result -} - -//go:noinline -func testCondXorZero(cond, a, b int) int { - var result int - if cond == 0 { - result = a ^ b - } else { - result = a - } - // riscv64/rva23u64:`CZERONEZ`, `XOR` - // riscv64/rva23u64:-`SEQZ`, -`CZEROEQZ`, -`OR` - return result -} - -//go:noinline -func testCondXorNonZero(cond, a, b int) int { - var result int - if cond != 0 { - result = a ^ b - } else { - result = a - } - // riscv64/rva23u64:`CZEROEQZ`, `XOR` - // riscv64/rva23u64:-`SNEZ`, -`CZERONEZ`, -`OR` - return result -} - -//go:noinline -func testCondAndZero(cond, a, b int) int { - var result int - if cond == 0 { - result = a & b - } else { - result = a - } - // riscv64/rva23u64:`CZEROEQZ`, `AND`, `OR` - // riscv64/rva23u64:-`SEQZ`, -`CZERONEZ` - return result -} - -//go:noinline -func testCondAndNonZero(cond, a, b int) int { - var result int - if cond != 0 { - result = a & b - } else { - result = a - } - // riscv64/rva23u64:`CZERONEZ`, `AND`, `OR` - // riscv64/rva23u64:-`SNEZ`, -`CZEROEQZ` - return result -} From 570295c6b79d17342625f95cd2c6f9377fa1ffb7 Mon Sep 17 00:00:00 2001 From: Xueqi Luo <1824368278@qq.com> Date: Mon, 20 Oct 2025 20:23:07 +0800 Subject: [PATCH 4/8] change rules form1 --- .../compile/internal/ssa/_gen/RISCV64.rules | 5 + .../internal/ssa/_gen/RISCV64latelower.rules | 56 +- .../compile/internal/ssa/rewriteRISCV64.go | 28 + .../internal/ssa/rewriteRISCV64latelower.go | 732 ++++++++++-------- 4 files changed, 479 insertions(+), 342 deletions(-) diff --git a/src/cmd/compile/internal/ssa/_gen/RISCV64.rules b/src/cmd/compile/internal/ssa/_gen/RISCV64.rules index 7059273eb2fd4c..8a4f0012a5ae8f 100644 --- a/src/cmd/compile/internal/ssa/_gen/RISCV64.rules +++ b/src/cmd/compile/internal/ssa/_gen/RISCV64.rules @@ -849,3 +849,8 @@ (Max64 x y) && buildcfg.GORISCV64 >= 22 => (MAX x y) (Min64u x y) && buildcfg.GORISCV64 >= 22 => (MINU x y) (Max64u x y) && buildcfg.GORISCV64 >= 22 => (MAXU x y) + +// Zicond Extension for Integer Conditional Operations + +// General lowering rule: always lower CondSelect to OR(CZEROEQZ, CZERONEZ) form +(CondSelect x y cond) && buildcfg.GORISCV64 >= 23 => (OR (CZEROEQZ x cond) (CZERONEZ y cond)) diff --git a/src/cmd/compile/internal/ssa/_gen/RISCV64latelower.rules b/src/cmd/compile/internal/ssa/_gen/RISCV64latelower.rules index 2f9b8808920fe7..0b1fdd3ccbae11 100644 --- a/src/cmd/compile/internal/ssa/_gen/RISCV64latelower.rules +++ b/src/cmd/compile/internal/ssa/_gen/RISCV64latelower.rules @@ -25,31 +25,31 @@ (SLLI [0] x) => x // "Zicond" Extension for Integer Conditional Operations -// (x == 0) ? x : y -(CondSelect x y (SEQZ x)) && buildcfg.GORISCV64 >= 23 => (CZEROEQZ y x) -// (z == 0) ? (x + y) : y -(CondSelect (ADD x y) x (SEQZ z)) && buildcfg.GORISCV64 >= 23 => (ADD x (CZERONEZ y z)) -// (z != 0) ? (x + y) : y -(CondSelect (ADD x y) x (SNEZ z)) && buildcfg.GORISCV64 >= 23 => (ADD x (CZEROEQZ y z)) -// (z == 0) ? (x - y) : y -(CondSelect (SUB x y) x (SEQZ z)) && buildcfg.GORISCV64 >= 23 => (SUB x (CZERONEZ y z)) -// (z != 0) ? (x - y) : y -(CondSelect (SUB x y) x (SNEZ z)) && buildcfg.GORISCV64 >= 23 => (SUB x (CZEROEQZ y z)) -// (z == 0) ? (x | y) : y -(CondSelect (OR x y) x (SEQZ z)) && buildcfg.GORISCV64 >= 23 => (OR x (CZERONEZ y z)) -// (z != 0) ? (x | y) : y -(CondSelect (OR x y) x (SNEZ z)) && buildcfg.GORISCV64 >= 23 => (OR x (CZEROEQZ y z)) -// (z == 0) ? (x ^ y) : y -(CondSelect (XOR x y) x (SEQZ z)) && buildcfg.GORISCV64 >= 23 => (XOR x (CZERONEZ y z)) -// (z != 0) ? (x ^ y) : y -(CondSelect (XOR x y) x (SNEZ z)) && buildcfg.GORISCV64 >= 23 => (XOR x (CZEROEQZ y z)) -// (z == 0) ? (x & y) : y -(CondSelect (AND x y) x (SEQZ z)) && buildcfg.GORISCV64 >= 23 => (OR (AND x y) (CZEROEQZ x z)) -// (z != 0) ? (x & y) : y -(CondSelect (AND x y) x (SNEZ z)) && buildcfg.GORISCV64 >= 23 => (OR (AND x y) (CZERONEZ x z)) -// (z == 0) ? x : y -(CondSelect x y (SEQZ z)) && buildcfg.GORISCV64 >= 23 => (OR (CZERONEZ x z) (CZEROEQZ y z)) -// (z != 0) ? x : y -(CondSelect x y (SNEZ z)) && buildcfg.GORISCV64 >= 23 => (OR (CZEROEQZ x z) (CZERONEZ y z)) -// Make sure we can rewrite all CondSelects. -(CondSelect x y cond) && buildcfg.GORISCV64 >= 23 => (OR (CZEROEQZ x cond) (CZERONEZ y cond)) +// Optimize specific patterns based on the unified OR(CZEROEQZ, CZERONEZ) form +// (x == 0) ? x : y -> CZEROEQZ y x (when x is the condition) +(OR (CZEROEQZ x (SEQZ x)) (CZERONEZ y (SEQZ x))) && buildcfg.GORISCV64 >= 23 => (CZEROEQZ y x) + +// (z == 0) ? (x + y) : x -> ADD x (CZERONEZ y z) +(OR (CZEROEQZ (ADD x y) (SEQZ z)) (CZERONEZ x (SEQZ z))) && buildcfg.GORISCV64 >= 23 => (ADD x (CZERONEZ y z)) +// (z != 0) ? (x + y) : x -> ADD x (CZEROEQZ y z) +(OR (CZEROEQZ (ADD x y) (SNEZ z)) (CZERONEZ x (SNEZ z))) && buildcfg.GORISCV64 >= 23 => (ADD x (CZEROEQZ y z)) + +// (z == 0) ? (x - y) : x -> SUB x (CZERONEZ y z) +(OR (CZEROEQZ (SUB x y) (SEQZ z)) (CZERONEZ x (SEQZ z))) && buildcfg.GORISCV64 >= 23 => (SUB x (CZERONEZ y z)) +// (z != 0) ? (x - y) : x -> SUB x (CZEROEQZ y z) +(OR (CZEROEQZ (SUB x y) (SNEZ z)) (CZERONEZ x (SNEZ z))) && buildcfg.GORISCV64 >= 23 => (SUB x (CZEROEQZ y z)) + +// (z == 0) ? (x | y) : x -> OR x (CZERONEZ y z) +(OR (CZEROEQZ (OR x y) (SEQZ z)) (CZERONEZ x (SEQZ z))) && buildcfg.GORISCV64 >= 23 => (OR x (CZERONEZ y z)) +// (z != 0) ? (x | y) : x -> OR x (CZEROEQZ y z) +(OR (CZEROEQZ (OR x y) (SNEZ z)) (CZERONEZ x (SNEZ z))) && buildcfg.GORISCV64 >= 23 => (OR x (CZEROEQZ y z)) + +// (z == 0) ? (x ^ y) : x -> XOR x (CZERONEZ y z) +(OR (CZEROEQZ (XOR x y) (SEQZ z)) (CZERONEZ x (SEQZ z))) && buildcfg.GORISCV64 >= 23 => (XOR x (CZERONEZ y z)) +// (z != 0) ? (x ^ y) : x -> XOR x (CZEROEQZ y z) +(OR (CZEROEQZ (XOR x y) (SNEZ z)) (CZERONEZ x (SNEZ z))) && buildcfg.GORISCV64 >= 23 => (XOR x (CZEROEQZ y z)) + +// (z == 0) ? (x & y) : x -> OR (AND x y) (CZEROEQZ x z) +(OR (CZEROEQZ (AND x y) (SEQZ z)) (CZERONEZ x (SEQZ z))) && buildcfg.GORISCV64 >= 23 => (OR (AND x y) (CZEROEQZ x z)) +// (z != 0) ? (x & y) : x -> OR (AND x y) (CZERONEZ x z) +(OR (CZEROEQZ (AND x y) (SNEZ z)) (CZERONEZ x (SNEZ z))) && buildcfg.GORISCV64 >= 23 => (OR (AND x y) (CZERONEZ x z)) diff --git a/src/cmd/compile/internal/ssa/rewriteRISCV64.go b/src/cmd/compile/internal/ssa/rewriteRISCV64.go index a7b4cf1bc402d1..ca0874a97c2b3c 100644 --- a/src/cmd/compile/internal/ssa/rewriteRISCV64.go +++ b/src/cmd/compile/internal/ssa/rewriteRISCV64.go @@ -132,6 +132,8 @@ func rewriteValueRISCV64(v *Value) bool { case OpCom8: v.Op = OpRISCV64NOT return true + case OpCondSelect: + return rewriteValueRISCV64_OpCondSelect(v) case OpConst16: return rewriteValueRISCV64_OpConst16(v) case OpConst32: @@ -1078,6 +1080,32 @@ func rewriteValueRISCV64_OpBswap32(v *Value) bool { return true } } +func rewriteValueRISCV64_OpCondSelect(v *Value) bool { + v_2 := v.Args[2] + v_1 := v.Args[1] + v_0 := v.Args[0] + b := v.Block + // match: (CondSelect x y cond) + // cond: buildcfg.GORISCV64 >= 23 + // result: (OR (CZEROEQZ x cond) (CZERONEZ y cond)) + for { + t := v.Type + x := v_0 + y := v_1 + cond := v_2 + if !(buildcfg.GORISCV64 >= 23) { + break + } + v.reset(OpRISCV64OR) + v0 := b.NewValue0(v.Pos, OpRISCV64CZEROEQZ, t) + v0.AddArg2(x, cond) + v1 := b.NewValue0(v.Pos, OpRISCV64CZERONEZ, t) + v1.AddArg2(y, cond) + v.AddArg2(v0, v1) + return true + } + return false +} func rewriteValueRISCV64_OpConst16(v *Value) bool { // match: (Const16 [val]) // result: (MOVDconst [int64(val)]) diff --git a/src/cmd/compile/internal/ssa/rewriteRISCV64latelower.go b/src/cmd/compile/internal/ssa/rewriteRISCV64latelower.go index e7336e4d489b2e..07710c6e84e365 100644 --- a/src/cmd/compile/internal/ssa/rewriteRISCV64latelower.go +++ b/src/cmd/compile/internal/ssa/rewriteRISCV64latelower.go @@ -6,8 +6,6 @@ import "internal/buildcfg" func rewriteValueRISCV64latelower(v *Value) bool { switch v.Op { - case OpCondSelect: - return rewriteValueRISCV64latelower_OpCondSelect(v) case OpRISCV64AND: return rewriteValueRISCV64latelower_OpRISCV64AND(v) case OpRISCV64NOT: @@ -25,210 +23,212 @@ func rewriteValueRISCV64latelower(v *Value) bool { } return false } -func rewriteValueRISCV64latelower_OpCondSelect(v *Value) bool { - v_2 := v.Args[2] +func rewriteValueRISCV64latelower_OpRISCV64AND(v *Value) bool { v_1 := v.Args[1] v_0 := v.Args[0] - b := v.Block - // match: (CondSelect x y (SEQZ x)) - // cond: buildcfg.GORISCV64 >= 23 - // result: (CZEROEQZ y x) + // match: (AND x (NOT y)) + // result: (ANDN x y) for { - t := v.Type - x := v_0 - y := v_1 - if v_2.Op != OpRISCV64SEQZ || x != v_2.Args[0] || !(buildcfg.GORISCV64 >= 23) { - break + for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { + x := v_0 + if v_1.Op != OpRISCV64NOT { + continue + } + y := v_1.Args[0] + v.reset(OpRISCV64ANDN) + v.AddArg2(x, y) + return true } - v.reset(OpRISCV64CZEROEQZ) - v.Type = t - v.AddArg2(y, x) - return true + break } - // match: (CondSelect (ADD x y) x (SEQZ z)) - // cond: buildcfg.GORISCV64 >= 23 - // result: (ADD x (CZERONEZ y z)) + return false +} +func rewriteValueRISCV64latelower_OpRISCV64NOT(v *Value) bool { + v_0 := v.Args[0] + // match: (NOT (XOR x y)) + // result: (XNOR x y) for { - t := v.Type - if v_0.Op != OpRISCV64ADD { + if v_0.Op != OpRISCV64XOR { break } - _ = 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 - if x != v_1 || v_2.Op != OpRISCV64SEQZ { - continue - } - z := v_2.Args[0] - if !(buildcfg.GORISCV64 >= 23) { + y := v_0.Args[1] + x := v_0.Args[0] + v.reset(OpRISCV64XNOR) + v.AddArg2(x, y) + return true + } + return false +} +func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { + v_1 := v.Args[1] + v_0 := v.Args[0] + b := v.Block + // match: (OR x (NOT y)) + // result: (ORN x y) + for { + for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { + x := v_0 + if v_1.Op != OpRISCV64NOT { continue } - v.reset(OpRISCV64ADD) - v0 := b.NewValue0(v.Pos, OpRISCV64CZERONEZ, t) - v0.AddArg2(y, z) - v.AddArg2(x, v0) + y := v_1.Args[0] + v.reset(OpRISCV64ORN) + v.AddArg2(x, y) return true } break } - // match: (CondSelect (ADD x y) x (SNEZ z)) + // match: (OR (CZEROEQZ x (SEQZ x)) (CZERONEZ y (SEQZ x))) // cond: buildcfg.GORISCV64 >= 23 - // result: (ADD x (CZEROEQZ y z)) + // result: (CZEROEQZ y x) for { - t := v.Type - if v_0.Op != OpRISCV64ADD { - break - } - _ = 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 - if x != v_1 || v_2.Op != OpRISCV64SNEZ { + for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { + if v_0.Op != OpRISCV64CZEROEQZ { continue } - z := v_2.Args[0] - if !(buildcfg.GORISCV64 >= 23) { + t := v_0.Type + _ = v_0.Args[1] + x := v_0.Args[0] + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpRISCV64SEQZ || x != v_0_1.Args[0] || v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { continue } - v.reset(OpRISCV64ADD) - v0 := b.NewValue0(v.Pos, OpRISCV64CZEROEQZ, t) - v0.AddArg2(y, z) - v.AddArg2(x, v0) + _ = v_1.Args[1] + y := v_1.Args[0] + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpRISCV64SEQZ || x != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + continue + } + v.reset(OpRISCV64CZEROEQZ) + v.Type = t + v.AddArg2(y, x) return true } break } - // match: (CondSelect (SUB x y) x (SEQZ z)) - // cond: buildcfg.GORISCV64 >= 23 - // result: (SUB x (CZERONEZ y z)) - for { - t := v.Type - if v_0.Op != OpRISCV64SUB { - break - } - y := v_0.Args[1] - x := v_0.Args[0] - if x != v_1 || v_2.Op != OpRISCV64SEQZ { - break - } - z := v_2.Args[0] - if !(buildcfg.GORISCV64 >= 23) { - break - } - v.reset(OpRISCV64SUB) - v0 := b.NewValue0(v.Pos, OpRISCV64CZERONEZ, t) - v0.AddArg2(y, z) - v.AddArg2(x, v0) - return true - } - // match: (CondSelect (SUB x y) x (SNEZ z)) + // match: (OR (CZEROEQZ (ADD x y) (SEQZ z)) (CZERONEZ x (SEQZ z))) // cond: buildcfg.GORISCV64 >= 23 - // result: (SUB x (CZEROEQZ y z)) - for { - t := v.Type - if v_0.Op != OpRISCV64SUB { - break - } - y := v_0.Args[1] - x := v_0.Args[0] - if x != v_1 || v_2.Op != OpRISCV64SNEZ { - break - } - z := v_2.Args[0] - if !(buildcfg.GORISCV64 >= 23) { - break - } - v.reset(OpRISCV64SUB) - v0 := b.NewValue0(v.Pos, OpRISCV64CZEROEQZ, t) - v0.AddArg2(y, z) - v.AddArg2(x, v0) - return true - } - // match: (CondSelect (OR x y) x (SEQZ z)) - // cond: buildcfg.GORISCV64 >= 23 - // result: (OR x (CZERONEZ y z)) + // result: (ADD x (CZERONEZ y z)) for { - t := v.Type - if v_0.Op != OpRISCV64OR { - break - } - _ = 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 - if x != v_1 || v_2.Op != OpRISCV64SEQZ { + for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { + if v_0.Op != OpRISCV64CZEROEQZ { continue } - z := v_2.Args[0] - if !(buildcfg.GORISCV64 >= 23) { + t := v_0.Type + _ = v_0.Args[1] + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpRISCV64ADD { continue } - v.reset(OpRISCV64OR) - v0 := b.NewValue0(v.Pos, OpRISCV64CZERONEZ, t) - v0.AddArg2(y, z) - v.AddArg2(x, v0) - return true + _ = v_0_0.Args[1] + v_0_0_0 := v_0_0.Args[0] + v_0_0_1 := v_0_0.Args[1] + for _i1 := 0; _i1 <= 1; _i1, v_0_0_0, v_0_0_1 = _i1+1, v_0_0_1, v_0_0_0 { + x := v_0_0_0 + y := v_0_0_1 + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpRISCV64SEQZ { + continue + } + z := v_0_1.Args[0] + if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { + continue + } + _ = v_1.Args[1] + if x != v_1.Args[0] { + continue + } + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpRISCV64SEQZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + continue + } + v.reset(OpRISCV64ADD) + v0 := b.NewValue0(v.Pos, OpRISCV64CZERONEZ, t) + v0.AddArg2(y, z) + v.AddArg2(x, v0) + return true + } } break } - // match: (CondSelect (OR x y) x (SNEZ z)) + // match: (OR (CZEROEQZ (ADD x y) (SNEZ z)) (CZERONEZ x (SNEZ z))) // cond: buildcfg.GORISCV64 >= 23 - // result: (OR x (CZEROEQZ y z)) + // result: (ADD x (CZEROEQZ y z)) for { - t := v.Type - if v_0.Op != OpRISCV64OR { - break - } - _ = 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 - if x != v_1 || v_2.Op != OpRISCV64SNEZ { + for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { + if v_0.Op != OpRISCV64CZEROEQZ { continue } - z := v_2.Args[0] - if !(buildcfg.GORISCV64 >= 23) { + t := v_0.Type + _ = v_0.Args[1] + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpRISCV64ADD { continue } - v.reset(OpRISCV64OR) - v0 := b.NewValue0(v.Pos, OpRISCV64CZEROEQZ, t) - v0.AddArg2(y, z) - v.AddArg2(x, v0) - return true + _ = v_0_0.Args[1] + v_0_0_0 := v_0_0.Args[0] + v_0_0_1 := v_0_0.Args[1] + for _i1 := 0; _i1 <= 1; _i1, v_0_0_0, v_0_0_1 = _i1+1, v_0_0_1, v_0_0_0 { + x := v_0_0_0 + y := v_0_0_1 + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpRISCV64SNEZ { + continue + } + z := v_0_1.Args[0] + if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { + continue + } + _ = v_1.Args[1] + if x != v_1.Args[0] { + continue + } + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpRISCV64SNEZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + continue + } + v.reset(OpRISCV64ADD) + v0 := b.NewValue0(v.Pos, OpRISCV64CZEROEQZ, t) + v0.AddArg2(y, z) + v.AddArg2(x, v0) + return true + } } break } - // match: (CondSelect (XOR x y) x (SEQZ z)) + // match: (OR (CZEROEQZ (SUB x y) (SEQZ z)) (CZERONEZ x (SEQZ z))) // cond: buildcfg.GORISCV64 >= 23 - // result: (XOR x (CZERONEZ y z)) + // result: (SUB x (CZERONEZ y z)) for { - t := v.Type - if v_0.Op != OpRISCV64XOR { - break - } - _ = 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 - if x != v_1 || v_2.Op != OpRISCV64SEQZ { + for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { + if v_0.Op != OpRISCV64CZEROEQZ { + continue + } + t := v_0.Type + _ = v_0.Args[1] + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpRISCV64SUB { + continue + } + y := v_0_0.Args[1] + x := v_0_0.Args[0] + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpRISCV64SEQZ { + continue + } + z := v_0_1.Args[0] + if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { + continue + } + _ = v_1.Args[1] + if x != v_1.Args[0] { continue } - z := v_2.Args[0] - if !(buildcfg.GORISCV64 >= 23) { + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpRISCV64SEQZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { continue } - v.reset(OpRISCV64XOR) + v.reset(OpRISCV64SUB) v0 := b.NewValue0(v.Pos, OpRISCV64CZERONEZ, t) v0.AddArg2(y, z) v.AddArg2(x, v0) @@ -236,28 +236,39 @@ func rewriteValueRISCV64latelower_OpCondSelect(v *Value) bool { } break } - // match: (CondSelect (XOR x y) x (SNEZ z)) + // match: (OR (CZEROEQZ (SUB x y) (SNEZ z)) (CZERONEZ x (SNEZ z))) // cond: buildcfg.GORISCV64 >= 23 - // result: (XOR x (CZEROEQZ y z)) + // result: (SUB x (CZEROEQZ y z)) for { - t := v.Type - if v_0.Op != OpRISCV64XOR { - break - } - _ = 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 - if x != v_1 || v_2.Op != OpRISCV64SNEZ { + for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { + if v_0.Op != OpRISCV64CZEROEQZ { + continue + } + t := v_0.Type + _ = v_0.Args[1] + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpRISCV64SUB { continue } - z := v_2.Args[0] - if !(buildcfg.GORISCV64 >= 23) { + y := v_0_0.Args[1] + x := v_0_0.Args[0] + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpRISCV64SNEZ { continue } - v.reset(OpRISCV64XOR) + z := v_0_1.Args[0] + if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { + continue + } + _ = v_1.Args[1] + if x != v_1.Args[0] { + continue + } + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpRISCV64SNEZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + continue + } + v.reset(OpRISCV64SUB) v0 := b.NewValue0(v.Pos, OpRISCV64CZEROEQZ, t) v0.AddArg2(y, z) v.AddArg2(x, v0) @@ -265,184 +276,277 @@ func rewriteValueRISCV64latelower_OpCondSelect(v *Value) bool { } break } - // match: (CondSelect (AND x y) x (SEQZ z)) + // match: (OR (CZEROEQZ (OR x y) (SEQZ z)) (CZERONEZ x (SEQZ z))) // cond: buildcfg.GORISCV64 >= 23 - // result: (OR (AND x y) (CZEROEQZ x z)) + // result: (OR x (CZERONEZ y z)) for { - t := v.Type - if v_0.Op != OpRISCV64AND { - break - } - _ = 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 - if x != v_1 || v_2.Op != OpRISCV64SEQZ { + for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { + if v_0.Op != OpRISCV64CZEROEQZ { continue } - z := v_2.Args[0] - if !(buildcfg.GORISCV64 >= 23) { + t := v_0.Type + _ = v_0.Args[1] + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpRISCV64OR { continue } - v.reset(OpRISCV64OR) - v0 := b.NewValue0(v.Pos, OpRISCV64AND, t) - v0.AddArg2(x, y) - v1 := b.NewValue0(v.Pos, OpRISCV64CZEROEQZ, t) - v1.AddArg2(x, z) - v.AddArg2(v0, v1) - return true + _ = v_0_0.Args[1] + v_0_0_0 := v_0_0.Args[0] + v_0_0_1 := v_0_0.Args[1] + for _i1 := 0; _i1 <= 1; _i1, v_0_0_0, v_0_0_1 = _i1+1, v_0_0_1, v_0_0_0 { + x := v_0_0_0 + y := v_0_0_1 + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpRISCV64SEQZ { + continue + } + z := v_0_1.Args[0] + if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { + continue + } + _ = v_1.Args[1] + if x != v_1.Args[0] { + continue + } + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpRISCV64SEQZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + continue + } + v.reset(OpRISCV64OR) + v0 := b.NewValue0(v.Pos, OpRISCV64CZERONEZ, t) + v0.AddArg2(y, z) + v.AddArg2(x, v0) + return true + } } break } - // match: (CondSelect (AND x y) x (SNEZ z)) + // match: (OR (CZEROEQZ (OR x y) (SNEZ z)) (CZERONEZ x (SNEZ z))) // cond: buildcfg.GORISCV64 >= 23 - // result: (OR (AND x y) (CZERONEZ x z)) + // result: (OR x (CZEROEQZ y z)) for { - t := v.Type - if v_0.Op != OpRISCV64AND { - break - } - _ = 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 - if x != v_1 || v_2.Op != OpRISCV64SNEZ { + for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { + if v_0.Op != OpRISCV64CZEROEQZ { continue } - z := v_2.Args[0] - if !(buildcfg.GORISCV64 >= 23) { + t := v_0.Type + _ = v_0.Args[1] + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpRISCV64OR { continue } - v.reset(OpRISCV64OR) - v0 := b.NewValue0(v.Pos, OpRISCV64AND, t) - v0.AddArg2(x, y) - v1 := b.NewValue0(v.Pos, OpRISCV64CZERONEZ, t) - v1.AddArg2(x, z) - v.AddArg2(v0, v1) - return true + _ = v_0_0.Args[1] + v_0_0_0 := v_0_0.Args[0] + v_0_0_1 := v_0_0.Args[1] + for _i1 := 0; _i1 <= 1; _i1, v_0_0_0, v_0_0_1 = _i1+1, v_0_0_1, v_0_0_0 { + x := v_0_0_0 + y := v_0_0_1 + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpRISCV64SNEZ { + continue + } + z := v_0_1.Args[0] + if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { + continue + } + _ = v_1.Args[1] + if x != v_1.Args[0] { + continue + } + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpRISCV64SNEZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + continue + } + v.reset(OpRISCV64OR) + v0 := b.NewValue0(v.Pos, OpRISCV64CZEROEQZ, t) + v0.AddArg2(y, z) + v.AddArg2(x, v0) + return true + } } break } - // match: (CondSelect x y (SEQZ z)) + // match: (OR (CZEROEQZ (XOR x y) (SEQZ z)) (CZERONEZ x (SEQZ z))) // cond: buildcfg.GORISCV64 >= 23 - // result: (OR (CZERONEZ x z) (CZEROEQZ y z)) + // result: (XOR x (CZERONEZ y z)) for { - t := v.Type - x := v_0 - y := v_1 - if v_2.Op != OpRISCV64SEQZ { - break - } - z := v_2.Args[0] - if !(buildcfg.GORISCV64 >= 23) { - break + for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { + if v_0.Op != OpRISCV64CZEROEQZ { + continue + } + t := v_0.Type + _ = v_0.Args[1] + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpRISCV64XOR { + continue + } + _ = v_0_0.Args[1] + v_0_0_0 := v_0_0.Args[0] + v_0_0_1 := v_0_0.Args[1] + for _i1 := 0; _i1 <= 1; _i1, v_0_0_0, v_0_0_1 = _i1+1, v_0_0_1, v_0_0_0 { + x := v_0_0_0 + y := v_0_0_1 + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpRISCV64SEQZ { + continue + } + z := v_0_1.Args[0] + if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { + continue + } + _ = v_1.Args[1] + if x != v_1.Args[0] { + continue + } + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpRISCV64SEQZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + continue + } + v.reset(OpRISCV64XOR) + v0 := b.NewValue0(v.Pos, OpRISCV64CZERONEZ, t) + v0.AddArg2(y, z) + v.AddArg2(x, v0) + return true + } } - v.reset(OpRISCV64OR) - v0 := b.NewValue0(v.Pos, OpRISCV64CZERONEZ, t) - v0.AddArg2(x, z) - v1 := b.NewValue0(v.Pos, OpRISCV64CZEROEQZ, t) - v1.AddArg2(y, z) - v.AddArg2(v0, v1) - return true + break } - // match: (CondSelect x y (SNEZ z)) + // match: (OR (CZEROEQZ (XOR x y) (SNEZ z)) (CZERONEZ x (SNEZ z))) // cond: buildcfg.GORISCV64 >= 23 - // result: (OR (CZEROEQZ x z) (CZERONEZ y z)) + // result: (XOR x (CZEROEQZ y z)) for { - t := v.Type - x := v_0 - y := v_1 - if v_2.Op != OpRISCV64SNEZ { - break - } - z := v_2.Args[0] - if !(buildcfg.GORISCV64 >= 23) { - break + for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { + if v_0.Op != OpRISCV64CZEROEQZ { + continue + } + t := v_0.Type + _ = v_0.Args[1] + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpRISCV64XOR { + continue + } + _ = v_0_0.Args[1] + v_0_0_0 := v_0_0.Args[0] + v_0_0_1 := v_0_0.Args[1] + for _i1 := 0; _i1 <= 1; _i1, v_0_0_0, v_0_0_1 = _i1+1, v_0_0_1, v_0_0_0 { + x := v_0_0_0 + y := v_0_0_1 + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpRISCV64SNEZ { + continue + } + z := v_0_1.Args[0] + if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { + continue + } + _ = v_1.Args[1] + if x != v_1.Args[0] { + continue + } + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpRISCV64SNEZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + continue + } + v.reset(OpRISCV64XOR) + v0 := b.NewValue0(v.Pos, OpRISCV64CZEROEQZ, t) + v0.AddArg2(y, z) + v.AddArg2(x, v0) + return true + } } - v.reset(OpRISCV64OR) - v0 := b.NewValue0(v.Pos, OpRISCV64CZEROEQZ, t) - v0.AddArg2(x, z) - v1 := b.NewValue0(v.Pos, OpRISCV64CZERONEZ, t) - v1.AddArg2(y, z) - v.AddArg2(v0, v1) - return true + break } - // match: (CondSelect x y cond) + // match: (OR (CZEROEQZ (AND x y) (SEQZ z)) (CZERONEZ x (SEQZ z))) // cond: buildcfg.GORISCV64 >= 23 - // result: (OR (CZEROEQZ x cond) (CZERONEZ y cond)) - for { - t := v.Type - x := v_0 - y := v_1 - cond := v_2 - if !(buildcfg.GORISCV64 >= 23) { - break - } - v.reset(OpRISCV64OR) - v0 := b.NewValue0(v.Pos, OpRISCV64CZEROEQZ, t) - v0.AddArg2(x, cond) - v1 := b.NewValue0(v.Pos, OpRISCV64CZERONEZ, t) - v1.AddArg2(y, cond) - v.AddArg2(v0, v1) - return true - } - return false -} -func rewriteValueRISCV64latelower_OpRISCV64AND(v *Value) bool { - v_1 := v.Args[1] - v_0 := v.Args[0] - // match: (AND x (NOT y)) - // result: (ANDN x y) + // result: (OR (AND x y) (CZEROEQZ x z)) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { - x := v_0 - if v_1.Op != OpRISCV64NOT { + if v_0.Op != OpRISCV64CZEROEQZ { continue } - y := v_1.Args[0] - v.reset(OpRISCV64ANDN) - v.AddArg2(x, y) - return true + t := v_0.Type + _ = v_0.Args[1] + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpRISCV64AND { + continue + } + _ = v_0_0.Args[1] + v_0_0_0 := v_0_0.Args[0] + v_0_0_1 := v_0_0.Args[1] + for _i1 := 0; _i1 <= 1; _i1, v_0_0_0, v_0_0_1 = _i1+1, v_0_0_1, v_0_0_0 { + x := v_0_0_0 + y := v_0_0_1 + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpRISCV64SEQZ { + continue + } + z := v_0_1.Args[0] + if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { + continue + } + _ = v_1.Args[1] + if x != v_1.Args[0] { + continue + } + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpRISCV64SEQZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + continue + } + v.reset(OpRISCV64OR) + v0 := b.NewValue0(v.Pos, OpRISCV64AND, t) + v0.AddArg2(x, y) + v1 := b.NewValue0(v.Pos, OpRISCV64CZEROEQZ, t) + v1.AddArg2(x, z) + v.AddArg2(v0, v1) + return true + } } break } - return false -} -func rewriteValueRISCV64latelower_OpRISCV64NOT(v *Value) bool { - v_0 := v.Args[0] - // match: (NOT (XOR x y)) - // result: (XNOR x y) - for { - if v_0.Op != OpRISCV64XOR { - break - } - y := v_0.Args[1] - x := v_0.Args[0] - v.reset(OpRISCV64XNOR) - v.AddArg2(x, y) - return true - } - return false -} -func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { - v_1 := v.Args[1] - v_0 := v.Args[0] - // match: (OR x (NOT y)) - // result: (ORN x y) + // match: (OR (CZEROEQZ (AND x y) (SNEZ z)) (CZERONEZ x (SNEZ z))) + // cond: buildcfg.GORISCV64 >= 23 + // result: (OR (AND x y) (CZERONEZ x z)) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { - x := v_0 - if v_1.Op != OpRISCV64NOT { + if v_0.Op != OpRISCV64CZEROEQZ { continue } - y := v_1.Args[0] - v.reset(OpRISCV64ORN) - v.AddArg2(x, y) - return true + t := v_0.Type + _ = v_0.Args[1] + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpRISCV64AND { + continue + } + _ = v_0_0.Args[1] + v_0_0_0 := v_0_0.Args[0] + v_0_0_1 := v_0_0.Args[1] + for _i1 := 0; _i1 <= 1; _i1, v_0_0_0, v_0_0_1 = _i1+1, v_0_0_1, v_0_0_0 { + x := v_0_0_0 + y := v_0_0_1 + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpRISCV64SNEZ { + continue + } + z := v_0_1.Args[0] + if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { + continue + } + _ = v_1.Args[1] + if x != v_1.Args[0] { + continue + } + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpRISCV64SNEZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + continue + } + v.reset(OpRISCV64OR) + v0 := b.NewValue0(v.Pos, OpRISCV64AND, t) + v0.AddArg2(x, y) + v1 := b.NewValue0(v.Pos, OpRISCV64CZERONEZ, t) + v1.AddArg2(x, z) + v.AddArg2(v0, v1) + return true + } } break } From 7f39dd03706afc62381c14810639132cdfffb122 Mon Sep 17 00:00:00 2001 From: Xueqi Luo <1824368278@qq.com> Date: Tue, 21 Oct 2025 15:29:31 +0800 Subject: [PATCH 5/8] change rules form2 --- .../internal/ssa/_gen/RISCV64latelower.rules | 74 +- .../internal/ssa/rewriteRISCV64latelower.go | 787 ++++++++++++++++-- test/codegen/condmove.go | 106 +-- 3 files changed, 795 insertions(+), 172 deletions(-) diff --git a/src/cmd/compile/internal/ssa/_gen/RISCV64latelower.rules b/src/cmd/compile/internal/ssa/_gen/RISCV64latelower.rules index 0b1fdd3ccbae11..0b0ff5223f9b67 100644 --- a/src/cmd/compile/internal/ssa/_gen/RISCV64latelower.rules +++ b/src/cmd/compile/internal/ssa/_gen/RISCV64latelower.rules @@ -29,27 +29,53 @@ // (x == 0) ? x : y -> CZEROEQZ y x (when x is the condition) (OR (CZEROEQZ x (SEQZ x)) (CZERONEZ y (SEQZ x))) && buildcfg.GORISCV64 >= 23 => (CZEROEQZ y x) -// (z == 0) ? (x + y) : x -> ADD x (CZERONEZ y z) -(OR (CZEROEQZ (ADD x y) (SEQZ z)) (CZERONEZ x (SEQZ z))) && buildcfg.GORISCV64 >= 23 => (ADD x (CZERONEZ y z)) -// (z != 0) ? (x + y) : x -> ADD x (CZEROEQZ y z) -(OR (CZEROEQZ (ADD x y) (SNEZ z)) (CZERONEZ x (SNEZ z))) && buildcfg.GORISCV64 >= 23 => (ADD x (CZEROEQZ y z)) - -// (z == 0) ? (x - y) : x -> SUB x (CZERONEZ y z) -(OR (CZEROEQZ (SUB x y) (SEQZ z)) (CZERONEZ x (SEQZ z))) && buildcfg.GORISCV64 >= 23 => (SUB x (CZERONEZ y z)) -// (z != 0) ? (x - y) : x -> SUB x (CZEROEQZ y z) -(OR (CZEROEQZ (SUB x y) (SNEZ z)) (CZERONEZ x (SNEZ z))) && buildcfg.GORISCV64 >= 23 => (SUB x (CZEROEQZ y z)) - -// (z == 0) ? (x | y) : x -> OR x (CZERONEZ y z) -(OR (CZEROEQZ (OR x y) (SEQZ z)) (CZERONEZ x (SEQZ z))) && buildcfg.GORISCV64 >= 23 => (OR x (CZERONEZ y z)) -// (z != 0) ? (x | y) : x -> OR x (CZEROEQZ y z) -(OR (CZEROEQZ (OR x y) (SNEZ z)) (CZERONEZ x (SNEZ z))) && buildcfg.GORISCV64 >= 23 => (OR x (CZEROEQZ y z)) - -// (z == 0) ? (x ^ y) : x -> XOR x (CZERONEZ y z) -(OR (CZEROEQZ (XOR x y) (SEQZ z)) (CZERONEZ x (SEQZ z))) && buildcfg.GORISCV64 >= 23 => (XOR x (CZERONEZ y z)) -// (z != 0) ? (x ^ y) : x -> XOR x (CZEROEQZ y z) -(OR (CZEROEQZ (XOR x y) (SNEZ z)) (CZERONEZ x (SNEZ z))) && buildcfg.GORISCV64 >= 23 => (XOR x (CZEROEQZ y z)) - -// (z == 0) ? (x & y) : x -> OR (AND x y) (CZEROEQZ x z) -(OR (CZEROEQZ (AND x y) (SEQZ z)) (CZERONEZ x (SEQZ z))) && buildcfg.GORISCV64 >= 23 => (OR (AND x y) (CZEROEQZ x z)) -// (z != 0) ? (x & y) : x -> OR (AND x y) (CZERONEZ x z) -(OR (CZEROEQZ (AND x y) (SNEZ z)) (CZERONEZ x (SNEZ z))) && buildcfg.GORISCV64 >= 23 => (OR (AND x y) (CZERONEZ x z)) +// OR-form optimizations for arithmetic/logic ops (64-bit and 32-bit) +// (z == 0) ? ((OP x y)) : x => (OP x (CZERONEZ y z)) +(OR (CZEROEQZ ((ADD|SUB|OR|XOR|SUBW) x y) (SEQZ z)) (CZERONEZ x (SEQZ z))) && buildcfg.GORISCV64 >= 23 + => ((ADD|SUB|OR|XOR|SUBW) x (CZERONEZ y z)) +// (z != 0) ? ((OP x y)) : x => (OP x (CZEROEQZ y z)) +(OR (CZEROEQZ ((ADD|SUB|OR|XOR|SUBW) x y) (SNEZ z)) (CZERONEZ x (SNEZ z))) && buildcfg.GORISCV64 >= 23 + => ((ADD|SUB|OR|XOR|SUBW) x (CZEROEQZ y z)) + +// AND-specific optimizations +// (z == 0) ? (x & y) : x => OR(AND x y, CZEROEQZ x z) +(OR (CZEROEQZ (AND x y) (SEQZ z)) (CZERONEZ x (SEQZ z))) && buildcfg.GORISCV64 >= 23 + => (OR (AND x y) (CZEROEQZ x z)) +// (z != 0) ? (x & y) : x => OR(AND x y, CZERONEZ x z) +(OR (CZEROEQZ (AND x y) (SNEZ z)) (CZERONEZ x (SNEZ z))) && buildcfg.GORISCV64 >= 23 + => (OR (AND x y) (CZERONEZ x z)) + +// ANDI-specific optimizations (immediate version of AND) +// (z == 0) ? (x & c) : x => OR(AND x c, CZEROEQZ x z) +(OR (CZEROEQZ (ANDI [c] x) (SEQZ z)) (CZERONEZ x (SEQZ z))) && buildcfg.GORISCV64 >= 23 + => (OR (AND x (MOVDconst [c])) (CZEROEQZ x z)) +// (z != 0) ? (x & c) : x => OR(AND x c, CZERONEZ x z) +(OR (CZEROEQZ (ANDI [c] x) (SNEZ z)) (CZERONEZ x (SNEZ z))) && buildcfg.GORISCV64 >= 23 + => (OR (AND x (MOVDconst [c])) (CZERONEZ x z)) + +// Immediate variants (64-bit only) - immediate is on the right +// (z == 0) ? ((OPI [c] x)) : x => (OP x (CZERONEZ c z)) +(OR (CZEROEQZ ((ADDI|ORI|XORI) [c] x) (SEQZ z)) (CZERONEZ x (SEQZ z))) && buildcfg.GORISCV64 >= 23 + => ((ADD|OR|XOR) x (CZERONEZ (MOVDconst [c]) z)) +// (z != 0) ? ((OPI [c] x)) : x => (OP x (CZEROEQZ c z)) +(OR (CZEROEQZ ((ADDI|ORI|XORI) [c] x) (SNEZ z)) (CZERONEZ x (SNEZ z))) && buildcfg.GORISCV64 >= 23 + => ((ADD|OR|XOR) x (CZEROEQZ (MOVDconst [c]) z)) + +// 32-bit immediate variant (only ADDIW exists, no SUBIW/ORIW/XORIW/ANDIW) +// (z == 0) ? (ADDIW [c] x) : x +(OR (CZEROEQZ (ADDIW [c] x) (SEQZ z)) (CZERONEZ x (SEQZ z))) && buildcfg.GORISCV64 >= 23 + => (ADD x (CZERONEZ (MOVDconst [int64(int32(c))]) z)) +// (z != 0) ? (ADDIW [c] x) : x +(OR (CZEROEQZ (ADDIW [c] x) (SNEZ z)) (CZERONEZ x (SNEZ z))) && buildcfg.GORISCV64 >= 23 + => (ADD x (CZEROEQZ (MOVDconst [int64(int32(c))]) z)) + +// Optimize conditional selection of constant or zero to single CZERO instruction +// (cond == 0) ? 0 : const => CZERONEZ const cond +(OR (CZEROEQZ (MOVDconst [0]) (SEQZ cond)) (CZERONEZ (MOVDconst [c]) (SEQZ cond))) && buildcfg.GORISCV64 >= 23 + => (CZERONEZ (MOVDconst [c]) cond) +// (cond != 0) ? 0 : const => CZEROEQZ const cond +(OR (CZEROEQZ (MOVDconst [0]) (SNEZ cond)) (CZERONEZ (MOVDconst [c]) (SNEZ cond))) && buildcfg.GORISCV64 >= 23 + => (CZEROEQZ (MOVDconst [c]) cond) + +// Constant propagation through CZERO(EQ|NE)Z +(CZERO(EQ|NE)Z (MOVDconst [0]) _) && buildcfg.GORISCV64 >= 23 => (MOVDconst [0]) \ No newline at end of file diff --git a/src/cmd/compile/internal/ssa/rewriteRISCV64latelower.go b/src/cmd/compile/internal/ssa/rewriteRISCV64latelower.go index 07710c6e84e365..bde84b639392e5 100644 --- a/src/cmd/compile/internal/ssa/rewriteRISCV64latelower.go +++ b/src/cmd/compile/internal/ssa/rewriteRISCV64latelower.go @@ -8,6 +8,10 @@ func rewriteValueRISCV64latelower(v *Value) bool { switch v.Op { case OpRISCV64AND: return rewriteValueRISCV64latelower_OpRISCV64AND(v) + case OpRISCV64CZEROEQZ: + return rewriteValueRISCV64latelower_OpRISCV64CZEROEQZ(v) + case OpRISCV64CZERONEZ: + return rewriteValueRISCV64latelower_OpRISCV64CZERONEZ(v) case OpRISCV64NOT: return rewriteValueRISCV64latelower_OpRISCV64NOT(v) case OpRISCV64OR: @@ -43,6 +47,40 @@ func rewriteValueRISCV64latelower_OpRISCV64AND(v *Value) bool { } return false } +func rewriteValueRISCV64latelower_OpRISCV64CZEROEQZ(v *Value) bool { + v_0 := v.Args[0] + // match: (CZEROEQZ (MOVDconst [0]) _) + // cond: buildcfg.GORISCV64 >= 23 + // result: (MOVDconst [0]) + for { + t := v.Type + if v_0.Op != OpRISCV64MOVDconst || auxIntToInt64(v_0.AuxInt) != 0 || !(buildcfg.GORISCV64 >= 23) { + break + } + v.reset(OpRISCV64MOVDconst) + v.Type = t + v.AuxInt = int64ToAuxInt(0) + return true + } + return false +} +func rewriteValueRISCV64latelower_OpRISCV64CZERONEZ(v *Value) bool { + v_0 := v.Args[0] + // match: (CZERONEZ (MOVDconst [0]) _) + // cond: buildcfg.GORISCV64 >= 23 + // result: (MOVDconst [0]) + for { + t := v.Type + if v_0.Op != OpRISCV64MOVDconst || auxIntToInt64(v_0.AuxInt) != 0 || !(buildcfg.GORISCV64 >= 23) { + break + } + v.reset(OpRISCV64MOVDconst) + v.Type = t + v.AuxInt = int64ToAuxInt(0) + return true + } + return false +} func rewriteValueRISCV64latelower_OpRISCV64NOT(v *Value) bool { v_0 := v.Args[0] // match: (NOT (XOR x y)) @@ -63,6 +101,7 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { v_1 := v.Args[1] v_0 := v.Args[0] b := v.Block + typ := &b.Func.Config.Types // match: (OR x (NOT y)) // result: (ORN x y) for { @@ -151,9 +190,9 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { } break } - // match: (OR (CZEROEQZ (ADD x y) (SNEZ z)) (CZERONEZ x (SNEZ z))) + // match: (OR (CZEROEQZ (SUB x y) (SEQZ z)) (CZERONEZ x (SEQZ z))) // cond: buildcfg.GORISCV64 >= 23 - // result: (ADD x (CZEROEQZ y z)) + // result: (SUB x (CZERONEZ y z)) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { if v_0.Op != OpRISCV64CZEROEQZ { @@ -162,7 +201,47 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { t := v_0.Type _ = v_0.Args[1] v_0_0 := v_0.Args[0] - if v_0_0.Op != OpRISCV64ADD { + if v_0_0.Op != OpRISCV64SUB { + continue + } + y := v_0_0.Args[1] + x := v_0_0.Args[0] + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpRISCV64SEQZ { + continue + } + z := v_0_1.Args[0] + if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { + continue + } + _ = v_1.Args[1] + if x != v_1.Args[0] { + continue + } + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpRISCV64SEQZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + continue + } + v.reset(OpRISCV64SUB) + v0 := b.NewValue0(v.Pos, OpRISCV64CZERONEZ, t) + v0.AddArg2(y, z) + v.AddArg2(x, v0) + return true + } + break + } + // match: (OR (CZEROEQZ (OR x y) (SEQZ z)) (CZERONEZ x (SEQZ z))) + // cond: buildcfg.GORISCV64 >= 23 + // result: (OR x (CZERONEZ y z)) + for { + for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { + if v_0.Op != OpRISCV64CZEROEQZ { + continue + } + t := v_0.Type + _ = v_0.Args[1] + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpRISCV64OR { continue } _ = v_0_0.Args[1] @@ -172,7 +251,7 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { x := v_0_0_0 y := v_0_0_1 v_0_1 := v_0.Args[1] - if v_0_1.Op != OpRISCV64SNEZ { + if v_0_1.Op != OpRISCV64SEQZ { continue } z := v_0_1.Args[0] @@ -184,11 +263,11 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { continue } v_1_1 := v_1.Args[1] - if v_1_1.Op != OpRISCV64SNEZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + if v_1_1.Op != OpRISCV64SEQZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { continue } - v.reset(OpRISCV64ADD) - v0 := b.NewValue0(v.Pos, OpRISCV64CZEROEQZ, t) + v.reset(OpRISCV64OR) + v0 := b.NewValue0(v.Pos, OpRISCV64CZERONEZ, t) v0.AddArg2(y, z) v.AddArg2(x, v0) return true @@ -196,9 +275,9 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { } break } - // match: (OR (CZEROEQZ (SUB x y) (SEQZ z)) (CZERONEZ x (SEQZ z))) + // match: (OR (CZEROEQZ (XOR x y) (SEQZ z)) (CZERONEZ x (SEQZ z))) // cond: buildcfg.GORISCV64 >= 23 - // result: (SUB x (CZERONEZ y z)) + // result: (XOR x (CZERONEZ y z)) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { if v_0.Op != OpRISCV64CZEROEQZ { @@ -207,38 +286,43 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { t := v_0.Type _ = v_0.Args[1] v_0_0 := v_0.Args[0] - if v_0_0.Op != OpRISCV64SUB { - continue - } - y := v_0_0.Args[1] - x := v_0_0.Args[0] - v_0_1 := v_0.Args[1] - if v_0_1.Op != OpRISCV64SEQZ { - continue - } - z := v_0_1.Args[0] - if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { - continue - } - _ = v_1.Args[1] - if x != v_1.Args[0] { + if v_0_0.Op != OpRISCV64XOR { continue } - v_1_1 := v_1.Args[1] - if v_1_1.Op != OpRISCV64SEQZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { - continue + _ = v_0_0.Args[1] + v_0_0_0 := v_0_0.Args[0] + v_0_0_1 := v_0_0.Args[1] + for _i1 := 0; _i1 <= 1; _i1, v_0_0_0, v_0_0_1 = _i1+1, v_0_0_1, v_0_0_0 { + x := v_0_0_0 + y := v_0_0_1 + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpRISCV64SEQZ { + continue + } + z := v_0_1.Args[0] + if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { + continue + } + _ = v_1.Args[1] + if x != v_1.Args[0] { + continue + } + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpRISCV64SEQZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + continue + } + v.reset(OpRISCV64XOR) + v0 := b.NewValue0(v.Pos, OpRISCV64CZERONEZ, t) + v0.AddArg2(y, z) + v.AddArg2(x, v0) + return true } - v.reset(OpRISCV64SUB) - v0 := b.NewValue0(v.Pos, OpRISCV64CZERONEZ, t) - v0.AddArg2(y, z) - v.AddArg2(x, v0) - return true } break } - // match: (OR (CZEROEQZ (SUB x y) (SNEZ z)) (CZERONEZ x (SNEZ z))) + // match: (OR (CZEROEQZ (SUBW x y) (SEQZ z)) (CZERONEZ x (SEQZ z))) // cond: buildcfg.GORISCV64 >= 23 - // result: (SUB x (CZEROEQZ y z)) + // result: (SUBW x (CZERONEZ y z)) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { if v_0.Op != OpRISCV64CZEROEQZ { @@ -247,13 +331,13 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { t := v_0.Type _ = v_0.Args[1] v_0_0 := v_0.Args[0] - if v_0_0.Op != OpRISCV64SUB { + if v_0_0.Op != OpRISCV64SUBW { continue } y := v_0_0.Args[1] x := v_0_0.Args[0] v_0_1 := v_0.Args[1] - if v_0_1.Op != OpRISCV64SNEZ { + if v_0_1.Op != OpRISCV64SEQZ { continue } z := v_0_1.Args[0] @@ -265,20 +349,20 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { continue } v_1_1 := v_1.Args[1] - if v_1_1.Op != OpRISCV64SNEZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + if v_1_1.Op != OpRISCV64SEQZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { continue } - v.reset(OpRISCV64SUB) - v0 := b.NewValue0(v.Pos, OpRISCV64CZEROEQZ, t) + v.reset(OpRISCV64SUBW) + v0 := b.NewValue0(v.Pos, OpRISCV64CZERONEZ, t) v0.AddArg2(y, z) v.AddArg2(x, v0) return true } break } - // match: (OR (CZEROEQZ (OR x y) (SEQZ z)) (CZERONEZ x (SEQZ z))) + // match: (OR (CZEROEQZ (ADD x y) (SNEZ z)) (CZERONEZ x (SNEZ z))) // cond: buildcfg.GORISCV64 >= 23 - // result: (OR x (CZERONEZ y z)) + // result: (ADD x (CZEROEQZ y z)) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { if v_0.Op != OpRISCV64CZEROEQZ { @@ -287,7 +371,7 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { t := v_0.Type _ = v_0.Args[1] v_0_0 := v_0.Args[0] - if v_0_0.Op != OpRISCV64OR { + if v_0_0.Op != OpRISCV64ADD { continue } _ = v_0_0.Args[1] @@ -297,7 +381,7 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { x := v_0_0_0 y := v_0_0_1 v_0_1 := v_0.Args[1] - if v_0_1.Op != OpRISCV64SEQZ { + if v_0_1.Op != OpRISCV64SNEZ { continue } z := v_0_1.Args[0] @@ -309,11 +393,11 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { continue } v_1_1 := v_1.Args[1] - if v_1_1.Op != OpRISCV64SEQZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + if v_1_1.Op != OpRISCV64SNEZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { continue } - v.reset(OpRISCV64OR) - v0 := b.NewValue0(v.Pos, OpRISCV64CZERONEZ, t) + v.reset(OpRISCV64ADD) + v0 := b.NewValue0(v.Pos, OpRISCV64CZEROEQZ, t) v0.AddArg2(y, z) v.AddArg2(x, v0) return true @@ -321,6 +405,46 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { } break } + // match: (OR (CZEROEQZ (SUB x y) (SNEZ z)) (CZERONEZ x (SNEZ z))) + // cond: buildcfg.GORISCV64 >= 23 + // result: (SUB x (CZEROEQZ y z)) + for { + for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { + if v_0.Op != OpRISCV64CZEROEQZ { + continue + } + t := v_0.Type + _ = v_0.Args[1] + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpRISCV64SUB { + continue + } + y := v_0_0.Args[1] + x := v_0_0.Args[0] + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpRISCV64SNEZ { + continue + } + z := v_0_1.Args[0] + if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { + continue + } + _ = v_1.Args[1] + if x != v_1.Args[0] { + continue + } + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpRISCV64SNEZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + continue + } + v.reset(OpRISCV64SUB) + v0 := b.NewValue0(v.Pos, OpRISCV64CZEROEQZ, t) + v0.AddArg2(y, z) + v.AddArg2(x, v0) + return true + } + break + } // match: (OR (CZEROEQZ (OR x y) (SNEZ z)) (CZERONEZ x (SNEZ z))) // cond: buildcfg.GORISCV64 >= 23 // result: (OR x (CZEROEQZ y z)) @@ -366,9 +490,9 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { } break } - // match: (OR (CZEROEQZ (XOR x y) (SEQZ z)) (CZERONEZ x (SEQZ z))) + // match: (OR (CZEROEQZ (XOR x y) (SNEZ z)) (CZERONEZ x (SNEZ z))) // cond: buildcfg.GORISCV64 >= 23 - // result: (XOR x (CZERONEZ y z)) + // result: (XOR x (CZEROEQZ y z)) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { if v_0.Op != OpRISCV64CZEROEQZ { @@ -387,7 +511,7 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { x := v_0_0_0 y := v_0_0_1 v_0_1 := v_0.Args[1] - if v_0_1.Op != OpRISCV64SEQZ { + if v_0_1.Op != OpRISCV64SNEZ { continue } z := v_0_1.Args[0] @@ -399,11 +523,11 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { continue } v_1_1 := v_1.Args[1] - if v_1_1.Op != OpRISCV64SEQZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + if v_1_1.Op != OpRISCV64SNEZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { continue } v.reset(OpRISCV64XOR) - v0 := b.NewValue0(v.Pos, OpRISCV64CZERONEZ, t) + v0 := b.NewValue0(v.Pos, OpRISCV64CZEROEQZ, t) v0.AddArg2(y, z) v.AddArg2(x, v0) return true @@ -411,9 +535,9 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { } break } - // match: (OR (CZEROEQZ (XOR x y) (SNEZ z)) (CZERONEZ x (SNEZ z))) + // match: (OR (CZEROEQZ (SUBW x y) (SNEZ z)) (CZERONEZ x (SNEZ z))) // cond: buildcfg.GORISCV64 >= 23 - // result: (XOR x (CZEROEQZ y z)) + // result: (SUBW x (CZEROEQZ y z)) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { if v_0.Op != OpRISCV64CZEROEQZ { @@ -422,37 +546,32 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { t := v_0.Type _ = v_0.Args[1] v_0_0 := v_0.Args[0] - if v_0_0.Op != OpRISCV64XOR { + if v_0_0.Op != OpRISCV64SUBW { continue } - _ = v_0_0.Args[1] - v_0_0_0 := v_0_0.Args[0] - v_0_0_1 := v_0_0.Args[1] - for _i1 := 0; _i1 <= 1; _i1, v_0_0_0, v_0_0_1 = _i1+1, v_0_0_1, v_0_0_0 { - x := v_0_0_0 - y := v_0_0_1 - v_0_1 := v_0.Args[1] - if v_0_1.Op != OpRISCV64SNEZ { - continue - } - z := v_0_1.Args[0] - if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { - continue - } - _ = v_1.Args[1] - if x != v_1.Args[0] { - continue - } - v_1_1 := v_1.Args[1] - if v_1_1.Op != OpRISCV64SNEZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { - continue - } - v.reset(OpRISCV64XOR) - v0 := b.NewValue0(v.Pos, OpRISCV64CZEROEQZ, t) - v0.AddArg2(y, z) - v.AddArg2(x, v0) - return true + y := v_0_0.Args[1] + x := v_0_0.Args[0] + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpRISCV64SNEZ { + continue + } + z := v_0_1.Args[0] + if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { + continue + } + _ = v_1.Args[1] + if x != v_1.Args[0] { + continue + } + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpRISCV64SNEZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + continue } + v.reset(OpRISCV64SUBW) + v0 := b.NewValue0(v.Pos, OpRISCV64CZEROEQZ, t) + v0.AddArg2(y, z) + v.AddArg2(x, v0) + return true } break } @@ -550,6 +669,512 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { } break } + // match: (OR (CZEROEQZ (ANDI [c] x) (SEQZ z)) (CZERONEZ x (SEQZ z))) + // cond: buildcfg.GORISCV64 >= 23 + // result: (OR (AND x (MOVDconst [c])) (CZEROEQZ x z)) + for { + for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { + if v_0.Op != OpRISCV64CZEROEQZ { + continue + } + t := v_0.Type + _ = v_0.Args[1] + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpRISCV64ANDI { + continue + } + c := auxIntToInt64(v_0_0.AuxInt) + x := v_0_0.Args[0] + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpRISCV64SEQZ { + continue + } + z := v_0_1.Args[0] + if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { + continue + } + _ = v_1.Args[1] + if x != v_1.Args[0] { + continue + } + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpRISCV64SEQZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + continue + } + v.reset(OpRISCV64OR) + v0 := b.NewValue0(v.Pos, OpRISCV64AND, t) + v1 := b.NewValue0(v.Pos, OpRISCV64MOVDconst, typ.UInt64) + v1.AuxInt = int64ToAuxInt(c) + v0.AddArg2(x, v1) + v2 := b.NewValue0(v.Pos, OpRISCV64CZEROEQZ, t) + v2.AddArg2(x, z) + v.AddArg2(v0, v2) + return true + } + break + } + // match: (OR (CZEROEQZ (ANDI [c] x) (SNEZ z)) (CZERONEZ x (SNEZ z))) + // cond: buildcfg.GORISCV64 >= 23 + // result: (OR (AND x (MOVDconst [c])) (CZERONEZ x z)) + for { + for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { + if v_0.Op != OpRISCV64CZEROEQZ { + continue + } + t := v_0.Type + _ = v_0.Args[1] + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpRISCV64ANDI { + continue + } + c := auxIntToInt64(v_0_0.AuxInt) + x := v_0_0.Args[0] + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpRISCV64SNEZ { + continue + } + z := v_0_1.Args[0] + if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { + continue + } + _ = v_1.Args[1] + if x != v_1.Args[0] { + continue + } + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpRISCV64SNEZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + continue + } + v.reset(OpRISCV64OR) + v0 := b.NewValue0(v.Pos, OpRISCV64AND, t) + v1 := b.NewValue0(v.Pos, OpRISCV64MOVDconst, typ.UInt64) + v1.AuxInt = int64ToAuxInt(c) + v0.AddArg2(x, v1) + v2 := b.NewValue0(v.Pos, OpRISCV64CZERONEZ, t) + v2.AddArg2(x, z) + v.AddArg2(v0, v2) + return true + } + break + } + // match: (OR (CZEROEQZ (ADDI [c] x) (SEQZ z)) (CZERONEZ x (SEQZ z))) + // cond: buildcfg.GORISCV64 >= 23 + // result: (ADD x (CZERONEZ (MOVDconst [c]) z)) + for { + for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { + if v_0.Op != OpRISCV64CZEROEQZ { + continue + } + t := v_0.Type + _ = v_0.Args[1] + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpRISCV64ADDI { + continue + } + c := auxIntToInt64(v_0_0.AuxInt) + x := v_0_0.Args[0] + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpRISCV64SEQZ { + continue + } + z := v_0_1.Args[0] + if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { + continue + } + _ = v_1.Args[1] + if x != v_1.Args[0] { + continue + } + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpRISCV64SEQZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + continue + } + v.reset(OpRISCV64ADD) + v0 := b.NewValue0(v.Pos, OpRISCV64CZERONEZ, t) + v1 := b.NewValue0(v.Pos, OpRISCV64MOVDconst, typ.UInt64) + v1.AuxInt = int64ToAuxInt(c) + v0.AddArg2(v1, z) + v.AddArg2(x, v0) + return true + } + break + } + // match: (OR (CZEROEQZ (ORI [c] x) (SEQZ z)) (CZERONEZ x (SEQZ z))) + // cond: buildcfg.GORISCV64 >= 23 + // result: (OR x (CZERONEZ (MOVDconst [c]) z)) + for { + for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { + if v_0.Op != OpRISCV64CZEROEQZ { + continue + } + t := v_0.Type + _ = v_0.Args[1] + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpRISCV64ORI { + continue + } + c := auxIntToInt64(v_0_0.AuxInt) + x := v_0_0.Args[0] + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpRISCV64SEQZ { + continue + } + z := v_0_1.Args[0] + if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { + continue + } + _ = v_1.Args[1] + if x != v_1.Args[0] { + continue + } + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpRISCV64SEQZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + continue + } + v.reset(OpRISCV64OR) + v0 := b.NewValue0(v.Pos, OpRISCV64CZERONEZ, t) + v1 := b.NewValue0(v.Pos, OpRISCV64MOVDconst, typ.UInt64) + v1.AuxInt = int64ToAuxInt(c) + v0.AddArg2(v1, z) + v.AddArg2(x, v0) + return true + } + break + } + // match: (OR (CZEROEQZ (XORI [c] x) (SEQZ z)) (CZERONEZ x (SEQZ z))) + // cond: buildcfg.GORISCV64 >= 23 + // result: (XOR x (CZERONEZ (MOVDconst [c]) z)) + for { + for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { + if v_0.Op != OpRISCV64CZEROEQZ { + continue + } + t := v_0.Type + _ = v_0.Args[1] + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpRISCV64XORI { + continue + } + c := auxIntToInt64(v_0_0.AuxInt) + x := v_0_0.Args[0] + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpRISCV64SEQZ { + continue + } + z := v_0_1.Args[0] + if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { + continue + } + _ = v_1.Args[1] + if x != v_1.Args[0] { + continue + } + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpRISCV64SEQZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + continue + } + v.reset(OpRISCV64XOR) + v0 := b.NewValue0(v.Pos, OpRISCV64CZERONEZ, t) + v1 := b.NewValue0(v.Pos, OpRISCV64MOVDconst, typ.UInt64) + v1.AuxInt = int64ToAuxInt(c) + v0.AddArg2(v1, z) + v.AddArg2(x, v0) + return true + } + break + } + // match: (OR (CZEROEQZ (ADDI [c] x) (SNEZ z)) (CZERONEZ x (SNEZ z))) + // cond: buildcfg.GORISCV64 >= 23 + // result: (ADD x (CZEROEQZ (MOVDconst [c]) z)) + for { + for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { + if v_0.Op != OpRISCV64CZEROEQZ { + continue + } + t := v_0.Type + _ = v_0.Args[1] + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpRISCV64ADDI { + continue + } + c := auxIntToInt64(v_0_0.AuxInt) + x := v_0_0.Args[0] + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpRISCV64SNEZ { + continue + } + z := v_0_1.Args[0] + if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { + continue + } + _ = v_1.Args[1] + if x != v_1.Args[0] { + continue + } + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpRISCV64SNEZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + continue + } + v.reset(OpRISCV64ADD) + v0 := b.NewValue0(v.Pos, OpRISCV64CZEROEQZ, t) + v1 := b.NewValue0(v.Pos, OpRISCV64MOVDconst, typ.UInt64) + v1.AuxInt = int64ToAuxInt(c) + v0.AddArg2(v1, z) + v.AddArg2(x, v0) + return true + } + break + } + // match: (OR (CZEROEQZ (ORI [c] x) (SNEZ z)) (CZERONEZ x (SNEZ z))) + // cond: buildcfg.GORISCV64 >= 23 + // result: (OR x (CZEROEQZ (MOVDconst [c]) z)) + for { + for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { + if v_0.Op != OpRISCV64CZEROEQZ { + continue + } + t := v_0.Type + _ = v_0.Args[1] + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpRISCV64ORI { + continue + } + c := auxIntToInt64(v_0_0.AuxInt) + x := v_0_0.Args[0] + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpRISCV64SNEZ { + continue + } + z := v_0_1.Args[0] + if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { + continue + } + _ = v_1.Args[1] + if x != v_1.Args[0] { + continue + } + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpRISCV64SNEZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + continue + } + v.reset(OpRISCV64OR) + v0 := b.NewValue0(v.Pos, OpRISCV64CZEROEQZ, t) + v1 := b.NewValue0(v.Pos, OpRISCV64MOVDconst, typ.UInt64) + v1.AuxInt = int64ToAuxInt(c) + v0.AddArg2(v1, z) + v.AddArg2(x, v0) + return true + } + break + } + // match: (OR (CZEROEQZ (XORI [c] x) (SNEZ z)) (CZERONEZ x (SNEZ z))) + // cond: buildcfg.GORISCV64 >= 23 + // result: (XOR x (CZEROEQZ (MOVDconst [c]) z)) + for { + for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { + if v_0.Op != OpRISCV64CZEROEQZ { + continue + } + t := v_0.Type + _ = v_0.Args[1] + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpRISCV64XORI { + continue + } + c := auxIntToInt64(v_0_0.AuxInt) + x := v_0_0.Args[0] + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpRISCV64SNEZ { + continue + } + z := v_0_1.Args[0] + if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { + continue + } + _ = v_1.Args[1] + if x != v_1.Args[0] { + continue + } + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpRISCV64SNEZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + continue + } + v.reset(OpRISCV64XOR) + v0 := b.NewValue0(v.Pos, OpRISCV64CZEROEQZ, t) + v1 := b.NewValue0(v.Pos, OpRISCV64MOVDconst, typ.UInt64) + v1.AuxInt = int64ToAuxInt(c) + v0.AddArg2(v1, z) + v.AddArg2(x, v0) + return true + } + break + } + // match: (OR (CZEROEQZ (ADDIW [c] x) (SEQZ z)) (CZERONEZ x (SEQZ z))) + // cond: buildcfg.GORISCV64 >= 23 + // result: (ADD x (CZERONEZ (MOVDconst [int64(int32(c))]) z)) + for { + for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { + if v_0.Op != OpRISCV64CZEROEQZ { + continue + } + t := v_0.Type + _ = v_0.Args[1] + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpRISCV64ADDIW { + continue + } + c := auxIntToInt64(v_0_0.AuxInt) + x := v_0_0.Args[0] + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpRISCV64SEQZ { + continue + } + z := v_0_1.Args[0] + if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { + continue + } + _ = v_1.Args[1] + if x != v_1.Args[0] { + continue + } + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpRISCV64SEQZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + continue + } + v.reset(OpRISCV64ADD) + v0 := b.NewValue0(v.Pos, OpRISCV64CZERONEZ, t) + v1 := b.NewValue0(v.Pos, OpRISCV64MOVDconst, typ.UInt64) + v1.AuxInt = int64ToAuxInt(int64(int32(c))) + v0.AddArg2(v1, z) + v.AddArg2(x, v0) + return true + } + break + } + // match: (OR (CZEROEQZ (ADDIW [c] x) (SNEZ z)) (CZERONEZ x (SNEZ z))) + // cond: buildcfg.GORISCV64 >= 23 + // result: (ADD x (CZEROEQZ (MOVDconst [int64(int32(c))]) z)) + for { + for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { + if v_0.Op != OpRISCV64CZEROEQZ { + continue + } + t := v_0.Type + _ = v_0.Args[1] + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpRISCV64ADDIW { + continue + } + c := auxIntToInt64(v_0_0.AuxInt) + x := v_0_0.Args[0] + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpRISCV64SNEZ { + continue + } + z := v_0_1.Args[0] + if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { + continue + } + _ = v_1.Args[1] + if x != v_1.Args[0] { + continue + } + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpRISCV64SNEZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + continue + } + v.reset(OpRISCV64ADD) + v0 := b.NewValue0(v.Pos, OpRISCV64CZEROEQZ, t) + v1 := b.NewValue0(v.Pos, OpRISCV64MOVDconst, typ.UInt64) + v1.AuxInt = int64ToAuxInt(int64(int32(c))) + v0.AddArg2(v1, z) + v.AddArg2(x, v0) + return true + } + break + } + // match: (OR (CZEROEQZ (MOVDconst [0]) (SEQZ cond)) (CZERONEZ (MOVDconst [c]) (SEQZ cond))) + // cond: buildcfg.GORISCV64 >= 23 + // result: (CZERONEZ (MOVDconst [c]) cond) + for { + for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { + if v_0.Op != OpRISCV64CZEROEQZ { + continue + } + t := v_0.Type + _ = v_0.Args[1] + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpRISCV64MOVDconst || auxIntToInt64(v_0_0.AuxInt) != 0 { + continue + } + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpRISCV64SEQZ { + continue + } + cond := v_0_1.Args[0] + if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { + continue + } + _ = v_1.Args[1] + v_1_0 := v_1.Args[0] + if v_1_0.Op != OpRISCV64MOVDconst { + continue + } + c := auxIntToInt64(v_1_0.AuxInt) + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpRISCV64SEQZ || cond != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + continue + } + v.reset(OpRISCV64CZERONEZ) + v.Type = t + v0 := b.NewValue0(v.Pos, OpRISCV64MOVDconst, typ.UInt64) + v0.AuxInt = int64ToAuxInt(c) + v.AddArg2(v0, cond) + return true + } + break + } + // match: (OR (CZEROEQZ (MOVDconst [0]) (SNEZ cond)) (CZERONEZ (MOVDconst [c]) (SNEZ cond))) + // cond: buildcfg.GORISCV64 >= 23 + // result: (CZEROEQZ (MOVDconst [c]) cond) + for { + for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { + if v_0.Op != OpRISCV64CZEROEQZ { + continue + } + t := v_0.Type + _ = v_0.Args[1] + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpRISCV64MOVDconst || auxIntToInt64(v_0_0.AuxInt) != 0 { + continue + } + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpRISCV64SNEZ { + continue + } + cond := v_0_1.Args[0] + if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { + continue + } + _ = v_1.Args[1] + v_1_0 := v_1.Args[0] + if v_1_0.Op != OpRISCV64MOVDconst { + continue + } + c := auxIntToInt64(v_1_0.AuxInt) + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpRISCV64SNEZ || cond != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + continue + } + v.reset(OpRISCV64CZEROEQZ) + v.Type = t + v0 := b.NewValue0(v.Pos, OpRISCV64MOVDconst, typ.UInt64) + v0.AuxInt = int64ToAuxInt(c) + v.AddArg2(v0, cond) + return true + } + break + } return false } func rewriteValueRISCV64latelower_OpRISCV64SLLI(v *Value) bool { diff --git a/test/codegen/condmove.go b/test/codegen/condmove.go index 8670d0e65c71e3..c3e675cea9190f 100644 --- a/test/codegen/condmove.go +++ b/test/codegen/condmove.go @@ -365,7 +365,7 @@ func cmovsetm(cond bool, x int) { // arm64:"CSETM\tNE", -"CSEL" // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` + // riscv64/rva23u64:`CZEROEQZ`, -`CZERONEZ` r0 = x0 if cond { @@ -376,7 +376,7 @@ func cmovsetm(cond bool, x int) { // arm64:"CSETM\tEQ", -"CSEL" // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` + // riscv64/rva23u64:`CZERONEZ`, -`CZEROEQZ` r1 = x1 } @@ -424,7 +424,7 @@ func cmovFcmp0(s, t float64, a, b int) { // arm64:"CSETM\tLS", -"CSEL" // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` + // riscv64/rva23u64:`CZEROEQZ`, -`CZERONEZ` r3 = x3 if s == t { @@ -494,7 +494,7 @@ func cmovFcmp1(s, t float64, a, b int) { // arm64:"CSETM\tHI", -"CSEL" // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` + // riscv64/rva23u64:`CZERONEZ`,-`CZEROEQZ` r3 = x3 if s == t { @@ -528,7 +528,7 @@ func cmovzero1(c bool) int { // loong64:"MASKEQZ", -"MASKNEZ" // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` + // riscv64/rva23u64:`CZEROEQZ`, -`CZERONEZ` return x } @@ -540,7 +540,7 @@ func cmovzero2(c bool) int { // loong64:"MASKNEZ", -"MASKEQZ" // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` + // riscv64/rva23u64:`CZERONEZ`, -`CZEROEQZ` return x } @@ -548,7 +548,7 @@ func cmovzero2(c bool) int { // an extra load of 0 to a register on PPC64 by using R0 (which always // holds the value $0) instead. Verify both cases where either arg1 // or arg2 is zero. -func cmovzeroreg0(a, b int) int { +func cmovzeroregZero11(a, b int) int { x := 0 if a == b { x = a @@ -556,7 +556,7 @@ func cmovzeroreg0(a, b int) int { // ppc64x:"ISEL\t[$]2, R[0-9]+, R0, R[0-9]+" // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` + // riscv64/rva23u64:`CZEROEQZ`,-`CZERONEZ` return x } @@ -568,7 +568,7 @@ func cmovzeroreg1(a, b int) int { // ppc64x:"ISEL\t[$]2, R0, R[0-9]+, R[0-9]+" // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` + // riscv64/rva23u64:`CZERONEZ`, -`CZEROEQZ` return x } @@ -628,110 +628,82 @@ func cmovmathhalveu(a uint, b bool) uint { return a } -func cmoveAddZero(cond, a, b int) int { - result := a +func cmoveAddZero11(cond, a, b int) int { if cond == 0 { - result = a + b + a += b } // riscv64/rva23u64:`CZERONEZ`, `ADD`, -`SEQZ`, -`CZEROEQZ`, -`OR` - return result + return a } -func cmoveAddNonZero(cond, a, b int) int { - var result int +func cmoveAddNonZero11(cond, a, b int) int { if cond != 0 { - result = a + b - } else { - result = a + a += b } // riscv64/rva23u64:`CZEROEQZ`, `ADD`, -`SNEZ`, -`CZERONEZ`, -`OR` - return result + return a } -func cmoveSubZero(cond, a, b int) int { - var result int +func cmoveSubZero11(cond, a, b int) int { if cond == 0 { - result = a - b - } else { - result = a + a -= b } // riscv64/rva23u64:`CZERONEZ`, `SUB`, -`SEQZ`, -`CZEROEQZ`, -`OR` - return result + return a } -func cmoveSubNonZero(cond, a, b int) int { - var result int +func cmoveSubNonZero11(cond, a, b int) int { if cond != 0 { - result = a - b - } else { - result = a + a -= b } // riscv64/rva23u64:`CZEROEQZ`, `SUB`, -`SNEZ`, -`CZERONEZ`, -`OR` - return result + return a } -func cmoveOrZero(cond, a, b int) int { - var result int +func cmoveOrZero11(cond, a, b int) int { if cond == 0 { - result = a | b - } else { - result = a + a |= b } // riscv64/rva23u64:`CZERONEZ`, `OR`, -`SEQZ`, -`CZEROEQZ` - return result + return a } -func cmoveOrNonZero(cond, a, b int) int { - var result int +func cmoveOrNonZero11(cond, a, b int) int { if cond != 0 { - result = a | b - } else { - result = a + a |= b } // riscv64/rva23u64:`CZEROEQZ`, `OR`, -`SNEZ`, -`CZERONEZ` - return result + return a } -func cmoveXorZero(cond, a, b int) int { - var result int +func cmoveXorZero11(cond, a, b int) int { if cond == 0 { - result = a ^ b - } else { - result = a + a ^= b } // riscv64/rva23u64:`CZERONEZ`, `XOR`, -`SEQZ`, -`CZEROEQZ`, -`OR` - return result + return a } -func cmoveXorNonZero(cond, a, b int) int { - var result int +func cmoveXorNonZero11(cond, a, b int) int { if cond != 0 { - result = a ^ b - } else { - result = a + a ^= b } // riscv64/rva23u64:`CZEROEQZ`, `XOR`, -`SNEZ`, -`CZERONEZ`, -`OR` - return result + return a } -func cmoveAndZero(cond, a, b int) int { - var result int +func cmoveAndZero11(cond, a, b int) int { if cond == 0 { - result = a & b - } else { - result = a + a &= b } // riscv64/rva23u64:`CZEROEQZ`, `AND`, `OR`, -`SEQZ`, -`CZERONEZ` - return result + return a } -func CondAndNonZero(cond, a, b int) int { - var result int +func CondAndNonZero11(cond, a, b int) int { if cond != 0 { - result = a & b - } else { - result = a + a &= b } // riscv64/rva23u64:`CZERONEZ`, `AND`, `OR`, -`SNEZ`, -`CZEROEQZ` - return result + return a } From 0ea745c8cf568b3a550727fd3210073b840a110d Mon Sep 17 00:00:00 2001 From: Xueqi Luo <1824368278@qq.com> Date: Tue, 21 Oct 2025 16:21:51 +0800 Subject: [PATCH 6/8] fix test file --- .../compile/internal/ssa/_gen/RISCV64.rules | 1 - .../internal/ssa/_gen/RISCV64latelower.rules | 12 +- test/codegen/condmove.go | 265 ++++++++++++------ 3 files changed, 177 insertions(+), 101 deletions(-) diff --git a/src/cmd/compile/internal/ssa/_gen/RISCV64.rules b/src/cmd/compile/internal/ssa/_gen/RISCV64.rules index 8a4f0012a5ae8f..c5b052bbc20b31 100644 --- a/src/cmd/compile/internal/ssa/_gen/RISCV64.rules +++ b/src/cmd/compile/internal/ssa/_gen/RISCV64.rules @@ -851,6 +851,5 @@ (Max64u x y) && buildcfg.GORISCV64 >= 22 => (MAXU x y) // Zicond Extension for Integer Conditional Operations - // General lowering rule: always lower CondSelect to OR(CZEROEQZ, CZERONEZ) form (CondSelect x y cond) && buildcfg.GORISCV64 >= 23 => (OR (CZEROEQZ x cond) (CZERONEZ y cond)) diff --git a/src/cmd/compile/internal/ssa/_gen/RISCV64latelower.rules b/src/cmd/compile/internal/ssa/_gen/RISCV64latelower.rules index 0b0ff5223f9b67..16b6da6f4ec227 100644 --- a/src/cmd/compile/internal/ssa/_gen/RISCV64latelower.rules +++ b/src/cmd/compile/internal/ssa/_gen/RISCV64latelower.rules @@ -24,12 +24,11 @@ (SRLI [0] x) => x (SLLI [0] x) => x -// "Zicond" Extension for Integer Conditional Operations +// "Zicond" Extension for Integer Conditional Operations // Optimize specific patterns based on the unified OR(CZEROEQZ, CZERONEZ) form // (x == 0) ? x : y -> CZEROEQZ y x (when x is the condition) (OR (CZEROEQZ x (SEQZ x)) (CZERONEZ y (SEQZ x))) && buildcfg.GORISCV64 >= 23 => (CZEROEQZ y x) -// OR-form optimizations for arithmetic/logic ops (64-bit and 32-bit) // (z == 0) ? ((OP x y)) : x => (OP x (CZERONEZ y z)) (OR (CZEROEQZ ((ADD|SUB|OR|XOR|SUBW) x y) (SEQZ z)) (CZERONEZ x (SEQZ z))) && buildcfg.GORISCV64 >= 23 => ((ADD|SUB|OR|XOR|SUBW) x (CZERONEZ y z)) @@ -37,7 +36,6 @@ (OR (CZEROEQZ ((ADD|SUB|OR|XOR|SUBW) x y) (SNEZ z)) (CZERONEZ x (SNEZ z))) && buildcfg.GORISCV64 >= 23 => ((ADD|SUB|OR|XOR|SUBW) x (CZEROEQZ y z)) -// AND-specific optimizations // (z == 0) ? (x & y) : x => OR(AND x y, CZEROEQZ x z) (OR (CZEROEQZ (AND x y) (SEQZ z)) (CZERONEZ x (SEQZ z))) && buildcfg.GORISCV64 >= 23 => (OR (AND x y) (CZEROEQZ x z)) @@ -45,7 +43,6 @@ (OR (CZEROEQZ (AND x y) (SNEZ z)) (CZERONEZ x (SNEZ z))) && buildcfg.GORISCV64 >= 23 => (OR (AND x y) (CZERONEZ x z)) -// ANDI-specific optimizations (immediate version of AND) // (z == 0) ? (x & c) : x => OR(AND x c, CZEROEQZ x z) (OR (CZEROEQZ (ANDI [c] x) (SEQZ z)) (CZERONEZ x (SEQZ z))) && buildcfg.GORISCV64 >= 23 => (OR (AND x (MOVDconst [c])) (CZEROEQZ x z)) @@ -53,7 +50,6 @@ (OR (CZEROEQZ (ANDI [c] x) (SNEZ z)) (CZERONEZ x (SNEZ z))) && buildcfg.GORISCV64 >= 23 => (OR (AND x (MOVDconst [c])) (CZERONEZ x z)) -// Immediate variants (64-bit only) - immediate is on the right // (z == 0) ? ((OPI [c] x)) : x => (OP x (CZERONEZ c z)) (OR (CZEROEQZ ((ADDI|ORI|XORI) [c] x) (SEQZ z)) (CZERONEZ x (SEQZ z))) && buildcfg.GORISCV64 >= 23 => ((ADD|OR|XOR) x (CZERONEZ (MOVDconst [c]) z)) @@ -61,7 +57,6 @@ (OR (CZEROEQZ ((ADDI|ORI|XORI) [c] x) (SNEZ z)) (CZERONEZ x (SNEZ z))) && buildcfg.GORISCV64 >= 23 => ((ADD|OR|XOR) x (CZEROEQZ (MOVDconst [c]) z)) -// 32-bit immediate variant (only ADDIW exists, no SUBIW/ORIW/XORIW/ANDIW) // (z == 0) ? (ADDIW [c] x) : x (OR (CZEROEQZ (ADDIW [c] x) (SEQZ z)) (CZERONEZ x (SEQZ z))) && buildcfg.GORISCV64 >= 23 => (ADD x (CZERONEZ (MOVDconst [int64(int32(c))]) z)) @@ -69,13 +64,12 @@ (OR (CZEROEQZ (ADDIW [c] x) (SNEZ z)) (CZERONEZ x (SNEZ z))) && buildcfg.GORISCV64 >= 23 => (ADD x (CZEROEQZ (MOVDconst [int64(int32(c))]) z)) -// Optimize conditional selection of constant or zero to single CZERO instruction // (cond == 0) ? 0 : const => CZERONEZ const cond (OR (CZEROEQZ (MOVDconst [0]) (SEQZ cond)) (CZERONEZ (MOVDconst [c]) (SEQZ cond))) && buildcfg.GORISCV64 >= 23 => (CZERONEZ (MOVDconst [c]) cond) -// (cond != 0) ? 0 : const => CZEROEQZ const cond +// (cond != 0) ? 0 : const => CZEROEQZ const cond (OR (CZEROEQZ (MOVDconst [0]) (SNEZ cond)) (CZERONEZ (MOVDconst [c]) (SNEZ cond))) && buildcfg.GORISCV64 >= 23 => (CZEROEQZ (MOVDconst [c]) cond) // Constant propagation through CZERO(EQ|NE)Z -(CZERO(EQ|NE)Z (MOVDconst [0]) _) && buildcfg.GORISCV64 >= 23 => (MOVDconst [0]) \ No newline at end of file +(CZERO(EQ|NE)Z (MOVDconst [0]) _) && buildcfg.GORISCV64 >= 23 => (MOVDconst [0]) diff --git a/test/codegen/condmove.go b/test/codegen/condmove.go index c3e675cea9190f..b6d8a8cedeb3a5 100644 --- a/test/codegen/condmove.go +++ b/test/codegen/condmove.go @@ -15,8 +15,7 @@ func cmovint(c int) int { // arm64:"CSEL\tLT" // ppc64x:"ISEL\t[$]0" // wasm:"Select" - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` return x } @@ -29,8 +28,7 @@ func cmovchan(x, y chan int) chan int { // arm64:"CSEL\tNE" // ppc64x:"ISEL\t[$]2" // wasm:"Select" - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` return x } @@ -43,8 +41,7 @@ func cmovuintptr(x, y uintptr) uintptr { // arm64:"CSNEG\tLS" // ppc64x:"ISEL\t[$]1" // wasm:"Select" - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` return x } @@ -57,8 +54,7 @@ func cmov32bit(x, y uint32) uint32 { // arm64:"CSNEG\t(LS|HS)" // ppc64x:"ISEL\t[$]1" // wasm:"Select" - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` return x } @@ -71,8 +67,7 @@ func cmov16bit(x, y uint16) uint16 { // arm64:"CSNEG\t(LS|HS)" // ppc64x:"ISEL\t[$][01]" // wasm:"Select" - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` return x } @@ -88,8 +83,7 @@ func cmovfloateq(x, y float64) int { // arm64:"CSEL\tEQ" // ppc64x:"ISEL\t[$]2" // wasm:"Select" - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` return a } @@ -103,8 +97,7 @@ func cmovfloatne(x, y float64) int { // arm64:"CSEL\tNE" // ppc64x:"ISEL\t[$]2" // wasm:"Select" - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` return a } @@ -133,8 +126,7 @@ func cmovfloatint2(x, y float64) float64 { // arm64:"CSEL\tMI" // ppc64x:"ISEL\t[$]0" // wasm:"Select" - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` r = r - ldexp(y, rexp-yexp) } @@ -151,8 +143,7 @@ func cmovloaded(x [4]int, y int) int { // arm64:"CSEL\tNE" // ppc64x:"ISEL\t[$]2" // wasm:"Select" - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR`, -`SNEZ` return y } @@ -166,8 +157,7 @@ func cmovuintptr2(x, y uintptr) uintptr { // arm64:"CSEL\tEQ" // ppc64x:"ISEL\t[$]2" // wasm:"Select" - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR`, -`SEQZ` return a } @@ -195,8 +185,7 @@ func cmovinvert1(x, y int64) int64 { y = -y } // amd64:"CMOVQGT" - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` return y } @@ -212,8 +201,7 @@ func cmovinvert3(x, y int64) int64 { y = -y } // amd64:"CMOVQEQ" - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` return y } @@ -222,8 +210,7 @@ func cmovinvert4(x, y int64) int64 { y = -y } // amd64:"CMOVQNE" - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` return y } @@ -232,8 +219,7 @@ func cmovinvert5(x, y uint64) uint64 { y = -y } // amd64:"CMOVQCS" - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` return y } @@ -242,8 +228,7 @@ func cmovinvert6(x, y uint64) uint64 { y = -y } // amd64:"CMOVQLS" - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` return y } @@ -262,8 +247,7 @@ func cmovstore(a []int, i int, b bool) { i += 42 } // amd64:"CMOVQNE" - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` a[i] = 7 } @@ -279,8 +263,7 @@ func cmovinc(cond bool, a, b, c int) { x0 = b + 1 } // arm64:"CSINC\tNE", -"CSEL" - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` r0 = x0 @@ -290,8 +273,7 @@ func cmovinc(cond bool, a, b, c int) { x1 = a } // arm64:"CSINC\tEQ", -"CSEL" - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` r1 = x1 @@ -311,8 +293,7 @@ func cmovinv(cond bool, a, b int) { x0 = ^b } // arm64:"CSINV\tNE", -"CSEL" - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` r0 = x0 @@ -322,8 +303,7 @@ func cmovinv(cond bool, a, b int) { x1 = a } // arm64:"CSINV\tEQ", -"CSEL" - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` r1 = x1 } @@ -337,8 +317,7 @@ func cmovneg(cond bool, a, b, c int) { x0 = -b } // arm64:"CSNEG\tNE", -"CSEL" - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` r0 = x0 @@ -348,8 +327,7 @@ func cmovneg(cond bool, a, b, c int) { x1 = a } // arm64:"CSNEG\tEQ", -"CSEL" - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` r1 = x1 } @@ -363,8 +341,7 @@ func cmovsetm(cond bool, x int) { x0 = 0 } // arm64:"CSETM\tNE", -"CSEL" - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZEROEQZ`, -`CZERONEZ` r0 = x0 @@ -374,8 +351,7 @@ func cmovsetm(cond bool, x int) { x1 = -1 } // arm64:"CSETM\tEQ", -"CSEL" - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZERONEZ`, -`CZEROEQZ` r1 = x1 } @@ -389,8 +365,7 @@ func cmovFcmp0(s, t float64, a, b int) { x0 = b + 1 } // arm64:"CSINC\tMI", -"CSEL" - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` r0 = x0 @@ -400,8 +375,7 @@ func cmovFcmp0(s, t float64, a, b int) { x1 = ^b } // arm64:"CSINV\tLS", -"CSEL" - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` r1 = x1 @@ -411,8 +385,7 @@ func cmovFcmp0(s, t float64, a, b int) { x2 = -b } // arm64:"CSNEG\tMI", -"CSEL" - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` r2 = x2 @@ -422,8 +395,7 @@ func cmovFcmp0(s, t float64, a, b int) { x3 = 0 } // arm64:"CSETM\tLS", -"CSEL" - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZEROEQZ`, -`CZERONEZ` r3 = x3 @@ -433,8 +405,7 @@ func cmovFcmp0(s, t float64, a, b int) { x4 = b + 1 } // arm64:"CSINC\tEQ", -"CSEL" - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` r4 = x4 @@ -444,8 +415,7 @@ func cmovFcmp0(s, t float64, a, b int) { x5 = b + 1 } // arm64:"CSINC\tNE", -"CSEL" - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` r5 = x5 } @@ -459,8 +429,7 @@ func cmovFcmp1(s, t float64, a, b int) { x0 = a } // arm64:"CSINC\tPL", -"CSEL" - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` r0 = x0 @@ -470,8 +439,7 @@ func cmovFcmp1(s, t float64, a, b int) { x1 = a } // arm64:"CSINV\tHI", -"CSEL" - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` r1 = x1 @@ -481,8 +449,7 @@ func cmovFcmp1(s, t float64, a, b int) { x2 = a } // arm64:"CSNEG\tPL", -"CSEL" - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` r2 = x2 @@ -492,8 +459,7 @@ func cmovFcmp1(s, t float64, a, b int) { x3 = -1 } // arm64:"CSETM\tHI", -"CSEL" - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZERONEZ`,-`CZEROEQZ` r3 = x3 @@ -503,8 +469,7 @@ func cmovFcmp1(s, t float64, a, b int) { x4 = a } // arm64:"CSINC\tNE", -"CSEL" - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` r4 = x4 @@ -514,8 +479,7 @@ func cmovFcmp1(s, t float64, a, b int) { x5 = a } // arm64:"CSINC\tEQ", -"CSEL" - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` r5 = x5 } @@ -526,8 +490,7 @@ func cmovzero1(c bool) int { x = 182 } // loong64:"MASKEQZ", -"MASKNEZ" - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZEROEQZ`, -`CZERONEZ` return x } @@ -538,8 +501,7 @@ func cmovzero2(c bool) int { x = 182 } // loong64:"MASKNEZ", -"MASKEQZ" - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZERONEZ`, -`CZEROEQZ` return x } @@ -548,14 +510,13 @@ func cmovzero2(c bool) int { // an extra load of 0 to a register on PPC64 by using R0 (which always // holds the value $0) instead. Verify both cases where either arg1 // or arg2 is zero. -func cmovzeroregZero11(a, b int) int { +func cmovzeroreg0(a, b int) int { x := 0 if a == b { x = a } // ppc64x:"ISEL\t[$]2, R[0-9]+, R0, R[0-9]+" - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZEROEQZ`,-`CZERONEZ` return x } @@ -566,8 +527,7 @@ func cmovzeroreg1(a, b int) int { x = 0 } // ppc64x:"ISEL\t[$]2, R0, R[0-9]+, R[0-9]+" - // riscv64/rva20u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZERONEZ`, -`CZEROEQZ` return x } @@ -628,7 +588,7 @@ func cmovmathhalveu(a uint, b bool) uint { return a } -func cmoveAddZero11(cond, a, b int) int { +func cmoveAddZero(cond, a, b int) int { if cond == 0 { a += b } @@ -636,7 +596,7 @@ func cmoveAddZero11(cond, a, b int) int { return a } -func cmoveAddNonZero11(cond, a, b int) int { +func cmoveAddNonZero(cond, a, b int) int { if cond != 0 { a += b } @@ -644,7 +604,7 @@ func cmoveAddNonZero11(cond, a, b int) int { return a } -func cmoveSubZero11(cond, a, b int) int { +func cmoveSubZero(cond, a, b int) int { if cond == 0 { a -= b } @@ -652,7 +612,7 @@ func cmoveSubZero11(cond, a, b int) int { return a } -func cmoveSubNonZero11(cond, a, b int) int { +func cmoveSubNonZero(cond, a, b int) int { if cond != 0 { a -= b } @@ -660,7 +620,7 @@ func cmoveSubNonZero11(cond, a, b int) int { return a } -func cmoveOrZero11(cond, a, b int) int { +func cmoveOrZero(cond, a, b int) int { if cond == 0 { a |= b } @@ -668,7 +628,7 @@ func cmoveOrZero11(cond, a, b int) int { return a } -func cmoveOrNonZero11(cond, a, b int) int { +func cmoveOrNonZero(cond, a, b int) int { if cond != 0 { a |= b } @@ -676,7 +636,7 @@ func cmoveOrNonZero11(cond, a, b int) int { return a } -func cmoveXorZero11(cond, a, b int) int { +func cmoveXorZero(cond, a, b int) int { if cond == 0 { a ^= b } @@ -684,7 +644,7 @@ func cmoveXorZero11(cond, a, b int) int { return a } -func cmoveXorNonZero11(cond, a, b int) int { +func cmoveXorNonZero(cond, a, b int) int { if cond != 0 { a ^= b } @@ -692,7 +652,7 @@ func cmoveXorNonZero11(cond, a, b int) int { return a } -func cmoveAndZero11(cond, a, b int) int { +func cmoveAndZero(cond, a, b int) int { if cond == 0 { a &= b } @@ -700,10 +660,133 @@ func cmoveAndZero11(cond, a, b int) int { return a } -func CondAndNonZero11(cond, a, b int) int { +func CondAndNonZero(cond, a, b int) int { if cond != 0 { a &= b } // riscv64/rva23u64:`CZERONEZ`, `AND`, `OR`, -`SNEZ`, -`CZEROEQZ` return a } + +// Immediate variants tests +func cmoveAddiZero(cond, a int) int { + if cond == 0 { + a += 42 + } + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZERONEZ`, `ADD`, -`SEQZ`, -`CZEROEQZ`, -`OR` + return a +} + +func cmoveAddiNonZero(cond, a int) int { + if cond != 0 { + a += 42 + } + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `ADD`, -`SNEZ`, -`CZERONEZ`, -`OR` + return a +} + +func cmoveOriZero(cond, a int) int { + if cond == 0 { + a |= 0xFF + } + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZERONEZ`, -`SEQZ`, -`CZEROEQZ` + return a +} + +func cmoveOriNonZero(cond, a int) int { + if cond != 0 { + a |= 0xFF + } + // riscv64/rva23u64:`CZEROEQZ`, -`SNEZ`, -`CZERONEZ` + return a +} + +func cmoveXoriZero(cond, a int) int { + if cond == 0 { + a ^= 0xFFFF + } + // riscv64/rva23u64:`CZERONEZ`, `XOR`, -`SEQZ`, -`CZEROEQZ`, -`OR` + return a +} + +func cmoveXoriNonZero(cond, a int) int { + if cond != 0 { + a ^= 0xFFFF + } + // riscv64/rva23u64:`CZEROEQZ`, `XOR`, -`SNEZ`, -`CZERONEZ`, -`OR` + return a +} + +func cmoveAndiZero(cond, a int) int { + if cond == 0 { + a &= 0xFF + } + // riscv64/rva23u64:`CZEROEQZ`, `AND`, `OR`, -`SEQZ`, -`CZERONEZ` + return a +} + +func cmoveAndiNonZero(cond, a int) int { + if cond != 0 { + a &= 0xFF + } + // riscv64/rva23u64:`CZERONEZ`, `AND`, `OR`, -`SNEZ`, -`CZEROEQZ` + return a +} + +// 32-bit immediate variant tests +func cmoveAddiwZero(cond int32, a int32) int32 { + if cond == 0 { + a += 42 + } + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZERONEZ`, `ADD`, -`SEQZ`, -`CZEROEQZ`, -`OR` + return a +} + +func cmoveAddiwNonZero(cond int32, a int32) int32 { + if cond != 0 { + a += 42 + } + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `ADD`, -`SNEZ`, -`CZERONEZ`, -`OR` + return a +} + +func cmoveAddwZero(cond int32, a, b int32) int32 { + if cond == 0 { + a += b + } + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZERONEZ`, `ADD`, -`SEQZ`, -`CZEROEQZ`, -`OR` + return a +} + +func cmoveAddwNonZero(cond int32, a, b int32) int32 { + if cond != 0 { + a += b + } + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `ADD`, -`SNEZ`, -`CZERONEZ`, -`OR` + return a +} + +func cmoveSubwZero(cond int32, a, b int32) int32 { + if cond == 0 { + a -= b + } + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZERONEZ`, `SUB`, -`SEQZ`, -`CZEROEQZ`, -`OR` + return a +} + +func cmoveSubwNonZero(cond int32, a, b int32) int32 { + if cond != 0 { + a -= b + } + // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` + // riscv64/rva23u64:`CZEROEQZ`, `SUB`, -`SNEZ`, -`CZERONEZ`, -`OR` + return a +} From 00604c69f2565ccd4b7e222a9519f5bb388c87a1 Mon Sep 17 00:00:00 2001 From: Xueqi Luo <1824368278@qq.com> Date: Tue, 21 Oct 2025 16:26:35 +0800 Subject: [PATCH 7/8] fix test case --- test/codegen/condmove.go | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/test/codegen/condmove.go b/test/codegen/condmove.go index b6d8a8cedeb3a5..6fc62cfc694970 100644 --- a/test/codegen/condmove.go +++ b/test/codegen/condmove.go @@ -668,12 +668,10 @@ func CondAndNonZero(cond, a, b int) int { return a } -// Immediate variants tests func cmoveAddiZero(cond, a int) int { if cond == 0 { a += 42 } - // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZERONEZ`, `ADD`, -`SEQZ`, -`CZEROEQZ`, -`OR` return a } @@ -682,7 +680,6 @@ func cmoveAddiNonZero(cond, a int) int { if cond != 0 { a += 42 } - // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZEROEQZ`, `ADD`, -`SNEZ`, -`CZERONEZ`, -`OR` return a } @@ -691,7 +688,6 @@ func cmoveOriZero(cond, a int) int { if cond == 0 { a |= 0xFF } - // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZERONEZ`, -`SEQZ`, -`CZEROEQZ` return a } @@ -741,7 +737,6 @@ func cmoveAddiwZero(cond int32, a int32) int32 { if cond == 0 { a += 42 } - // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZERONEZ`, `ADD`, -`SEQZ`, -`CZEROEQZ`, -`OR` return a } @@ -750,7 +745,6 @@ func cmoveAddiwNonZero(cond int32, a int32) int32 { if cond != 0 { a += 42 } - // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZEROEQZ`, `ADD`, -`SNEZ`, -`CZERONEZ`, -`OR` return a } @@ -759,7 +753,6 @@ func cmoveAddwZero(cond int32, a, b int32) int32 { if cond == 0 { a += b } - // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZERONEZ`, `ADD`, -`SEQZ`, -`CZEROEQZ`, -`OR` return a } @@ -768,7 +761,6 @@ func cmoveAddwNonZero(cond int32, a, b int32) int32 { if cond != 0 { a += b } - // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZEROEQZ`, `ADD`, -`SNEZ`, -`CZERONEZ`, -`OR` return a } @@ -777,7 +769,6 @@ func cmoveSubwZero(cond int32, a, b int32) int32 { if cond == 0 { a -= b } - // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZERONEZ`, `SUB`, -`SEQZ`, -`CZEROEQZ`, -`OR` return a } @@ -786,7 +777,6 @@ func cmoveSubwNonZero(cond int32, a, b int32) int32 { if cond != 0 { a -= b } - // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` // riscv64/rva23u64:`CZEROEQZ`, `SUB`, -`SNEZ`, -`CZERONEZ`, -`OR` return a } From 9e3f91a396349d2099030880c5985e97f66b9b10 Mon Sep 17 00:00:00 2001 From: Xueqi Luo <1824368278@qq.com> Date: Wed, 22 Oct 2025 17:11:15 +0800 Subject: [PATCH 8/8] add some rules --- .../compile/internal/ssa/_gen/RISCV64.rules | 6 + .../internal/ssa/_gen/RISCV64latelower.rules | 41 +- .../compile/internal/ssa/rewriteRISCV64.go | 130 +++++ .../internal/ssa/rewriteRISCV64latelower.go | 488 ++++-------------- test/codegen/condmove.go | 12 +- 5 files changed, 257 insertions(+), 420 deletions(-) diff --git a/src/cmd/compile/internal/ssa/_gen/RISCV64.rules b/src/cmd/compile/internal/ssa/_gen/RISCV64.rules index c5b052bbc20b31..ce4336dd0bccd2 100644 --- a/src/cmd/compile/internal/ssa/_gen/RISCV64.rules +++ b/src/cmd/compile/internal/ssa/_gen/RISCV64.rules @@ -853,3 +853,9 @@ // Zicond Extension for Integer Conditional Operations // General lowering rule: always lower CondSelect to OR(CZEROEQZ, CZERONEZ) form (CondSelect x y cond) && buildcfg.GORISCV64 >= 23 => (OR (CZEROEQZ x cond) (CZERONEZ y cond)) +(CZERO(EQ|NE)Z x (SNEZ y)) => (CZERO(EQ|NE)Z x y) +(CZERO(EQ|NE)Z x (SEQZ y)) => (CZERO(NE|EQ)Z x y) +(CZEROEQZ x x) => x +(CZERONEZ x x) => (MOVDconst [0]) +(CZERO(EQ|NE)Z (MOVDconst [0]) _) => (MOVDconst [0]) +(OR (MOVDconst [0]) x) => x diff --git a/src/cmd/compile/internal/ssa/_gen/RISCV64latelower.rules b/src/cmd/compile/internal/ssa/_gen/RISCV64latelower.rules index 16b6da6f4ec227..2ed08aa204bd58 100644 --- a/src/cmd/compile/internal/ssa/_gen/RISCV64latelower.rules +++ b/src/cmd/compile/internal/ssa/_gen/RISCV64latelower.rules @@ -27,49 +27,34 @@ // "Zicond" Extension for Integer Conditional Operations // Optimize specific patterns based on the unified OR(CZEROEQZ, CZERONEZ) form // (x == 0) ? x : y -> CZEROEQZ y x (when x is the condition) -(OR (CZEROEQZ x (SEQZ x)) (CZERONEZ y (SEQZ x))) && buildcfg.GORISCV64 >= 23 => (CZEROEQZ y x) +(OR (CZERONEZ x x) (CZEROEQZ y x)) => (CZEROEQZ y x) // (z == 0) ? ((OP x y)) : x => (OP x (CZERONEZ y z)) -(OR (CZEROEQZ ((ADD|SUB|OR|XOR|SUBW) x y) (SEQZ z)) (CZERONEZ x (SEQZ z))) && buildcfg.GORISCV64 >= 23 - => ((ADD|SUB|OR|XOR|SUBW) x (CZERONEZ y z)) +(OR (CZERONEZ ((ADD|SUB|OR|XOR|SUBW) x y) z) (CZEROEQZ x z)) => ((ADD|SUB|OR|XOR|SUBW) x (CZERONEZ y z)) // (z != 0) ? ((OP x y)) : x => (OP x (CZEROEQZ y z)) -(OR (CZEROEQZ ((ADD|SUB|OR|XOR|SUBW) x y) (SNEZ z)) (CZERONEZ x (SNEZ z))) && buildcfg.GORISCV64 >= 23 - => ((ADD|SUB|OR|XOR|SUBW) x (CZEROEQZ y z)) +(OR (CZEROEQZ ((ADD|SUB|OR|XOR|SUBW) x y) z) (CZERONEZ x z)) => ((ADD|SUB|OR|XOR|SUBW) x (CZEROEQZ y z)) // (z == 0) ? (x & y) : x => OR(AND x y, CZEROEQZ x z) -(OR (CZEROEQZ (AND x y) (SEQZ z)) (CZERONEZ x (SEQZ z))) && buildcfg.GORISCV64 >= 23 - => (OR (AND x y) (CZEROEQZ x z)) +(OR (CZERONEZ (AND x y) z) (CZEROEQZ x z)) => (OR (AND x y) (CZEROEQZ x z)) // (z != 0) ? (x & y) : x => OR(AND x y, CZERONEZ x z) -(OR (CZEROEQZ (AND x y) (SNEZ z)) (CZERONEZ x (SNEZ z))) && buildcfg.GORISCV64 >= 23 - => (OR (AND x y) (CZERONEZ x z)) +(OR (CZEROEQZ (AND x y) z) (CZERONEZ x z)) => (OR (AND x y) (CZERONEZ x z)) // (z == 0) ? (x & c) : x => OR(AND x c, CZEROEQZ x z) -(OR (CZEROEQZ (ANDI [c] x) (SEQZ z)) (CZERONEZ x (SEQZ z))) && buildcfg.GORISCV64 >= 23 - => (OR (AND x (MOVDconst [c])) (CZEROEQZ x z)) +(OR (CZERONEZ (ANDI [c] x) z) (CZEROEQZ x z)) => (OR (AND x (MOVDconst [c])) (CZEROEQZ x z)) // (z != 0) ? (x & c) : x => OR(AND x c, CZERONEZ x z) -(OR (CZEROEQZ (ANDI [c] x) (SNEZ z)) (CZERONEZ x (SNEZ z))) && buildcfg.GORISCV64 >= 23 - => (OR (AND x (MOVDconst [c])) (CZERONEZ x z)) +(OR (CZEROEQZ (ANDI [c] x) z) (CZERONEZ x z)) => (OR (AND x (MOVDconst [c])) (CZERONEZ x z)) // (z == 0) ? ((OPI [c] x)) : x => (OP x (CZERONEZ c z)) -(OR (CZEROEQZ ((ADDI|ORI|XORI) [c] x) (SEQZ z)) (CZERONEZ x (SEQZ z))) && buildcfg.GORISCV64 >= 23 - => ((ADD|OR|XOR) x (CZERONEZ (MOVDconst [c]) z)) +(OR (CZERONEZ ((ADDI|ORI|XORI) [c] x) z) (CZEROEQZ x z)) => ((ADD|OR|XOR) x (CZERONEZ (MOVDconst [c]) z)) // (z != 0) ? ((OPI [c] x)) : x => (OP x (CZEROEQZ c z)) -(OR (CZEROEQZ ((ADDI|ORI|XORI) [c] x) (SNEZ z)) (CZERONEZ x (SNEZ z))) && buildcfg.GORISCV64 >= 23 - => ((ADD|OR|XOR) x (CZEROEQZ (MOVDconst [c]) z)) +(OR (CZEROEQZ ((ADDI|ORI|XORI) [c] x) z) (CZERONEZ x z)) => ((ADD|OR|XOR) x (CZEROEQZ (MOVDconst [c]) z)) // (z == 0) ? (ADDIW [c] x) : x -(OR (CZEROEQZ (ADDIW [c] x) (SEQZ z)) (CZERONEZ x (SEQZ z))) && buildcfg.GORISCV64 >= 23 - => (ADD x (CZERONEZ (MOVDconst [int64(int32(c))]) z)) +(OR (CZERONEZ (ADDIW [c] x) z) (CZEROEQZ x z)) => (ADD x (CZERONEZ (MOVDconst [int64(int32(c))]) z)) // (z != 0) ? (ADDIW [c] x) : x -(OR (CZEROEQZ (ADDIW [c] x) (SNEZ z)) (CZERONEZ x (SNEZ z))) && buildcfg.GORISCV64 >= 23 - => (ADD x (CZEROEQZ (MOVDconst [int64(int32(c))]) z)) +(OR (CZEROEQZ (ADDIW [c] x) z) (CZERONEZ x z)) => (ADD x (CZEROEQZ (MOVDconst [int64(int32(c))]) z)) // (cond == 0) ? 0 : const => CZERONEZ const cond -(OR (CZEROEQZ (MOVDconst [0]) (SEQZ cond)) (CZERONEZ (MOVDconst [c]) (SEQZ cond))) && buildcfg.GORISCV64 >= 23 - => (CZERONEZ (MOVDconst [c]) cond) +(OR (CZERONEZ (MOVDconst [0]) cond) (CZEROEQZ (MOVDconst [c]) cond)) => (CZERONEZ (MOVDconst [c]) cond) // (cond != 0) ? 0 : const => CZEROEQZ const cond -(OR (CZEROEQZ (MOVDconst [0]) (SNEZ cond)) (CZERONEZ (MOVDconst [c]) (SNEZ cond))) && buildcfg.GORISCV64 >= 23 - => (CZEROEQZ (MOVDconst [c]) cond) - -// Constant propagation through CZERO(EQ|NE)Z -(CZERO(EQ|NE)Z (MOVDconst [0]) _) && buildcfg.GORISCV64 >= 23 => (MOVDconst [0]) +(OR (CZEROEQZ (MOVDconst [0]) cond) (CZERONEZ (MOVDconst [c]) cond)) => (CZEROEQZ (MOVDconst [c]) cond) diff --git a/src/cmd/compile/internal/ssa/rewriteRISCV64.go b/src/cmd/compile/internal/ssa/rewriteRISCV64.go index ca0874a97c2b3c..47b6879df4af35 100644 --- a/src/cmd/compile/internal/ssa/rewriteRISCV64.go +++ b/src/cmd/compile/internal/ssa/rewriteRISCV64.go @@ -513,6 +513,10 @@ func rewriteValueRISCV64(v *Value) bool { return rewriteValueRISCV64_OpRISCV64AND(v) case OpRISCV64ANDI: return rewriteValueRISCV64_OpRISCV64ANDI(v) + case OpRISCV64CZEROEQZ: + return rewriteValueRISCV64_OpRISCV64CZEROEQZ(v) + case OpRISCV64CZERONEZ: + return rewriteValueRISCV64_OpRISCV64CZERONEZ(v) case OpRISCV64FADDD: return rewriteValueRISCV64_OpRISCV64FADDD(v) case OpRISCV64FADDS: @@ -3581,6 +3585,119 @@ func rewriteValueRISCV64_OpRISCV64ANDI(v *Value) bool { } return false } +func rewriteValueRISCV64_OpRISCV64CZEROEQZ(v *Value) bool { + v_1 := v.Args[1] + v_0 := v.Args[0] + // match: (CZEROEQZ x (SNEZ y)) + // result: (CZEROEQZ x y) + for { + t := v.Type + x := v_0 + if v_1.Op != OpRISCV64SNEZ { + break + } + y := v_1.Args[0] + v.reset(OpRISCV64CZEROEQZ) + v.Type = t + v.AddArg2(x, y) + return true + } + // match: (CZEROEQZ x (SEQZ y)) + // result: (CZERONEZ x y) + for { + t := v.Type + x := v_0 + if v_1.Op != OpRISCV64SEQZ { + break + } + y := v_1.Args[0] + v.reset(OpRISCV64CZERONEZ) + v.Type = t + v.AddArg2(x, y) + return true + } + // match: (CZEROEQZ x x) + // result: x + for { + x := v_0 + if x != v_1 { + break + } + v.copyOf(x) + return true + } + // match: (CZEROEQZ (MOVDconst [0]) _) + // result: (MOVDconst [0]) + for { + t := v.Type + if v_0.Op != OpRISCV64MOVDconst || auxIntToInt64(v_0.AuxInt) != 0 { + break + } + v.reset(OpRISCV64MOVDconst) + v.Type = t + v.AuxInt = int64ToAuxInt(0) + return true + } + return false +} +func rewriteValueRISCV64_OpRISCV64CZERONEZ(v *Value) bool { + v_1 := v.Args[1] + v_0 := v.Args[0] + // match: (CZERONEZ x (SNEZ y)) + // result: (CZERONEZ x y) + for { + t := v.Type + x := v_0 + if v_1.Op != OpRISCV64SNEZ { + break + } + y := v_1.Args[0] + v.reset(OpRISCV64CZERONEZ) + v.Type = t + v.AddArg2(x, y) + return true + } + // match: (CZERONEZ x (SEQZ y)) + // result: (CZEROEQZ x y) + for { + t := v.Type + x := v_0 + if v_1.Op != OpRISCV64SEQZ { + break + } + y := v_1.Args[0] + v.reset(OpRISCV64CZEROEQZ) + v.Type = t + v.AddArg2(x, y) + return true + } + // match: (CZERONEZ x x) + // result: (MOVDconst [0]) + for { + t := v.Type + x := v_0 + if x != v_1 { + break + } + v.reset(OpRISCV64MOVDconst) + v.Type = t + v.AuxInt = int64ToAuxInt(0) + return true + } + // match: (CZERONEZ (MOVDconst [0]) _) + // result: (MOVDconst [0]) + for { + t := v.Type + if v_0.Op != OpRISCV64MOVDconst || auxIntToInt64(v_0.AuxInt) != 0 { + break + } + v.reset(OpRISCV64MOVDconst) + v.Type = t + v.AuxInt = int64ToAuxInt(0) + return true + } + return false +} func rewriteValueRISCV64_OpRISCV64FADDD(v *Value) bool { v_1 := v.Args[1] v_0 := v.Args[0] @@ -6976,6 +7093,19 @@ func rewriteValueRISCV64_OpRISCV64OR(v *Value) bool { v.copyOf(x) return true } + // match: (OR (MOVDconst [0]) x) + // result: x + for { + for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { + if v_0.Op != OpRISCV64MOVDconst || auxIntToInt64(v_0.AuxInt) != 0 { + continue + } + x := v_1 + v.copyOf(x) + return true + } + break + } return false } func rewriteValueRISCV64_OpRISCV64ORI(v *Value) bool { diff --git a/src/cmd/compile/internal/ssa/rewriteRISCV64latelower.go b/src/cmd/compile/internal/ssa/rewriteRISCV64latelower.go index bde84b639392e5..672e40ae4bd3c2 100644 --- a/src/cmd/compile/internal/ssa/rewriteRISCV64latelower.go +++ b/src/cmd/compile/internal/ssa/rewriteRISCV64latelower.go @@ -2,16 +2,10 @@ package ssa -import "internal/buildcfg" - func rewriteValueRISCV64latelower(v *Value) bool { switch v.Op { case OpRISCV64AND: return rewriteValueRISCV64latelower_OpRISCV64AND(v) - case OpRISCV64CZEROEQZ: - return rewriteValueRISCV64latelower_OpRISCV64CZEROEQZ(v) - case OpRISCV64CZERONEZ: - return rewriteValueRISCV64latelower_OpRISCV64CZERONEZ(v) case OpRISCV64NOT: return rewriteValueRISCV64latelower_OpRISCV64NOT(v) case OpRISCV64OR: @@ -47,40 +41,6 @@ func rewriteValueRISCV64latelower_OpRISCV64AND(v *Value) bool { } return false } -func rewriteValueRISCV64latelower_OpRISCV64CZEROEQZ(v *Value) bool { - v_0 := v.Args[0] - // match: (CZEROEQZ (MOVDconst [0]) _) - // cond: buildcfg.GORISCV64 >= 23 - // result: (MOVDconst [0]) - for { - t := v.Type - if v_0.Op != OpRISCV64MOVDconst || auxIntToInt64(v_0.AuxInt) != 0 || !(buildcfg.GORISCV64 >= 23) { - break - } - v.reset(OpRISCV64MOVDconst) - v.Type = t - v.AuxInt = int64ToAuxInt(0) - return true - } - return false -} -func rewriteValueRISCV64latelower_OpRISCV64CZERONEZ(v *Value) bool { - v_0 := v.Args[0] - // match: (CZERONEZ (MOVDconst [0]) _) - // cond: buildcfg.GORISCV64 >= 23 - // result: (MOVDconst [0]) - for { - t := v.Type - if v_0.Op != OpRISCV64MOVDconst || auxIntToInt64(v_0.AuxInt) != 0 || !(buildcfg.GORISCV64 >= 23) { - break - } - v.reset(OpRISCV64MOVDconst) - v.Type = t - v.AuxInt = int64ToAuxInt(0) - return true - } - return false -} func rewriteValueRISCV64latelower_OpRISCV64NOT(v *Value) bool { v_0 := v.Args[0] // match: (NOT (XOR x y)) @@ -117,25 +77,21 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { } break } - // match: (OR (CZEROEQZ x (SEQZ x)) (CZERONEZ y (SEQZ x))) - // cond: buildcfg.GORISCV64 >= 23 + // match: (OR (CZERONEZ x x) (CZEROEQZ y x)) // result: (CZEROEQZ y x) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { - if v_0.Op != OpRISCV64CZEROEQZ { + if v_0.Op != OpRISCV64CZERONEZ { continue } t := v_0.Type - _ = v_0.Args[1] - x := v_0.Args[0] - v_0_1 := v_0.Args[1] - if v_0_1.Op != OpRISCV64SEQZ || x != v_0_1.Args[0] || v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { + x := v_0.Args[1] + if x != v_0.Args[0] || v_1.Op != OpRISCV64CZEROEQZ || v_1.Type != t { continue } _ = v_1.Args[1] y := v_1.Args[0] - v_1_1 := v_1.Args[1] - if v_1_1.Op != OpRISCV64SEQZ || x != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + if x != v_1.Args[1] { continue } v.reset(OpRISCV64CZEROEQZ) @@ -145,16 +101,15 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { } break } - // match: (OR (CZEROEQZ (ADD x y) (SEQZ z)) (CZERONEZ x (SEQZ z))) - // cond: buildcfg.GORISCV64 >= 23 + // match: (OR (CZERONEZ (ADD x y) z) (CZEROEQZ x z)) // result: (ADD x (CZERONEZ y z)) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { - if v_0.Op != OpRISCV64CZEROEQZ { + if v_0.Op != OpRISCV64CZERONEZ { continue } t := v_0.Type - _ = v_0.Args[1] + z := v_0.Args[1] v_0_0 := v_0.Args[0] if v_0_0.Op != OpRISCV64ADD { continue @@ -165,20 +120,11 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { for _i1 := 0; _i1 <= 1; _i1, v_0_0_0, v_0_0_1 = _i1+1, v_0_0_1, v_0_0_0 { x := v_0_0_0 y := v_0_0_1 - v_0_1 := v_0.Args[1] - if v_0_1.Op != OpRISCV64SEQZ { - continue - } - z := v_0_1.Args[0] - if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { + if v_1.Op != OpRISCV64CZEROEQZ || v_1.Type != t { continue } _ = v_1.Args[1] - if x != v_1.Args[0] { - continue - } - v_1_1 := v_1.Args[1] - if v_1_1.Op != OpRISCV64SEQZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + if x != v_1.Args[0] || z != v_1.Args[1] { continue } v.reset(OpRISCV64ADD) @@ -190,36 +136,26 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { } break } - // match: (OR (CZEROEQZ (SUB x y) (SEQZ z)) (CZERONEZ x (SEQZ z))) - // cond: buildcfg.GORISCV64 >= 23 + // match: (OR (CZERONEZ (SUB x y) z) (CZEROEQZ x z)) // result: (SUB x (CZERONEZ y z)) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { - if v_0.Op != OpRISCV64CZEROEQZ { + if v_0.Op != OpRISCV64CZERONEZ { continue } t := v_0.Type - _ = v_0.Args[1] + z := v_0.Args[1] v_0_0 := v_0.Args[0] if v_0_0.Op != OpRISCV64SUB { continue } y := v_0_0.Args[1] x := v_0_0.Args[0] - v_0_1 := v_0.Args[1] - if v_0_1.Op != OpRISCV64SEQZ { - continue - } - z := v_0_1.Args[0] - if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { + if v_1.Op != OpRISCV64CZEROEQZ || v_1.Type != t { continue } _ = v_1.Args[1] - if x != v_1.Args[0] { - continue - } - v_1_1 := v_1.Args[1] - if v_1_1.Op != OpRISCV64SEQZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + if x != v_1.Args[0] || z != v_1.Args[1] { continue } v.reset(OpRISCV64SUB) @@ -230,16 +166,15 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { } break } - // match: (OR (CZEROEQZ (OR x y) (SEQZ z)) (CZERONEZ x (SEQZ z))) - // cond: buildcfg.GORISCV64 >= 23 + // match: (OR (CZERONEZ (OR x y) z) (CZEROEQZ x z)) // result: (OR x (CZERONEZ y z)) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { - if v_0.Op != OpRISCV64CZEROEQZ { + if v_0.Op != OpRISCV64CZERONEZ { continue } t := v_0.Type - _ = v_0.Args[1] + z := v_0.Args[1] v_0_0 := v_0.Args[0] if v_0_0.Op != OpRISCV64OR { continue @@ -250,20 +185,11 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { for _i1 := 0; _i1 <= 1; _i1, v_0_0_0, v_0_0_1 = _i1+1, v_0_0_1, v_0_0_0 { x := v_0_0_0 y := v_0_0_1 - v_0_1 := v_0.Args[1] - if v_0_1.Op != OpRISCV64SEQZ { - continue - } - z := v_0_1.Args[0] - if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { + if v_1.Op != OpRISCV64CZEROEQZ || v_1.Type != t { continue } _ = v_1.Args[1] - if x != v_1.Args[0] { - continue - } - v_1_1 := v_1.Args[1] - if v_1_1.Op != OpRISCV64SEQZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + if x != v_1.Args[0] || z != v_1.Args[1] { continue } v.reset(OpRISCV64OR) @@ -275,16 +201,15 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { } break } - // match: (OR (CZEROEQZ (XOR x y) (SEQZ z)) (CZERONEZ x (SEQZ z))) - // cond: buildcfg.GORISCV64 >= 23 + // match: (OR (CZERONEZ (XOR x y) z) (CZEROEQZ x z)) // result: (XOR x (CZERONEZ y z)) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { - if v_0.Op != OpRISCV64CZEROEQZ { + if v_0.Op != OpRISCV64CZERONEZ { continue } t := v_0.Type - _ = v_0.Args[1] + z := v_0.Args[1] v_0_0 := v_0.Args[0] if v_0_0.Op != OpRISCV64XOR { continue @@ -295,20 +220,11 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { for _i1 := 0; _i1 <= 1; _i1, v_0_0_0, v_0_0_1 = _i1+1, v_0_0_1, v_0_0_0 { x := v_0_0_0 y := v_0_0_1 - v_0_1 := v_0.Args[1] - if v_0_1.Op != OpRISCV64SEQZ { - continue - } - z := v_0_1.Args[0] - if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { + if v_1.Op != OpRISCV64CZEROEQZ || v_1.Type != t { continue } _ = v_1.Args[1] - if x != v_1.Args[0] { - continue - } - v_1_1 := v_1.Args[1] - if v_1_1.Op != OpRISCV64SEQZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + if x != v_1.Args[0] || z != v_1.Args[1] { continue } v.reset(OpRISCV64XOR) @@ -320,36 +236,26 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { } break } - // match: (OR (CZEROEQZ (SUBW x y) (SEQZ z)) (CZERONEZ x (SEQZ z))) - // cond: buildcfg.GORISCV64 >= 23 + // match: (OR (CZERONEZ (SUBW x y) z) (CZEROEQZ x z)) // result: (SUBW x (CZERONEZ y z)) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { - if v_0.Op != OpRISCV64CZEROEQZ { + if v_0.Op != OpRISCV64CZERONEZ { continue } t := v_0.Type - _ = v_0.Args[1] + z := v_0.Args[1] v_0_0 := v_0.Args[0] if v_0_0.Op != OpRISCV64SUBW { continue } y := v_0_0.Args[1] x := v_0_0.Args[0] - v_0_1 := v_0.Args[1] - if v_0_1.Op != OpRISCV64SEQZ { - continue - } - z := v_0_1.Args[0] - if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { + if v_1.Op != OpRISCV64CZEROEQZ || v_1.Type != t { continue } _ = v_1.Args[1] - if x != v_1.Args[0] { - continue - } - v_1_1 := v_1.Args[1] - if v_1_1.Op != OpRISCV64SEQZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + if x != v_1.Args[0] || z != v_1.Args[1] { continue } v.reset(OpRISCV64SUBW) @@ -360,8 +266,7 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { } break } - // match: (OR (CZEROEQZ (ADD x y) (SNEZ z)) (CZERONEZ x (SNEZ z))) - // cond: buildcfg.GORISCV64 >= 23 + // match: (OR (CZEROEQZ (ADD x y) z) (CZERONEZ x z)) // result: (ADD x (CZEROEQZ y z)) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { @@ -369,7 +274,7 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { continue } t := v_0.Type - _ = v_0.Args[1] + z := v_0.Args[1] v_0_0 := v_0.Args[0] if v_0_0.Op != OpRISCV64ADD { continue @@ -380,20 +285,11 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { for _i1 := 0; _i1 <= 1; _i1, v_0_0_0, v_0_0_1 = _i1+1, v_0_0_1, v_0_0_0 { x := v_0_0_0 y := v_0_0_1 - v_0_1 := v_0.Args[1] - if v_0_1.Op != OpRISCV64SNEZ { - continue - } - z := v_0_1.Args[0] if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { continue } _ = v_1.Args[1] - if x != v_1.Args[0] { - continue - } - v_1_1 := v_1.Args[1] - if v_1_1.Op != OpRISCV64SNEZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + if x != v_1.Args[0] || z != v_1.Args[1] { continue } v.reset(OpRISCV64ADD) @@ -405,8 +301,7 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { } break } - // match: (OR (CZEROEQZ (SUB x y) (SNEZ z)) (CZERONEZ x (SNEZ z))) - // cond: buildcfg.GORISCV64 >= 23 + // match: (OR (CZEROEQZ (SUB x y) z) (CZERONEZ x z)) // result: (SUB x (CZEROEQZ y z)) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { @@ -414,27 +309,18 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { continue } t := v_0.Type - _ = v_0.Args[1] + z := v_0.Args[1] v_0_0 := v_0.Args[0] if v_0_0.Op != OpRISCV64SUB { continue } y := v_0_0.Args[1] x := v_0_0.Args[0] - v_0_1 := v_0.Args[1] - if v_0_1.Op != OpRISCV64SNEZ { - continue - } - z := v_0_1.Args[0] if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { continue } _ = v_1.Args[1] - if x != v_1.Args[0] { - continue - } - v_1_1 := v_1.Args[1] - if v_1_1.Op != OpRISCV64SNEZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + if x != v_1.Args[0] || z != v_1.Args[1] { continue } v.reset(OpRISCV64SUB) @@ -445,8 +331,7 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { } break } - // match: (OR (CZEROEQZ (OR x y) (SNEZ z)) (CZERONEZ x (SNEZ z))) - // cond: buildcfg.GORISCV64 >= 23 + // match: (OR (CZEROEQZ (OR x y) z) (CZERONEZ x z)) // result: (OR x (CZEROEQZ y z)) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { @@ -454,7 +339,7 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { continue } t := v_0.Type - _ = v_0.Args[1] + z := v_0.Args[1] v_0_0 := v_0.Args[0] if v_0_0.Op != OpRISCV64OR { continue @@ -465,20 +350,11 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { for _i1 := 0; _i1 <= 1; _i1, v_0_0_0, v_0_0_1 = _i1+1, v_0_0_1, v_0_0_0 { x := v_0_0_0 y := v_0_0_1 - v_0_1 := v_0.Args[1] - if v_0_1.Op != OpRISCV64SNEZ { - continue - } - z := v_0_1.Args[0] if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { continue } _ = v_1.Args[1] - if x != v_1.Args[0] { - continue - } - v_1_1 := v_1.Args[1] - if v_1_1.Op != OpRISCV64SNEZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + if x != v_1.Args[0] || z != v_1.Args[1] { continue } v.reset(OpRISCV64OR) @@ -490,8 +366,7 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { } break } - // match: (OR (CZEROEQZ (XOR x y) (SNEZ z)) (CZERONEZ x (SNEZ z))) - // cond: buildcfg.GORISCV64 >= 23 + // match: (OR (CZEROEQZ (XOR x y) z) (CZERONEZ x z)) // result: (XOR x (CZEROEQZ y z)) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { @@ -499,7 +374,7 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { continue } t := v_0.Type - _ = v_0.Args[1] + z := v_0.Args[1] v_0_0 := v_0.Args[0] if v_0_0.Op != OpRISCV64XOR { continue @@ -510,20 +385,11 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { for _i1 := 0; _i1 <= 1; _i1, v_0_0_0, v_0_0_1 = _i1+1, v_0_0_1, v_0_0_0 { x := v_0_0_0 y := v_0_0_1 - v_0_1 := v_0.Args[1] - if v_0_1.Op != OpRISCV64SNEZ { - continue - } - z := v_0_1.Args[0] if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { continue } _ = v_1.Args[1] - if x != v_1.Args[0] { - continue - } - v_1_1 := v_1.Args[1] - if v_1_1.Op != OpRISCV64SNEZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + if x != v_1.Args[0] || z != v_1.Args[1] { continue } v.reset(OpRISCV64XOR) @@ -535,8 +401,7 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { } break } - // match: (OR (CZEROEQZ (SUBW x y) (SNEZ z)) (CZERONEZ x (SNEZ z))) - // cond: buildcfg.GORISCV64 >= 23 + // match: (OR (CZEROEQZ (SUBW x y) z) (CZERONEZ x z)) // result: (SUBW x (CZEROEQZ y z)) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { @@ -544,27 +409,18 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { continue } t := v_0.Type - _ = v_0.Args[1] + z := v_0.Args[1] v_0_0 := v_0.Args[0] if v_0_0.Op != OpRISCV64SUBW { continue } y := v_0_0.Args[1] x := v_0_0.Args[0] - v_0_1 := v_0.Args[1] - if v_0_1.Op != OpRISCV64SNEZ { - continue - } - z := v_0_1.Args[0] if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { continue } _ = v_1.Args[1] - if x != v_1.Args[0] { - continue - } - v_1_1 := v_1.Args[1] - if v_1_1.Op != OpRISCV64SNEZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + if x != v_1.Args[0] || z != v_1.Args[1] { continue } v.reset(OpRISCV64SUBW) @@ -575,16 +431,15 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { } break } - // match: (OR (CZEROEQZ (AND x y) (SEQZ z)) (CZERONEZ x (SEQZ z))) - // cond: buildcfg.GORISCV64 >= 23 + // match: (OR (CZERONEZ (AND x y) z) (CZEROEQZ x z)) // result: (OR (AND x y) (CZEROEQZ x z)) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { - if v_0.Op != OpRISCV64CZEROEQZ { + if v_0.Op != OpRISCV64CZERONEZ { continue } t := v_0.Type - _ = v_0.Args[1] + z := v_0.Args[1] v_0_0 := v_0.Args[0] if v_0_0.Op != OpRISCV64AND { continue @@ -595,20 +450,11 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { for _i1 := 0; _i1 <= 1; _i1, v_0_0_0, v_0_0_1 = _i1+1, v_0_0_1, v_0_0_0 { x := v_0_0_0 y := v_0_0_1 - v_0_1 := v_0.Args[1] - if v_0_1.Op != OpRISCV64SEQZ { - continue - } - z := v_0_1.Args[0] - if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { + if v_1.Op != OpRISCV64CZEROEQZ || v_1.Type != t { continue } _ = v_1.Args[1] - if x != v_1.Args[0] { - continue - } - v_1_1 := v_1.Args[1] - if v_1_1.Op != OpRISCV64SEQZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + if x != v_1.Args[0] || z != v_1.Args[1] { continue } v.reset(OpRISCV64OR) @@ -622,8 +468,7 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { } break } - // match: (OR (CZEROEQZ (AND x y) (SNEZ z)) (CZERONEZ x (SNEZ z))) - // cond: buildcfg.GORISCV64 >= 23 + // match: (OR (CZEROEQZ (AND x y) z) (CZERONEZ x z)) // result: (OR (AND x y) (CZERONEZ x z)) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { @@ -631,7 +476,7 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { continue } t := v_0.Type - _ = v_0.Args[1] + z := v_0.Args[1] v_0_0 := v_0.Args[0] if v_0_0.Op != OpRISCV64AND { continue @@ -642,20 +487,11 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { for _i1 := 0; _i1 <= 1; _i1, v_0_0_0, v_0_0_1 = _i1+1, v_0_0_1, v_0_0_0 { x := v_0_0_0 y := v_0_0_1 - v_0_1 := v_0.Args[1] - if v_0_1.Op != OpRISCV64SNEZ { - continue - } - z := v_0_1.Args[0] if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { continue } _ = v_1.Args[1] - if x != v_1.Args[0] { - continue - } - v_1_1 := v_1.Args[1] - if v_1_1.Op != OpRISCV64SNEZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + if x != v_1.Args[0] || z != v_1.Args[1] { continue } v.reset(OpRISCV64OR) @@ -669,36 +505,26 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { } break } - // match: (OR (CZEROEQZ (ANDI [c] x) (SEQZ z)) (CZERONEZ x (SEQZ z))) - // cond: buildcfg.GORISCV64 >= 23 + // match: (OR (CZERONEZ (ANDI [c] x) z) (CZEROEQZ x z)) // result: (OR (AND x (MOVDconst [c])) (CZEROEQZ x z)) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { - if v_0.Op != OpRISCV64CZEROEQZ { + if v_0.Op != OpRISCV64CZERONEZ { continue } t := v_0.Type - _ = v_0.Args[1] + z := v_0.Args[1] v_0_0 := v_0.Args[0] if v_0_0.Op != OpRISCV64ANDI { continue } c := auxIntToInt64(v_0_0.AuxInt) x := v_0_0.Args[0] - v_0_1 := v_0.Args[1] - if v_0_1.Op != OpRISCV64SEQZ { - continue - } - z := v_0_1.Args[0] - if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { + if v_1.Op != OpRISCV64CZEROEQZ || v_1.Type != t { continue } _ = v_1.Args[1] - if x != v_1.Args[0] { - continue - } - v_1_1 := v_1.Args[1] - if v_1_1.Op != OpRISCV64SEQZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + if x != v_1.Args[0] || z != v_1.Args[1] { continue } v.reset(OpRISCV64OR) @@ -713,8 +539,7 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { } break } - // match: (OR (CZEROEQZ (ANDI [c] x) (SNEZ z)) (CZERONEZ x (SNEZ z))) - // cond: buildcfg.GORISCV64 >= 23 + // match: (OR (CZEROEQZ (ANDI [c] x) z) (CZERONEZ x z)) // result: (OR (AND x (MOVDconst [c])) (CZERONEZ x z)) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { @@ -722,27 +547,18 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { continue } t := v_0.Type - _ = v_0.Args[1] + z := v_0.Args[1] v_0_0 := v_0.Args[0] if v_0_0.Op != OpRISCV64ANDI { continue } c := auxIntToInt64(v_0_0.AuxInt) x := v_0_0.Args[0] - v_0_1 := v_0.Args[1] - if v_0_1.Op != OpRISCV64SNEZ { - continue - } - z := v_0_1.Args[0] if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { continue } _ = v_1.Args[1] - if x != v_1.Args[0] { - continue - } - v_1_1 := v_1.Args[1] - if v_1_1.Op != OpRISCV64SNEZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + if x != v_1.Args[0] || z != v_1.Args[1] { continue } v.reset(OpRISCV64OR) @@ -757,36 +573,26 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { } break } - // match: (OR (CZEROEQZ (ADDI [c] x) (SEQZ z)) (CZERONEZ x (SEQZ z))) - // cond: buildcfg.GORISCV64 >= 23 + // match: (OR (CZERONEZ (ADDI [c] x) z) (CZEROEQZ x z)) // result: (ADD x (CZERONEZ (MOVDconst [c]) z)) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { - if v_0.Op != OpRISCV64CZEROEQZ { + if v_0.Op != OpRISCV64CZERONEZ { continue } t := v_0.Type - _ = v_0.Args[1] + z := v_0.Args[1] v_0_0 := v_0.Args[0] if v_0_0.Op != OpRISCV64ADDI { continue } c := auxIntToInt64(v_0_0.AuxInt) x := v_0_0.Args[0] - v_0_1 := v_0.Args[1] - if v_0_1.Op != OpRISCV64SEQZ { - continue - } - z := v_0_1.Args[0] - if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { + if v_1.Op != OpRISCV64CZEROEQZ || v_1.Type != t { continue } _ = v_1.Args[1] - if x != v_1.Args[0] { - continue - } - v_1_1 := v_1.Args[1] - if v_1_1.Op != OpRISCV64SEQZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + if x != v_1.Args[0] || z != v_1.Args[1] { continue } v.reset(OpRISCV64ADD) @@ -799,36 +605,26 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { } break } - // match: (OR (CZEROEQZ (ORI [c] x) (SEQZ z)) (CZERONEZ x (SEQZ z))) - // cond: buildcfg.GORISCV64 >= 23 + // match: (OR (CZERONEZ (ORI [c] x) z) (CZEROEQZ x z)) // result: (OR x (CZERONEZ (MOVDconst [c]) z)) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { - if v_0.Op != OpRISCV64CZEROEQZ { + if v_0.Op != OpRISCV64CZERONEZ { continue } t := v_0.Type - _ = v_0.Args[1] + z := v_0.Args[1] v_0_0 := v_0.Args[0] if v_0_0.Op != OpRISCV64ORI { continue } c := auxIntToInt64(v_0_0.AuxInt) x := v_0_0.Args[0] - v_0_1 := v_0.Args[1] - if v_0_1.Op != OpRISCV64SEQZ { - continue - } - z := v_0_1.Args[0] - if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { + if v_1.Op != OpRISCV64CZEROEQZ || v_1.Type != t { continue } _ = v_1.Args[1] - if x != v_1.Args[0] { - continue - } - v_1_1 := v_1.Args[1] - if v_1_1.Op != OpRISCV64SEQZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + if x != v_1.Args[0] || z != v_1.Args[1] { continue } v.reset(OpRISCV64OR) @@ -841,36 +637,26 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { } break } - // match: (OR (CZEROEQZ (XORI [c] x) (SEQZ z)) (CZERONEZ x (SEQZ z))) - // cond: buildcfg.GORISCV64 >= 23 + // match: (OR (CZERONEZ (XORI [c] x) z) (CZEROEQZ x z)) // result: (XOR x (CZERONEZ (MOVDconst [c]) z)) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { - if v_0.Op != OpRISCV64CZEROEQZ { + if v_0.Op != OpRISCV64CZERONEZ { continue } t := v_0.Type - _ = v_0.Args[1] + z := v_0.Args[1] v_0_0 := v_0.Args[0] if v_0_0.Op != OpRISCV64XORI { continue } c := auxIntToInt64(v_0_0.AuxInt) x := v_0_0.Args[0] - v_0_1 := v_0.Args[1] - if v_0_1.Op != OpRISCV64SEQZ { - continue - } - z := v_0_1.Args[0] - if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { + if v_1.Op != OpRISCV64CZEROEQZ || v_1.Type != t { continue } _ = v_1.Args[1] - if x != v_1.Args[0] { - continue - } - v_1_1 := v_1.Args[1] - if v_1_1.Op != OpRISCV64SEQZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + if x != v_1.Args[0] || z != v_1.Args[1] { continue } v.reset(OpRISCV64XOR) @@ -883,8 +669,7 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { } break } - // match: (OR (CZEROEQZ (ADDI [c] x) (SNEZ z)) (CZERONEZ x (SNEZ z))) - // cond: buildcfg.GORISCV64 >= 23 + // match: (OR (CZEROEQZ (ADDI [c] x) z) (CZERONEZ x z)) // result: (ADD x (CZEROEQZ (MOVDconst [c]) z)) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { @@ -892,27 +677,18 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { continue } t := v_0.Type - _ = v_0.Args[1] + z := v_0.Args[1] v_0_0 := v_0.Args[0] if v_0_0.Op != OpRISCV64ADDI { continue } c := auxIntToInt64(v_0_0.AuxInt) x := v_0_0.Args[0] - v_0_1 := v_0.Args[1] - if v_0_1.Op != OpRISCV64SNEZ { - continue - } - z := v_0_1.Args[0] if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { continue } _ = v_1.Args[1] - if x != v_1.Args[0] { - continue - } - v_1_1 := v_1.Args[1] - if v_1_1.Op != OpRISCV64SNEZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + if x != v_1.Args[0] || z != v_1.Args[1] { continue } v.reset(OpRISCV64ADD) @@ -925,8 +701,7 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { } break } - // match: (OR (CZEROEQZ (ORI [c] x) (SNEZ z)) (CZERONEZ x (SNEZ z))) - // cond: buildcfg.GORISCV64 >= 23 + // match: (OR (CZEROEQZ (ORI [c] x) z) (CZERONEZ x z)) // result: (OR x (CZEROEQZ (MOVDconst [c]) z)) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { @@ -934,27 +709,18 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { continue } t := v_0.Type - _ = v_0.Args[1] + z := v_0.Args[1] v_0_0 := v_0.Args[0] if v_0_0.Op != OpRISCV64ORI { continue } c := auxIntToInt64(v_0_0.AuxInt) x := v_0_0.Args[0] - v_0_1 := v_0.Args[1] - if v_0_1.Op != OpRISCV64SNEZ { - continue - } - z := v_0_1.Args[0] if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { continue } _ = v_1.Args[1] - if x != v_1.Args[0] { - continue - } - v_1_1 := v_1.Args[1] - if v_1_1.Op != OpRISCV64SNEZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + if x != v_1.Args[0] || z != v_1.Args[1] { continue } v.reset(OpRISCV64OR) @@ -967,8 +733,7 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { } break } - // match: (OR (CZEROEQZ (XORI [c] x) (SNEZ z)) (CZERONEZ x (SNEZ z))) - // cond: buildcfg.GORISCV64 >= 23 + // match: (OR (CZEROEQZ (XORI [c] x) z) (CZERONEZ x z)) // result: (XOR x (CZEROEQZ (MOVDconst [c]) z)) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { @@ -976,27 +741,18 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { continue } t := v_0.Type - _ = v_0.Args[1] + z := v_0.Args[1] v_0_0 := v_0.Args[0] if v_0_0.Op != OpRISCV64XORI { continue } c := auxIntToInt64(v_0_0.AuxInt) x := v_0_0.Args[0] - v_0_1 := v_0.Args[1] - if v_0_1.Op != OpRISCV64SNEZ { - continue - } - z := v_0_1.Args[0] if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { continue } _ = v_1.Args[1] - if x != v_1.Args[0] { - continue - } - v_1_1 := v_1.Args[1] - if v_1_1.Op != OpRISCV64SNEZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + if x != v_1.Args[0] || z != v_1.Args[1] { continue } v.reset(OpRISCV64XOR) @@ -1009,36 +765,26 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { } break } - // match: (OR (CZEROEQZ (ADDIW [c] x) (SEQZ z)) (CZERONEZ x (SEQZ z))) - // cond: buildcfg.GORISCV64 >= 23 + // match: (OR (CZERONEZ (ADDIW [c] x) z) (CZEROEQZ x z)) // result: (ADD x (CZERONEZ (MOVDconst [int64(int32(c))]) z)) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { - if v_0.Op != OpRISCV64CZEROEQZ { + if v_0.Op != OpRISCV64CZERONEZ { continue } t := v_0.Type - _ = v_0.Args[1] + z := v_0.Args[1] v_0_0 := v_0.Args[0] if v_0_0.Op != OpRISCV64ADDIW { continue } c := auxIntToInt64(v_0_0.AuxInt) x := v_0_0.Args[0] - v_0_1 := v_0.Args[1] - if v_0_1.Op != OpRISCV64SEQZ { - continue - } - z := v_0_1.Args[0] - if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { + if v_1.Op != OpRISCV64CZEROEQZ || v_1.Type != t { continue } _ = v_1.Args[1] - if x != v_1.Args[0] { - continue - } - v_1_1 := v_1.Args[1] - if v_1_1.Op != OpRISCV64SEQZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + if x != v_1.Args[0] || z != v_1.Args[1] { continue } v.reset(OpRISCV64ADD) @@ -1051,8 +797,7 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { } break } - // match: (OR (CZEROEQZ (ADDIW [c] x) (SNEZ z)) (CZERONEZ x (SNEZ z))) - // cond: buildcfg.GORISCV64 >= 23 + // match: (OR (CZEROEQZ (ADDIW [c] x) z) (CZERONEZ x z)) // result: (ADD x (CZEROEQZ (MOVDconst [int64(int32(c))]) z)) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { @@ -1060,27 +805,18 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { continue } t := v_0.Type - _ = v_0.Args[1] + z := v_0.Args[1] v_0_0 := v_0.Args[0] if v_0_0.Op != OpRISCV64ADDIW { continue } c := auxIntToInt64(v_0_0.AuxInt) x := v_0_0.Args[0] - v_0_1 := v_0.Args[1] - if v_0_1.Op != OpRISCV64SNEZ { - continue - } - z := v_0_1.Args[0] if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { continue } _ = v_1.Args[1] - if x != v_1.Args[0] { - continue - } - v_1_1 := v_1.Args[1] - if v_1_1.Op != OpRISCV64SNEZ || z != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + if x != v_1.Args[0] || z != v_1.Args[1] { continue } v.reset(OpRISCV64ADD) @@ -1093,26 +829,17 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { } break } - // match: (OR (CZEROEQZ (MOVDconst [0]) (SEQZ cond)) (CZERONEZ (MOVDconst [c]) (SEQZ cond))) - // cond: buildcfg.GORISCV64 >= 23 + // match: (OR (CZERONEZ (MOVDconst [0]) cond) (CZEROEQZ (MOVDconst [c]) cond)) // result: (CZERONEZ (MOVDconst [c]) cond) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { - if v_0.Op != OpRISCV64CZEROEQZ { + if v_0.Op != OpRISCV64CZERONEZ { continue } t := v_0.Type - _ = v_0.Args[1] + cond := v_0.Args[1] v_0_0 := v_0.Args[0] - if v_0_0.Op != OpRISCV64MOVDconst || auxIntToInt64(v_0_0.AuxInt) != 0 { - continue - } - v_0_1 := v_0.Args[1] - if v_0_1.Op != OpRISCV64SEQZ { - continue - } - cond := v_0_1.Args[0] - if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { + if v_0_0.Op != OpRISCV64MOVDconst || auxIntToInt64(v_0_0.AuxInt) != 0 || v_1.Op != OpRISCV64CZEROEQZ || v_1.Type != t { continue } _ = v_1.Args[1] @@ -1121,8 +848,7 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { continue } c := auxIntToInt64(v_1_0.AuxInt) - v_1_1 := v_1.Args[1] - if v_1_1.Op != OpRISCV64SEQZ || cond != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + if cond != v_1.Args[1] { continue } v.reset(OpRISCV64CZERONEZ) @@ -1134,8 +860,7 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { } break } - // match: (OR (CZEROEQZ (MOVDconst [0]) (SNEZ cond)) (CZERONEZ (MOVDconst [c]) (SNEZ cond))) - // cond: buildcfg.GORISCV64 >= 23 + // match: (OR (CZEROEQZ (MOVDconst [0]) cond) (CZERONEZ (MOVDconst [c]) cond)) // result: (CZEROEQZ (MOVDconst [c]) cond) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { @@ -1143,17 +868,9 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { continue } t := v_0.Type - _ = v_0.Args[1] + cond := v_0.Args[1] v_0_0 := v_0.Args[0] - if v_0_0.Op != OpRISCV64MOVDconst || auxIntToInt64(v_0_0.AuxInt) != 0 { - continue - } - v_0_1 := v_0.Args[1] - if v_0_1.Op != OpRISCV64SNEZ { - continue - } - cond := v_0_1.Args[0] - if v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { + if v_0_0.Op != OpRISCV64MOVDconst || auxIntToInt64(v_0_0.AuxInt) != 0 || v_1.Op != OpRISCV64CZERONEZ || v_1.Type != t { continue } _ = v_1.Args[1] @@ -1162,8 +879,7 @@ func rewriteValueRISCV64latelower_OpRISCV64OR(v *Value) bool { continue } c := auxIntToInt64(v_1_0.AuxInt) - v_1_1 := v_1.Args[1] - if v_1_1.Op != OpRISCV64SNEZ || cond != v_1_1.Args[0] || !(buildcfg.GORISCV64 >= 23) { + if cond != v_1.Args[1] { continue } v.reset(OpRISCV64CZEROEQZ) diff --git a/test/codegen/condmove.go b/test/codegen/condmove.go index 6fc62cfc694970..f6f0f687a443af 100644 --- a/test/codegen/condmove.go +++ b/test/codegen/condmove.go @@ -127,7 +127,7 @@ func cmovfloatint2(x, y float64) float64 { // ppc64x:"ISEL\t[$]0" // wasm:"Select" // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` + // riscv64/rva23u64:`CZEROEQZ`, -`CZERONEZ`, -`OR` r = r - ldexp(y, rexp-yexp) } return r @@ -144,7 +144,7 @@ func cmovloaded(x [4]int, y int) int { // ppc64x:"ISEL\t[$]2" // wasm:"Select" // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR`, -`SNEZ` + // riscv64/rva23u64:`CZERONEZ`, `OR`, -`CZEROEQZ`, -`SNEZ` return y } @@ -158,7 +158,7 @@ func cmovuintptr2(x, y uintptr) uintptr { // ppc64x:"ISEL\t[$]2" // wasm:"Select" // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR`, -`SEQZ` + // riscv64/rva23u64:`CZERONEZ`, `OR`, -`CZEROEQZ`, -`SEQZ` return a } @@ -248,7 +248,7 @@ func cmovstore(a []int, i int, b bool) { } // amd64:"CMOVQNE" // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva23u64:`CZEROEQZ`, `CZERONEZ`, `OR` + // riscv64/rva23u64:`CZEROEQZ`, -`CZERONEZ` a[i] = 7 } @@ -517,7 +517,7 @@ func cmovzeroreg0(a, b int) int { } // ppc64x:"ISEL\t[$]2, R[0-9]+, R0, R[0-9]+" // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva23u64:`CZEROEQZ`,-`CZERONEZ` + // riscv64/rva23u64:`CZERONEZ`, -`CZEROEQZ` return x } @@ -528,7 +528,7 @@ func cmovzeroreg1(a, b int) int { } // ppc64x:"ISEL\t[$]2, R0, R[0-9]+, R[0-9]+" // riscv64/rva20u64, riscv64/rva22u64:-`CZEROEQZ`, -`CZERONEZ` - // riscv64/rva23u64:`CZERONEZ`, -`CZEROEQZ` + // riscv64/rva23u64:`CZEROEQZ`, -`CZERONEZ` return x }