Skip to content

Commit 28ea648

Browse files
authored
riscv64: Stricter ISA flag checking when lowering instructions (bytecodealliance#9079)
* riscv64: Match F and D ISA extensions on all float instructions * riscv64: Stricter vector type checking
1 parent 3461726 commit 28ea648

File tree

3 files changed

+335
-270
lines changed

3 files changed

+335
-270
lines changed

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

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,22 @@
10551055
(extern constructor has_zicond has_zicond)
10561056

10571057

1058+
;;;; Type Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1059+
1060+
;; Helper that matches any supported type. This extractor checks the ISA flags
1061+
;; to determine if the type is supported.
1062+
(decl ty_supported (Type) Type)
1063+
(extern extractor ty_supported ty_supported)
1064+
1065+
;; Helper that matches any scalar floating point type
1066+
(decl ty_supported_float (Type) Type)
1067+
(extern extractor ty_supported_float ty_supported_float)
1068+
1069+
;; Helper that matches any supported vector type
1070+
(decl ty_supported_vec (Type) Type)
1071+
(extern extractor ty_supported_vec ty_supported_vec)
1072+
1073+
10581074
;;;; Instruction Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10591075

10601076
;; RV32I Base Integer Instruction Set
@@ -1869,7 +1885,7 @@
18691885
(rule 8 (imm $F64 0) (gen_bitcast (zero_reg) $I64 $F64))
18701886

18711887
;; If Zfa is enabled, we can load certain constants with the `fli` instruction.
1872-
(rule 7 (imm (ty_scalar_float ty) imm)
1888+
(rule 7 (imm (ty_supported_float ty) imm)
18731889
(if-let $true (has_zfa))
18741890
(if-let const (fli_constant_from_u64 ty imm))
18751891
(rv_fli ty const))
@@ -1879,7 +1895,7 @@
18791895
;;
18801896
;; For f64's this saves one instruction, and for f32's it avoids
18811897
;; having to allocate an integer register, reducing integer register pressure.
1882-
(rule 6 (imm (ty_scalar_float ty) imm)
1898+
(rule 6 (imm (ty_supported_float ty) imm)
18831899
(if-let $true (has_zfa))
18841900
(if-let const (fli_constant_from_negated_u64 ty imm))
18851901
(rv_fneg ty (rv_fli ty const)))
@@ -2930,10 +2946,10 @@
29302946
;; Generates a bitcast instruction.
29312947
;; Args are: src, src_ty, dst_ty
29322948
(decl gen_bitcast (Reg Type Type) Reg)
2933-
(rule 5 (gen_bitcast r (ty_scalar_float src_ty) (ty_vec_fits_in_register _)) (rv_vfmv_sf r src_ty))
2934-
(rule 4 (gen_bitcast r (ty_int_ref_scalar_64 src_ty) (ty_vec_fits_in_register _)) (rv_vmv_sx r src_ty))
2935-
(rule 3 (gen_bitcast r (ty_vec_fits_in_register _) (ty_scalar_float dst_ty)) (rv_vfmv_fs r dst_ty))
2936-
(rule 2 (gen_bitcast r (ty_vec_fits_in_register _) (ty_int_ref_scalar_64 dst_ty)) (rv_vmv_xs r dst_ty))
2949+
(rule 5 (gen_bitcast r (ty_supported_float src_ty) (ty_supported_vec _)) (rv_vfmv_sf r src_ty))
2950+
(rule 4 (gen_bitcast r (ty_int_ref_scalar_64 src_ty) (ty_supported_vec _)) (rv_vmv_sx r src_ty))
2951+
(rule 3 (gen_bitcast r (ty_supported_vec _) (ty_supported_float dst_ty)) (rv_vfmv_fs r dst_ty))
2952+
(rule 2 (gen_bitcast r (ty_supported_vec _) (ty_int_ref_scalar_64 dst_ty)) (rv_vmv_xs r dst_ty))
29372953
(rule 1 (gen_bitcast r $F32 $I32) (rv_fmvxw r))
29382954
(rule 1 (gen_bitcast r $F64 $I64) (rv_fmvxd r))
29392955
(rule 1 (gen_bitcast r $I32 $F32) (rv_fmvwx r))

0 commit comments

Comments
 (0)