Skip to content

Commit 9e3f91a

Browse files
committed
add some rules
1 parent 00604c6 commit 9e3f91a

File tree

5 files changed

+257
-420
lines changed

5 files changed

+257
-420
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,3 +853,9 @@
853853
// Zicond Extension for Integer Conditional Operations
854854
// General lowering rule: always lower CondSelect to OR(CZEROEQZ, CZERONEZ) form
855855
(CondSelect <t> x y cond) && buildcfg.GORISCV64 >= 23 => (OR (CZEROEQZ <t> x cond) (CZERONEZ <t> y cond))
856+
(CZERO(EQ|NE)Z <t> x (SNEZ y)) => (CZERO(EQ|NE)Z <t> x y)
857+
(CZERO(EQ|NE)Z <t> x (SEQZ y)) => (CZERO(NE|EQ)Z <t> x y)
858+
(CZEROEQZ <t> x x) => x
859+
(CZERONEZ <t> x x) => (MOVDconst <t> [0])
860+
(CZERO(EQ|NE)Z <t> (MOVDconst [0]) _) => (MOVDconst <t> [0])
861+
(OR (MOVDconst [0]) x) => x

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

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,49 +27,34 @@
2727
// "Zicond" Extension for Integer Conditional Operations
2828
// Optimize specific patterns based on the unified OR(CZEROEQZ, CZERONEZ) form
2929
// (x == 0) ? x : y -> CZEROEQZ y x (when x is the condition)
30-
(OR (CZEROEQZ <t> x (SEQZ x)) (CZERONEZ <t> y (SEQZ x))) && buildcfg.GORISCV64 >= 23 => (CZEROEQZ <t> y x)
30+
(OR (CZERONEZ <t> x x) (CZEROEQZ <t> y x)) => (CZEROEQZ <t> y x)
3131

3232
// (z == 0) ? ((OP x y)) : x => (OP x (CZERONEZ y z))
33-
(OR (CZEROEQZ <t> ((ADD|SUB|OR|XOR|SUBW) x y) (SEQZ z)) (CZERONEZ <t> x (SEQZ z))) && buildcfg.GORISCV64 >= 23
34-
=> ((ADD|SUB|OR|XOR|SUBW) x (CZERONEZ <t> y z))
33+
(OR (CZERONEZ <t> ((ADD|SUB|OR|XOR|SUBW) x y) z) (CZEROEQZ <t> x z)) => ((ADD|SUB|OR|XOR|SUBW) x (CZERONEZ <t> y z))
3534
// (z != 0) ? ((OP x y)) : x => (OP x (CZEROEQZ y z))
36-
(OR (CZEROEQZ <t> ((ADD|SUB|OR|XOR|SUBW) x y) (SNEZ z)) (CZERONEZ <t> x (SNEZ z))) && buildcfg.GORISCV64 >= 23
37-
=> ((ADD|SUB|OR|XOR|SUBW) x (CZEROEQZ <t> y z))
35+
(OR (CZEROEQZ <t> ((ADD|SUB|OR|XOR|SUBW) x y) z) (CZERONEZ <t> x z)) => ((ADD|SUB|OR|XOR|SUBW) x (CZEROEQZ <t> y z))
3836

3937
// (z == 0) ? (x & y) : x => OR(AND x y, CZEROEQZ x z)
40-
(OR (CZEROEQZ <t> (AND x y) (SEQZ z)) (CZERONEZ <t> x (SEQZ z))) && buildcfg.GORISCV64 >= 23
41-
=> (OR (AND <t> x y) (CZEROEQZ <t> x z))
38+
(OR (CZERONEZ <t> (AND x y) z) (CZEROEQZ <t> x z)) => (OR (AND <t> x y) (CZEROEQZ <t> x z))
4239
// (z != 0) ? (x & y) : x => OR(AND x y, CZERONEZ x z)
43-
(OR (CZEROEQZ <t> (AND x y) (SNEZ z)) (CZERONEZ <t> x (SNEZ z))) && buildcfg.GORISCV64 >= 23
44-
=> (OR (AND <t> x y) (CZERONEZ <t> x z))
40+
(OR (CZEROEQZ <t> (AND x y) z) (CZERONEZ <t> x z)) => (OR (AND <t> x y) (CZERONEZ <t> x z))
4541

