diff --git a/cranelift/codegen/src/isle_prelude.rs b/cranelift/codegen/src/isle_prelude.rs index 9b847428827e..39c845023642 100644 --- a/cranelift/codegen/src/isle_prelude.rs +++ b/cranelift/codegen/src/isle_prelude.rs @@ -528,6 +528,15 @@ macro_rules! isle_common_prelude_methods { } } + #[inline] + fn ty_vec(&mut self, ty: Type) -> Option { + if ty.is_vector() { + Some(ty) + } else { + None + } + } + #[inline] fn ty_vec64_int(&mut self, ty: Type) -> Option { if ty.is_vector() && ty.bits() == 64 && ty.lane_type().is_int() { diff --git a/cranelift/codegen/src/prelude.isle b/cranelift/codegen/src/prelude.isle index e44c21e6c15c..7de798748096 100644 --- a/cranelift/codegen/src/prelude.isle +++ b/cranelift/codegen/src/prelude.isle @@ -635,6 +635,10 @@ (decl ty_dyn_vec128 (Type) Type) (extern extractor ty_dyn_vec128 ty_dyn_vec128) +;; An extractor that only matches vector. +(decl ty_vec (Type) Type) +(extern extractor ty_vec ty_vec) + ;; An extractor that only matches 64-bit vector types with integer ;; lanes (I8X8, I16X4, I32X2) (decl ty_vec64_int (Type) Type) diff --git a/cranelift/codegen/src/prelude_opt.isle b/cranelift/codegen/src/prelude_opt.isle index dc86184bc688..524f94a5f0e9 100644 --- a/cranelift/codegen/src/prelude_opt.isle +++ b/cranelift/codegen/src/prelude_opt.isle @@ -95,6 +95,15 @@ (iconst ty (imm64 c))) (rule 1 (iconst_u $I128 c) (uextend $I128 (iconst_u $I64 c))) +;; Constructs a constant value node from a 64-bit immediate, adapting it +;; to the specified type. For 128-bit integers, the immediate is zero-extended; +;; for other integer types, a direct iconst is generated; and for vector types, +;; the constant is splatted across all lanes. +(decl const (Type Imm64) Value) +(rule 2 (const $I128 n) (uextend $I128 (iconst $I64 n))) +(rule 1 (const (ty_int ty) n) (iconst ty n)) +(rule 0 (const (ty_vec ty) n) (splat ty (const (lane_type ty) n))) + ;; These take `Value`, rather than going through `inst_data_tupled`, because ;; most of the time they want to return the original `Value`, and it would be ;; a waste to need to re-GVN the instruction data in those cases.