Skip to content

Commit 8724c33

Browse files
committed
zicond-refine
1 parent de1f90a commit 8724c33

File tree

6 files changed

+817
-345
lines changed

6 files changed

+817
-345
lines changed

src/cmd/compile/internal/ssa/_gen/RISCV64.rules

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -860,8 +860,8 @@
860860
(Min64u x y) && buildcfg.GORISCV64 >= 22 => (MINU x y)
861861
(Max64u x y) && buildcfg.GORISCV64 >= 22 => (MAXU x y)
862862

863-
// Zicond Extension for Integer Conditional Operations
864-
(CondSelect <t> x y cond) && buildcfg.GORISCV64 >= 23 =>
863+
// Conditional selection (note that these will only be emitted for rva23u64 and above)
864+
(CondSelect <t> x y cond) =>
865865
(OR (CZEROEQZ <t> x (MOVBUreg <typ.UInt64> cond)) (CZERONEZ <t> y (MOVBUreg <typ.UInt64> cond)))
866866
(CZERO(EQ|NE)Z x (SNEZ y)) => (CZERO(EQ|NE)Z x y)
867867
(CZERO(EQ|NE)Z x (SEQZ y)) => (CZERO(NE|EQ)Z x y)
@@ -870,11 +870,11 @@
870870
(CZERO(EQ|NE)Z (MOVDconst [0]) _) => (MOVDconst [0])
871871

872872
// Optimize conditional arithmetic operations
873-
(OR (CZERONEZ <t> ((ADD|SUB|OR|XOR|SUBW) x y) cond) (CZEROEQZ <t> x cond)) => ((ADD|SUB|OR|XOR|SUBW) x (CZERONEZ <t> y cond))
873+
(OR (CZEROEQZ <t> x cond) (CZERONEZ <t> ((ADD|SUB|OR|XOR|SUBW) x y) cond)) => ((ADD|SUB|OR|XOR|SUBW) x (CZERONEZ <t> y cond))
874874
(OR (CZEROEQZ <t> ((ADD|SUB|OR|XOR|SUBW) x y) cond) (CZERONEZ <t> x cond)) => ((ADD|SUB|OR|XOR|SUBW) x (CZEROEQZ <t> y cond))
875-
(OR (CZERONEZ x:(AND z _) cond) y:(CZEROEQZ z cond)) => (OR x y)
875+
(OR x:(CZEROEQZ z cond) (CZERONEZ y:(AND z _) cond)) => (OR y x)
876876
(OR (CZEROEQZ x:(AND z _) cond) y:(CZERONEZ z cond)) => (OR x y)
877-
(OR (CZERONEZ x:(ANDI <t> [c] z) cond) y:(CZEROEQZ z cond)) => (OR x y)
877+
(OR x:(CZEROEQZ z cond) (CZERONEZ y:(ANDI <t> [c] z) cond)) => (OR y x)
878878
(OR (CZEROEQZ x:(ANDI <t> [c] z) cond) y:(CZERONEZ z cond)) => (OR x y)
879-
(OR (CZERONEZ <t> ((ADDI|ORI|XORI) [c] x) cond) (CZEROEQZ <t> x cond)) => ((ADD|OR|XOR) x (CZERONEZ <t> (MOVDconst [c]) cond))
879+
(OR (CZEROEQZ <t> x cond) (CZERONEZ <t> ((ADDI|ORI|XORI) [c] x) cond)) => ((ADD|OR|XOR) x (CZERONEZ <t> (MOVDconst [c]) cond))
880880
(OR (CZEROEQZ <t> ((ADDI|ORI|XORI) [c] x) cond) (CZERONEZ <t> x cond)) => ((ADD|OR|XOR) x (CZEROEQZ <t> (MOVDconst [c]) cond))

src/cmd/compile/internal/ssa/_gen/RISCV64Ops.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,8 @@ func init() {
525525
{name: "FCLASSD", argLength: 1, reg: fpgp, asm: "FCLASSD", typ: "Int64"}, // classify float64
526526

527527
// RISC-V Integer Conditional (Zicond) operations extension
528-
{name: "CZEROEQZ", argLength: 2, reg: gp21, asm: "CZEROEQZ"},
529-
{name: "CZERONEZ", argLength: 2, reg: gp21, asm: "CZERONEZ"},
528+
{name: "CZEROEQZ", argLength: 2, reg: gp21, asm: "CZEROEQZ"}, // arg1 == 0 result is 0, else arg0
529+
{name: "CZERONEZ", argLength: 2, reg: gp21, asm: "CZERONEZ"}, // arg1 != 0 result is 0, else arg0
530530
}
531531

532532
RISCV64blocks := []blockData{

0 commit comments

Comments
 (0)