4642
// (z == 0) ? (x & c) : x => OR(AND x c, CZEROEQZ x z)
47-
(OR (CZEROEQZ <t> (ANDI [c] x) (SEQZ z)) (CZERONEZ <t> x (SEQZ z))) && buildcfg.GORISCV64 >= 23
48-
=> (OR (AND <t> x (MOVDconst [c])) (CZEROEQZ <t> x z))
43+
(OR (CZERONEZ <t> (ANDI [c] x) z) (CZEROEQZ <t> x z)) => (OR (AND <t> x (MOVDconst [c])) (CZEROEQZ <t> x z))
4944
// (z != 0) ? (x & c) : x => OR(AND x c, CZERONEZ x z)
50-
(OR (CZEROEQZ <t> (ANDI [c] x) (SNEZ z)) (CZERONEZ <t> x (SNEZ z))) && buildcfg.GORISCV64 >= 23
51-
=> (OR (AND <t> x (MOVDconst [c])) (CZERONEZ <t> x z))
45+
(OR (CZEROEQZ <t> (ANDI [c] x) z) (CZERONEZ <t> x z)) => (OR (AND <t> x (MOVDconst [c])) (CZERONEZ <t> x z))
5246

5347
// (z == 0) ? ((OPI [c] x)) : x => (OP x (CZERONEZ c z))
54-
(OR (CZEROEQZ <t> ((ADDI|ORI|XORI) [c] x) (SEQZ z)) (CZERONEZ <t> x (SEQZ z))) && buildcfg.GORISCV64 >= 23
55-
=> ((ADD|OR|XOR) x (CZERONEZ <t> (MOVDconst [c]) z))
48+
(OR (CZERONEZ <t> ((ADDI|ORI|XORI) [c] x) z) (CZEROEQZ <t> x z)) => ((ADD|OR|XOR) x (CZERONEZ <t> (MOVDconst [c]) z))
5649
// (z != 0) ? ((OPI [c] x)) : x => (OP x (CZEROEQZ c z))
57-
(OR (CZEROEQZ <t> ((ADDI|ORI|XORI) [c] x) (SNEZ z)) (CZERONEZ <t> x (SNEZ z))) && buildcfg.GORISCV64 >= 23
58-
=> ((ADD|OR|XOR) x (CZEROEQZ <t> (MOVDconst [c]) z))
50+
(OR (CZEROEQZ <t> ((ADDI|ORI|XORI) [c] x) z) (CZERONEZ <t> x z)) => ((ADD|OR|XOR) x (CZEROEQZ <t> (MOVDconst [c]) z))
5951

6052
// (z == 0) ? (ADDIW [c] x) : x
61-
(OR (CZEROEQZ <t> (ADDIW [c] x) (SEQZ z)) (CZERONEZ <t> x (SEQZ z))) && buildcfg.GORISCV64 >= 23
62-
=> (ADD x (CZERONEZ <t> (MOVDconst [int64(int32(c))]) z))
53+
(OR (CZERONEZ <t> (ADDIW [c] x) z) (CZEROEQZ <t> x z)) => (ADD x (CZERONEZ <t> (MOVDconst [int64(int32(c))]) z))
6354
// (z != 0) ? (ADDIW [c] x) : x
64-
(OR (CZEROEQZ <t> (ADDIW [c] x) (SNEZ z)) (CZERONEZ <t> x (SNEZ z))) && buildcfg.GORISCV64 >= 23
65-
=> (ADD x (CZEROEQZ <t> (MOVDconst [int64(int32(c))]) z))
55+
(OR (CZEROEQZ <t> (ADDIW [c] x) z) (CZERONEZ <t> x z)) => (ADD x (CZEROEQZ <t> (MOVDconst [int64(int32(c))]) z))
6656

6757
// (cond == 0) ? 0 : const => CZERONEZ const cond
68-
(OR (CZEROEQZ <t> (MOVDconst [0]) (SEQZ cond)) (CZERONEZ <t> (MOVDconst [c]) (SEQZ cond))) && buildcfg.GORISCV64 >= 23
69-
=> (CZERONEZ <t> (MOVDconst [c]) cond)
58+
(OR (CZERONEZ <t> (MOVDconst [0]) cond) (CZEROEQZ <t> (MOVDconst [c]) cond)) => (CZERONEZ <t> (MOVDconst [c]) cond)
7059
// (cond != 0) ? 0 : const => CZEROEQZ const cond
71-
(OR (CZEROEQZ <t> (MOVDconst [0]) (SNEZ cond)) (CZERONEZ <t> (MOVDconst [c]) (SNEZ cond))) && buildcfg.GORISCV64 >= 23
72-
=> (CZEROEQZ <t> (MOVDconst [c]) cond)
73-
74-
// Constant propagation through CZERO(EQ|NE)Z
75-
(CZERO(EQ|NE)Z <t> (MOVDconst [0]) _) && buildcfg.GORISCV64 >= 23 => (MOVDconst <t> [0])
60+
(OR (CZEROEQZ <t> (MOVDconst [0]) cond) (CZERONEZ <t> (MOVDconst [c]) cond)) => (CZEROEQZ <t> (MOVDconst [c]) cond)

src/cmd/compile/internal/ssa/rewriteRISCV64.go

Lines changed: 130 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)