From 9db55d2f54e869be328c2f0926786f8fd0ec84a4 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Sun, 26 Jun 2022 14:28:06 -0400 Subject: [PATCH] Fix vector comparison now returning a vector of integers --- src/builder.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/builder.rs b/src/builder.rs index 08930387ccb..867fd531f50 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -1490,6 +1490,9 @@ pub fn vector_select(&mut self, cond: RValue<'gcc>, then_val: RValue<'gcc>, else let zeros = self.context.new_rvalue_from_vector(None, cond_type, &zeros); let masks = self.context.new_comparison(None, ComparisonOp::NotEquals, cond, zeros); + // NOTE: masks is a vector of integers, but the values can be vectors of floats, so use bitcast to make + // the & operation work. + let masks = self.bitcast_if_needed(masks, then_val.get_type()); let then_vals = masks & then_val; let ones = vec![self.context.new_rvalue_one(element_type); num_units]; @@ -1509,6 +1512,16 @@ pub fn vector_select(&mut self, cond: RValue<'gcc>, then_val: RValue<'gcc>, else fn difference_or_zero<'gcc>(a: RValue<'gcc>, b: RValue<'gcc>, context: &'gcc Context<'gcc>) -> RValue<'gcc> { let difference = a - b; let masks = context.new_comparison(None, ComparisonOp::GreaterThanEquals, b, a); + // NOTE: masks is a vector of integers, but the values can be vectors of floats, so use bitcast to make + // the & operation work. + let a_type = a.get_type(); + let masks = + if masks.get_type() != a_type { + context.new_bitcast(None, masks, a_type) + } + else { + masks + }; difference & masks }