From 1f0fece59c21fca9fca24ffebf0ee204f510e0ef Mon Sep 17 00:00:00 2001 From: Solo-steven Date: Tue, 24 Oct 2023 15:36:22 +0800 Subject: [PATCH 1/2] refactor: using emit_cmp helper to refactor lowering of selection instruction on x64 --- cranelift/codegen/src/isa/x64/lower.isle | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cranelift/codegen/src/isa/x64/lower.isle b/cranelift/codegen/src/isa/x64/lower.isle index af11e659de8d..fb91e233a2e9 100644 --- a/cranelift/codegen/src/isa/x64/lower.isle +++ b/cranelift/codegen/src/isa/x64/lower.isle @@ -2082,8 +2082,7 @@ ;; than one instruction for certain types (e.g., XMM-held, I128). (rule (lower (has_type ty (select (maybe_uextend (icmp cc a @ (value_type (fits_in_64 a_ty)) b)) x y))) - (let ((size OperandSize (raw_operand_size_of_type a_ty))) - (with_flags (x64_cmp size b a) (cmove_from_values ty cc x y)))) + (lower_select_icmp ty (emit_cmp cc a b ) x y)) ;; Finally, we lower `select` from a condition value `c`. These rules are meant ;; to be the final, default lowerings if no other patterns matched above. @@ -2099,6 +2098,10 @@ (let ((cond_result IcmpCondResult (cmp_zero_i128 (CC.Z) c))) (select_icmp cond_result x y))) +(decl lower_select_icmp (Type IcmpCondResult Value Value) InstOutput) +(rule (lower_select_icmp ty (IcmpCondResult.Condition flags cc) x y) + (with_flags flags (cmove_from_values ty cc x y))) + ;; Specializations for floating-point compares to generate a `mins*` or a ;; `maxs*` instruction. These are equivalent to the "pseudo-m{in,ax}" ;; specializations for vectors. From 2d68a1bd68a5a3e44afc1828a37fb4434020c0d8 Mon Sep 17 00:00:00 2001 From: Solo-steven Date: Wed, 25 Oct 2023 16:31:20 +0800 Subject: [PATCH 2/2] chore: remove space before paran --- cranelift/codegen/src/isa/x64/lower.isle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cranelift/codegen/src/isa/x64/lower.isle b/cranelift/codegen/src/isa/x64/lower.isle index fb91e233a2e9..e0d17fe627a4 100644 --- a/cranelift/codegen/src/isa/x64/lower.isle +++ b/cranelift/codegen/src/isa/x64/lower.isle @@ -2082,7 +2082,7 @@ ;; than one instruction for certain types (e.g., XMM-held, I128). (rule (lower (has_type ty (select (maybe_uextend (icmp cc a @ (value_type (fits_in_64 a_ty)) b)) x y))) - (lower_select_icmp ty (emit_cmp cc a b ) x y)) + (lower_select_icmp ty (emit_cmp cc a b) x y)) ;; Finally, we lower `select` from a condition value `c`. These rules are meant ;; to be the final, default lowerings if no other patterns matched above.