Skip to content

Commit

Permalink
Fix float vector comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
antoyo committed Jun 24, 2022
1 parent 2586690 commit c689be4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
9 changes: 5 additions & 4 deletions gcc/jit/jit-playback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,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;
Expand Down Expand Up @@ -1332,11 +1332,12 @@ new_comparison (location *loc,
if (VECTOR_TYPE_P (a_type))
{
// TODO: document where this comes from and what it is doing.
tree zero_vec = build_zero_cst (a_type);
tree minus_one_vec = build_minus_one_cst (a_type);
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, a_type, cmp, minus_one_vec, zero_vec);
inner_expr = build3 (VEC_COND_EXPR, t_vec_result_type, cmp, minus_one_vec, zero_vec);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion gcc/jit/jit-playback.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class context : public log_user
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,
Expand Down
3 changes: 2 additions & 1 deletion gcc/jit/jit-recording.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6061,7 +6061,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
Expand Down
15 changes: 13 additions & 2 deletions gcc/jit/jit-recording.h
Original file line number Diff line number Diff line change
Expand Up @@ -1836,9 +1836,20 @@ class comparison : public rvalue
m_b (b)
{
type *a_type = a->get_type ();
if (a_type->dyn_cast_vector_type () != NULL)
vector_type *vec_type = a_type->dyn_cast_vector_type ();
if (vec_type != NULL)
{
m_type = a_type;
type *element_type = vec_type->get_element_type ();
type *inner_type;
if (element_type == ctxt->get_type (GCC_JIT_TYPE_FLOAT))
/* TODO: choose correct int type by size instead. */
inner_type = ctxt->get_type (GCC_JIT_TYPE_INT);
else if (element_type == ctxt->get_type (GCC_JIT_TYPE_DOUBLE))
inner_type = ctxt->get_type (GCC_JIT_TYPE_LONG);
else
inner_type = element_type;
m_type = new vector_type (inner_type, vec_type->get_num_units ());
ctxt->record (m_type);
}
}

Expand Down

0 comments on commit c689be4

Please sign in to comment.