Skip to content

Commit cd67025

Browse files
committed
fix merge conflict and form of rules
1 parent 1d8c459 commit cd67025

File tree

7 files changed

+671
-916
lines changed

7 files changed

+671
-916
lines changed

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

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -850,11 +850,25 @@
850850
(Max64u x y) && buildcfg.GORISCV64 >= 22 => (MAXU x y)
851851

852852
// Zicond Extension for Integer Conditional Operations
853-
// General lowering rule: always lower CondSelect to OR(CZEROEQZ, CZERONEZ) form
854853
(CondSelect <t> x y cond) && buildcfg.GORISCV64 >= 23 => (OR (CZEROEQZ <t> x cond) (CZERONEZ <t> y cond))
855-
(CZERO(EQ|NE)Z <t> x (SNEZ y)) => (CZERO(EQ|NE)Z <t> x y)
856-
(CZERO(EQ|NE)Z <t> x (SEQZ y)) => (CZERO(NE|EQ)Z <t> x y)
857-
(CZEROEQZ <t> x x) => x
858-
(CZERONEZ <t> x x) => (MOVDconst <t> [0])
859-
(CZERO(EQ|NE)Z <t> (MOVDconst [0]) _) => (MOVDconst <t> [0])
860-
(OR (MOVDconst [0]) x) => x
854+
(CZERO(EQ|NE)Z x (SNEZ y)) => (CZERO(EQ|NE)Z x y)
855+
(CZERO(EQ|NE)Z x (SEQZ y)) => (CZERO(NE|EQ)Z x y)
856+
(CZEROEQZ x x) => x
857+
(CZERONEZ x x) => (MOVDconst [0])
858+
(CZERO(EQ|NE)Z (MOVDconst [0]) _) => (MOVDconst [0])
859+
860+
// Fold OR(CZERONEZ(OP x y), CZEROEQZ x) into OP x (CZERONEZ y)
861+
(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))
862+
(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))
863+
864+
// Fold OR(CZERONEZ(AND), CZEROEQZ) when operands match
865+
(OR (CZERONEZ x:(AND z _) cond) y:(CZEROEQZ z cond)) => (OR x y)
866+
(OR (CZEROEQZ x:(AND z _) cond) y:(CZERONEZ z cond)) => (OR x y)
867+
868+
// Fold OR(CZERONEZ(ANDI), CZEROEQZ) when operands match
869+
(OR (CZERONEZ x:(ANDI <t> [c] z) cond) y:(CZEROEQZ z cond)) => (OR x y)
870+
(OR (CZEROEQZ x:(ANDI <t> [c] z) cond) y:(CZERONEZ z cond)) => (OR x y)
871+
872+
// Fold OR(CZERONEZ(OPI [c] x), CZEROEQZ x) into OP x (CZERONEZ c)
873+
(OR (CZERONEZ <t> ((ADDI|ORI|XORI) [c] x) cond) (CZEROEQZ <t> x cond)) => ((ADD|OR|XOR) x (CZERONEZ <t> (MOVDconst [c]) cond))
874+
(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/RISCV64latelower.rules

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,38 +23,3 @@
2323
(SRAI [0] x) => x
2424
(SRLI [0] x) => x
2525
(SLLI [0] x) => x
26-
27-
// "Zicond" Extension for Integer Conditional Operations
28-
// Optimize specific patterns based on the unified OR(CZEROEQZ, CZERONEZ) form
29-
// (x == 0) ? x : y -> CZEROEQZ y x (when x is the condition)
30-
(OR (CZERONEZ <t> x x) (CZEROEQZ <t> y x)) => (CZEROEQZ <t> y x)
31-
32-
// (z == 0) ? ((OP x y)) : x => (OP x (CZERONEZ 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))
34-
// (z != 0) ? ((OP x y)) : x => (OP x (CZEROEQZ 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))
36-
37-
// (z == 0) ? (x & y) : x => OR(AND x y, CZEROEQZ x z)
38-
(OR (CZERONEZ <t> (AND x y) z) (CZEROEQZ <t> x z)) => (OR (AND <t> x y) (CZEROEQZ <t> x z))
39-
// (z != 0) ? (x & y) : x => OR(AND x y, CZERONEZ x z)
40-
(OR (CZEROEQZ <t> (AND x y) z) (CZERONEZ <t> x z)) => (OR (AND <t> x y) (CZERONEZ <t> x z))
41-
42-
// (z == 0) ? (x & c) : x => OR(AND x c, CZEROEQZ x z)
43-
(OR (CZERONEZ <t> (ANDI [c] x) z) (CZEROEQZ <t> x z)) => (OR (AND <t> x (MOVDconst [c])) (CZEROEQZ <t> x z))
44-
// (z != 0) ? (x & c) : x => OR(AND x c, CZERONEZ x z)
45-
(OR (CZEROEQZ <t> (ANDI [c] x) z) (CZERONEZ <t> x z)) => (OR (AND <t> x (MOVDconst [c])) (CZERONEZ <t> x z))
46-
47-
// (z == 0) ? ((OPI [c] x)) : x => (OP x (CZERONEZ 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))
49-
// (z != 0) ? ((OPI [c] x)) : x => (OP x (CZEROEQZ 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))
51-
52-
// (z == 0) ? (ADDIW [c] x) : x
53-
(OR (CZERONEZ <t> (ADDIW [c] x) z) (CZEROEQZ <t> x z)) => (ADD x (CZERONEZ <t> (MOVDconst [int64(int32(c))]) z))
54-
// (z != 0) ? (ADDIW [c] x) : x
55-
(OR (CZEROEQZ <t> (ADDIW [c] x) z) (CZERONEZ <t> x z)) => (ADD x (CZEROEQZ <t> (MOVDconst [int64(int32(c))]) z))
56-
57-
// (cond == 0) ? 0 : const => CZERONEZ const cond
58-
(OR (CZERONEZ <t> (MOVDconst [0]) cond) (CZEROEQZ <t> (MOVDconst [c]) cond)) => (CZERONEZ <t> (MOVDconst [c]) cond)
59-
// (cond != 0) ? 0 : const => CZEROEQZ const cond
60-
(OR (CZEROEQZ <t> (MOVDconst [0]) cond) (CZERONEZ <t> (MOVDconst [c]) cond)) => (CZEROEQZ <t> (MOVDconst [c]) cond)

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44

55
package ssa
66

7-
import (
8-
"cmd/internal/src"
9-
"internal/buildcfg"
10-
)
7+
import "cmd/internal/src"
118

129
// branchelim tries to eliminate branches by
1310
// generating CondSelect instructions.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"cmd/compile/internal/types"
1212
"cmd/internal/obj"
1313
"cmd/internal/src"
14+
"internal/buildcfg"
1415
)
1516

1617
// A Config holds readonly compilation information.
@@ -346,6 +347,7 @@ func NewConfig(arch string, types Types, ctxt *obj.Link, optimize, softfloat boo
346347
c.floatParamRegs = paramFloatRegRISCV64
347348
c.FPReg = framepointerRegRISCV64
348349
c.hasGReg = true
350+
c.haveCondSelect = buildcfg.GORISCV64 >= 23
349351
case "wasm":
350352
c.PtrSize = 8
351353
c.RegSize = 8

0 commit comments

Comments
 (0)