Skip to content

Commit

Permalink
middle-end: prevent LIM from hoising vector compares from gconds if t…
Browse files Browse the repository at this point in the history
…arget does not support it.

LIM notices that in some cases the condition and the results are loop
invariant and tries to move them out of the loop.

While the resulting code is operationally sound, moving the compare out of the
gcond results in generating code that no longer branches, so cbranch is no
longer applicable.  As such I now add code to check during this motion to see
if the target supports flag setting vector comparison as general operation.

I have tried writing a GIMPLE testcase for this but the gimple FE seems to be
having some trouble with the vector types.  It seems to fail parsing.

The early break code testsuite however has a test for this
(vect-early-break_67.c).

gcc/ChangeLog:

	* tree-ssa-loop-im.cc (determine_max_movement): Import insn-codes.h
	and optabs-tree.h and check for vector compare motion out of gcond.
  • Loading branch information
TamarChristinaArm committed Dec 24, 2023
1 parent 0994ddd commit f1dcc0f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions gcc/tree-ssa-loop-im.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ along with GCC; see the file COPYING3. If not see
#include "tree-dfa.h"
#include "tree-ssa.h"
#include "dbgcnt.h"
#include "insn-codes.h"
#include "optabs-tree.h"

/* TODO: Support for predicated code motion. I.e.
Expand Down Expand Up @@ -852,6 +854,17 @@ determine_max_movement (gimple *stmt, bool must_preserve_exec)
if (!extract_true_false_args_from_phi (dom, phi, NULL, NULL))
return false;

/* Check if one of the depedent statement is a vector compare whether
the target supports it, otherwise it's invalid to hoist it out of
the gcond it belonged to. */
if (VECTOR_TYPE_P (TREE_TYPE (gimple_cond_lhs (cond))))
{
tree type = TREE_TYPE (gimple_cond_lhs (cond));
auto code = gimple_cond_code (cond);
if (!target_supports_op_p (type, code, optab_vector))
return false;
}

/* Fold in dependencies and cost of the condition. */
FOR_EACH_SSA_TREE_OPERAND (val, cond, iter, SSA_OP_USE)
{
Expand Down

0 comments on commit f1dcc0f

Please sign in to comment.