aboutsummaryrefslogtreecommitdiff
path: root/gcc/jit
diff options
context:
space:
mode:
authorAntoni Boucher <bouanto@zoho.com>2022-11-20 10:22:53 -0500
committerAntoni Boucher <bouanto@zoho.com>2022-12-06 19:40:17 -0500
commitd2e782cb99c3116c389d6a9565678c4ffe267777 (patch)
treea75b5d3a8a7f6fb3c024fc42fad4f3dfc656f3bb /gcc/jit
parent3fe66f7f9f0940cbaf5a21366ecdc6c57360b2f1 (diff)
downloadgcc-d2e782cb99c3116c389d6a9565678c4ffe267777.zip
gcc-d2e782cb99c3116c389d6a9565678c4ffe267777.tar.gz
gcc-d2e782cb99c3116c389d6a9565678c4ffe267777.tar.bz2
libgccjit: Fix float vector comparison
Fix float vector comparison and add comparison tests to include float and vectors. gcc/testsuite: PR jit/107770 * jit.dg/harness.h: Add new macro to to perform vector comparisons * jit.dg/test-expressions.c: Extend comparison tests to add float types and vectors gcc/jit: PR jit/107770 * jit-playback.cc: Fix vector float comparison * jit-playback.h: Update comparison function signature * jit-recording.cc: Update call for "new_comparison" function * jit-recording.h: Fix vector float comparison Co-authored-by: Guillaume Gomez <guillaume1.gomez@gmail.com> Signed-off-by: Guillaume Gomez <guillaume1.gomez@gmail.com>
Diffstat (limited to 'gcc/jit')
-rw-r--r--gcc/jit/jit-playback.cc27
-rw-r--r--gcc/jit/jit-playback.h2
-rw-r--r--gcc/jit/jit-recording.cc3
-rw-r--r--gcc/jit/jit-recording.h18
4 files changed, 42 insertions, 8 deletions
diff --git a/gcc/jit/jit-playback.cc b/gcc/jit/jit-playback.cc
index 069ed70..96e9227 100644
--- a/gcc/jit/jit-playback.cc
+++ b/gcc/jit/jit-playback.cc
@@ -1213,7 +1213,7 @@ playback::rvalue *
playback::context::
new_comparison (location *loc,
enum gcc_jit_comparison op,
- rvalue *a, rvalue *b)
+ rvalue *a, rvalue *b, type *vec_result_type)
{
// FIXME: type-checking, or coercion?
enum tree_code inner_op;
@@ -1252,10 +1252,27 @@ new_comparison (location *loc,
tree node_b = b->as_tree ();
node_b = fold_const_var (node_b);
- tree inner_expr = build2 (inner_op,
- boolean_type_node,
- node_a,
- node_b);
+ tree inner_expr;
+ tree a_type = TREE_TYPE (node_a);
+ if (VECTOR_TYPE_P (a_type))
+ {
+ /* Build a vector comparison. See build_vec_cmp in c-typeck.cc for
+ reference. */
+ tree t_vec_result_type = vec_result_type->as_tree ();
+ tree zero_vec = build_zero_cst (t_vec_result_type);
+ tree minus_one_vec = build_minus_one_cst (t_vec_result_type);
+ tree cmp_type = truth_type_for (a_type);
+ tree cmp = build2 (inner_op, cmp_type, node_a, node_b);
+ inner_expr = build3 (VEC_COND_EXPR, t_vec_result_type, cmp, minus_one_vec,
+ zero_vec);
+ }
+ else
+ {
+ inner_expr = build2 (inner_op,
+ boolean_type_node,
+ node_a,
+ node_b);
+ }
/* Try to fold. */
inner_expr = fold (inner_expr);
diff --git a/gcc/jit/jit-playback.h b/gcc/jit/jit-playback.h
index 1aeee2c..214f399 100644
--- a/gcc/jit/jit-playback.h
+++ b/gcc/jit/jit-playback.h
@@ -162,7 +162,7 @@ public:
rvalue *
new_comparison (location *loc,
enum gcc_jit_comparison op,
- rvalue *a, rvalue *b);
+ rvalue *a, rvalue *b, type *vec_result_type);
rvalue *
new_call (location *loc,
diff --git a/gcc/jit/jit-recording.cc b/gcc/jit/jit-recording.cc
index 6ae5a66..2ce2722 100644
--- a/gcc/jit/jit-recording.cc
+++ b/gcc/jit/jit-recording.cc
@@ -5836,7 +5836,8 @@ recording::comparison::replay_into (replayer *r)
set_playback_obj (r->new_comparison (playback_location (r, m_loc),
m_op,
m_a->playback_rvalue (),
- m_b->playback_rvalue ()));
+ m_b->playback_rvalue (),
+ m_type->playback_type ()));
}
/* Implementation of pure virtual hook recording::rvalue::visit_children
diff --git a/gcc/jit/jit-recording.h b/gcc/jit/jit-recording.h
index 8610ea9..5d7c717 100644
--- a/gcc/jit/jit-recording.h
+++ b/gcc/jit/jit-recording.h
@@ -1683,7 +1683,23 @@ public:
m_op (op),
m_a (a),
m_b (b)
- {}
+ {
+ type *a_type = a->get_type ();
+ vector_type *vec_type = a_type->dyn_cast_vector_type ();
+ if (vec_type != NULL)
+ {
+ type *element_type = vec_type->get_element_type ();
+ type *inner_type;
+ /* Vectors of floating-point values return a vector of integers of the
+ same size. */
+ if (element_type->is_float ())
+ inner_type = ctxt->get_int_type (element_type->get_size (), false);
+ else
+ inner_type = element_type;
+ m_type = new vector_type (inner_type, vec_type->get_num_units ());
+ ctxt->record (m_type);
+ }
+ }
void replay_into (replayer *r) final override;