about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAndy Sadler <andrewsadler122@gmail.com>2024-02-17 17:19:08 -0600
committerAndy Sadler <andrewsadler122@gmail.com>2024-02-17 17:24:46 -0600
commit5ac9bee7f13c83123cc3d184f50a255248e640f2 (patch)
tree1befac77d25fbd4cf28490d4e0ea4e81b7ead04c
parente69f125758a2e04574192c9d884f0391dbd0a707 (diff)
downloadrust-5ac9bee7f13c83123cc3d184f50a255248e640f2.tar.gz
rust-5ac9bee7f13c83123cc3d184f50a255248e640f2.zip
fix tests/ui/simd/issue-89193.rs and mark as passing
Work around an issue where usize and isize can sometimes (but not
always) get canonicalized to their corresponding integer type.  This
causes shuffle_vector to panic, since the types of the vectors it got
passed aren't the same.

Also insert a cast on the mask element, since we might get passed a
signed integer of any size, not just i32.  For now, we always cast to
i32.

Signed-off-by: Andy Sadler <andrewsadler122@gmail.com>
-rw-r--r--src/intrinsic/simd.rs15
-rw-r--r--tests/failing-ui-tests.txt1
2 files changed, 11 insertions, 5 deletions
diff --git a/src/intrinsic/simd.rs b/src/intrinsic/simd.rs
index 5991f061c10..33d659f251f 100644
--- a/src/intrinsic/simd.rs
+++ b/src/intrinsic/simd.rs
@@ -710,7 +710,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
         };
         let elem_type = vector_type.dyncast_vector().expect("vector type").get_element_type();
 
-        let mut values = vec![];
+        let mut values = Vec::with_capacity(in_len as usize);
         for i in 0..in_len {
             let index = bx.context.new_rvalue_from_long(bx.i32_type, i as i64);
             let int = bx.context.new_vector_access(None, pointers, index).to_rvalue();
@@ -723,19 +723,26 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
 
         let vector = bx.context.new_rvalue_from_vector(None, vector_type, &values);
 
-        let mut mask_types = vec![];
-        let mut mask_values = vec![];
+        let mut mask_types = Vec::with_capacity(in_len as usize);
+        let mut mask_values = Vec::with_capacity(in_len as usize);
         for i in 0..in_len {
             let index = bx.context.new_rvalue_from_long(bx.i32_type, i as i64);
             mask_types.push(bx.context.new_field(None, bx.i32_type, "m"));
             let mask_value = bx.context.new_vector_access(None, mask, index).to_rvalue();
-            let masked = bx.context.new_rvalue_from_int(bx.i32_type, in_len as i32) & mask_value;
+            let mask_value_cast = bx.context.new_cast(None, mask_value, bx.i32_type);
+            let masked = bx.context.new_rvalue_from_int(bx.i32_type, in_len as i32) & mask_value_cast;
             let value = index + masked;
             mask_values.push(value);
         }
         let mask_type = bx.context.new_struct_type(None, "mask_type", &mask_types);
         let mask = bx.context.new_struct_constructor(None, mask_type.as_type(), None, &mask_values);
 
+        // FIXME(antoyo): We sometimes need to bitcast here, since usize/isize sometimes (but not
+        // always) get canonicalized to their corresponding integer type (i.e. uint64_t/int64_t on
+        // 64-bit platforms).  This causes the shuffle_vector call below to panic, since the types
+        // of the two vectors aren't the same.  This is a workaround for now.
+        let vector = bx.bitcast_if_needed(vector, default.get_type());
+
         if invert {
             bx.shuffle_vector(vector, default, mask)
         } else {
diff --git a/tests/failing-ui-tests.txt b/tests/failing-ui-tests.txt
index 023fe9d7e83..6e020e9b354 100644
--- a/tests/failing-ui-tests.txt
+++ b/tests/failing-ui-tests.txt
@@ -48,7 +48,6 @@ tests/ui/rfcs/rfc-1857-stabilize-drop-order/drop-order.rs
 tests/ui/rfcs/rfc-2091-track-caller/std-panic-locations.rs
 tests/ui/simd/issue-17170.rs
 tests/ui/simd/issue-39720.rs
-tests/ui/simd/issue-89193.rs
 tests/ui/statics/issue-91050-1.rs
 tests/ui/statics/issue-91050-2.rs
 tests/ui/alloc-error/default-alloc-error-hook.rs