Skip to content

Commit 36aaaaa

Browse files
committed
riscv64: Restrict shnadd selection
1 parent a59796e commit 36aaaaa

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

cranelift/codegen/src/isa/riscv64/lower.isle

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,34 +51,38 @@
5151
(if-let $true (has_zba))
5252
(alu_rrr (AluOPRRR.Adduw) x y))
5353

54-
;; Add with shift. We have a few of these instructions with `Zba`.
55-
(decl select_shnadd (Imm64) AluOPRRR)
56-
(rule (select_shnadd (u64_from_imm64 1)) (AluOPRRR.Sh1add))
57-
(rule (select_shnadd (u64_from_imm64 2)) (AluOPRRR.Sh2add))
58-
(rule (select_shnadd (u64_from_imm64 3)) (AluOPRRR.Sh3add))
54+
;; Add with const shift. We have a few of these instructions with `Zba`.
55+
(decl pure partial match_shnadd (Imm64) AluOPRRR)
56+
(rule (match_shnadd (uimm8 1)) (AluOPRRR.Sh1add))
57+
(rule (match_shnadd (uimm8 2)) (AluOPRRR.Sh2add))
58+
(rule (match_shnadd (uimm8 3)) (AluOPRRR.Sh3add))
5959

6060
(rule 4 (lower (has_type (fits_in_64 ty) (iadd x (ishl y (maybe_uextend (iconst n))))))
6161
(if-let $true (has_zba))
62-
(alu_rrr (select_shnadd n) y x))
62+
(if-let shnadd (match_shnadd n))
63+
(alu_rrr shnadd y x))
6364

6465
(rule 5 (lower (has_type (fits_in_64 ty) (iadd (ishl x (maybe_uextend (iconst n))) y)))
6566
(if-let $true (has_zba))
66-
(alu_rrr (select_shnadd n) x y))
67+
(if-let shnadd (match_shnadd n))
68+
(alu_rrr shnadd x y))
6769

6870

69-
;; Add with uextended shift. We have a few of these instructions with `Zba`.
70-
(decl select_shnadd_uw (Imm64) AluOPRRR)
71-
(rule (select_shnadd_uw (u64_from_imm64 1)) (AluOPRRR.Sh1adduw))
72-
(rule (select_shnadd_uw (u64_from_imm64 2)) (AluOPRRR.Sh2adduw))
73-
(rule (select_shnadd_uw (u64_from_imm64 3)) (AluOPRRR.Sh3adduw))
71+
;; Add with uextended const shift. We have a few of these instructions with `Zba`.
72+
(decl pure partial match_shnadd_uw (Imm64) AluOPRRR)
73+
(rule (match_shnadd_uw (uimm8 1)) (AluOPRRR.Sh1adduw))
74+
(rule (match_shnadd_uw (uimm8 2)) (AluOPRRR.Sh2adduw))
75+
(rule (match_shnadd_uw (uimm8 3)) (AluOPRRR.Sh3adduw))
7476

7577
(rule 6 (lower (has_type (fits_in_64 ty) (iadd x (ishl (uextend y) (maybe_uextend (iconst n))))))
7678
(if-let $true (has_zba))
77-
(alu_rrr (select_shnadd_uw n) y x))
79+
(if-let shnadd_uw (match_shnadd_uw n))
80+
(alu_rrr shnadd_uw y x))
7881

7982
(rule 7 (lower (has_type (fits_in_64 ty) (iadd (ishl (uextend x) (maybe_uextend (iconst n))) y)))
8083
(if-let $true (has_zba))
81-
(alu_rrr (select_shnadd_uw n) x y))
84+
(if-let shnadd_uw (match_shnadd_uw n))
85+
(alu_rrr shnadd_uw x y))
8286

8387
;; I128 cases
8488
(rule 8 (lower (has_type $I128 (iadd x y)))

0 commit comments

Comments
 (0)