libgccjit: Allow comparing vector types
authorAntoni Boucher <bouanto@zoho.com>
Sat, 25 Jun 2022 01:05:29 +0000 (21:05 -0400)
committerAntoni Boucher <bouanto@zoho.com>
Wed, 14 Dec 2022 04:55:12 +0000 (23:55 -0500)
gcc/jit/ChangeLog:
PR jit/108078
* jit-recording.h: Add vector_type::is_same_type_as method

gcc/testsuite/ChangeLog:
PR jit/108078
* jit.dg/test-vector-types.cc: Add tests for vector type comparison

Co-authored-by: Guillaume Gomez <guillaume1.gomez@gmail.com>
Signed-off-by: Guillaume Gomez <guillaume1.gomez@gmail.com>
gcc/jit/jit-recording.h
gcc/testsuite/jit.dg/test-vector-types.cc

index 5d7c717..e1236de 100644 (file)
@@ -806,6 +806,15 @@ public:
 
   void replay_into (replayer *) final override;
 
+  bool is_same_type_as (type *other) final override
+  {
+    vector_type *other_vec_type = other->dyn_cast_vector_type ();
+    if (other_vec_type == NULL)
+      return false;
+    return get_num_units () == other_vec_type->get_num_units ()
+      && get_element_type () == other_vec_type->get_element_type ();
+  }
+
   vector_type *is_vector () final override { return this; }
 
 private:
index 1f49be6..5661d1b 100644 (file)
@@ -105,6 +105,19 @@ create_code (gcc_jit_context *ctxt, void *user_data)
                 v4f_type, GCC_JIT_BINARY_OP_MULT);
   create_vec_fn (ctxt, "jit_v4f_div",
                 v4f_type, GCC_JIT_BINARY_OP_DIVIDE);
+
+  // Checking compatibility between types.
+  CHECK_VALUE(gcc_jit_compatible_types(v4si_type, v4ui_type), 0);
+  CHECK_VALUE(gcc_jit_compatible_types(v4si_type, v4f_type), 0);
+  CHECK_VALUE(gcc_jit_compatible_types(v4ui_type, v4f_type), 0);
+
+  gcc_jit_type *v4si_type2 = gcc_jit_type_get_vector (int_type, 4);
+  gcc_jit_type *v4ui_type2 = gcc_jit_type_get_vector (unsigned_type, 4);
+  gcc_jit_type *v4f_type2 = gcc_jit_type_get_vector (float_type, 4);
+
+  CHECK_VALUE(gcc_jit_compatible_types(v4si_type, v4si_type2), 1);
+  CHECK_VALUE(gcc_jit_compatible_types(v4ui_type, v4ui_type2), 1);
+  CHECK_VALUE(gcc_jit_compatible_types(v4f_type, v4f_type2), 1);
 }
 
 template <typename T>