From 85d468dc5a5168d8ae11ee0fb606a1c3b65baecd Mon Sep 17 00:00:00 2001 From: Afonso Bordado Date: Fri, 10 Sep 2021 15:38:30 +0100 Subject: [PATCH] cranelift: Add `coerce_bools_to_ints` helper --- cranelift/codegen/src/ir/types.rs | 13 +++++++++++++ cranelift/filetests/src/function_runner.rs | 15 ++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/cranelift/codegen/src/ir/types.rs b/cranelift/codegen/src/ir/types.rs index 477c589a54..1f59c9c07c 100644 --- a/cranelift/codegen/src/ir/types.rs +++ b/cranelift/codegen/src/ir/types.rs @@ -340,6 +340,19 @@ impl Type { Err(()) => panic!("unable to determine architecture pointer width"), } } + + /// Coerces boolean types (scalar and vectors) into their integer counterparts. + /// B1 is converted into I8. + pub fn coerce_bools_to_ints(self) -> Self { + let is_scalar_bool = self.is_bool(); + let is_vector_bool = self.is_vector() && self.lane_type().is_bool(); + + if is_scalar_bool || is_vector_bool { + self.as_int() + } else { + self + } + } } impl Display for Type { diff --git a/cranelift/filetests/src/function_runner.rs b/cranelift/filetests/src/function_runner.rs index 32667b325c..698a37c01a 100644 --- a/cranelift/filetests/src/function_runner.rs +++ b/cranelift/filetests/src/function_runner.rs @@ -297,15 +297,7 @@ fn make_trampoline(signature: &ir::Signature, isa: &dyn TargetIsa) -> Function { .enumerate() .map(|(i, param)| { // Calculate the type to load from memory, using integers for booleans (no encodings). - let is_scalar_bool = param.value_type.is_bool(); - let is_vector_bool = - param.value_type.is_vector() && param.value_type.lane_type().is_bool(); - - let ty = if is_scalar_bool || is_vector_bool { - param.value_type.as_int() - } else { - param.value_type - }; + let ty = param.value_type.coerce_bools_to_ints(); // Load the value. let loaded = builder.ins().load( @@ -314,6 +306,11 @@ fn make_trampoline(signature: &ir::Signature, isa: &dyn TargetIsa) -> Function { values_vec_ptr_val, (i * UnboxedValues::SLOT_SIZE) as i32, ); + + let is_scalar_bool = param.value_type.is_bool(); + let is_vector_bool = + param.value_type.is_vector() && param.value_type.lane_type().is_bool(); + // For booleans, we want to type-convert the loaded integer into a boolean and ensure // that we are using the architecture's canonical boolean representation (presumably // comparison will emit this).