Skip to content

Commit f1dcc0f

Browse files
middle-end: prevent LIM from hoising vector compares from gconds if target 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.
1 parent 0994ddd commit f1dcc0f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

gcc/tree-ssa-loop-im.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ along with GCC; see the file COPYING3. If not see
4848
#include "tree-dfa.h"
4949
#include "tree-ssa.h"
5050
#include "dbgcnt.h"
51+
#include "insn-codes.h"
52+
#include "optabs-tree.h"
5153

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

857+
/* Check if one of the depedent statement is a vector compare whether
858+
the target supports it, otherwise it's invalid to hoist it out of
859+
the gcond it belonged to. */
860+
if (VECTOR_TYPE_P (TREE_TYPE (gimple_cond_lhs (cond))))
861+
{
862+
tree type = TREE_TYPE (gimple_cond_lhs (cond));
863+
auto code = gimple_cond_code (cond);
864+
if (!target_supports_op_p (type, code, optab_vector))
865+
return false;
866+
}
867+
855868
/* Fold in dependencies and cost of the condition. */
856869
FOR_EACH_SSA_TREE_OPERAND (val, cond, iter, SSA_OP_USE)
857870
{

0 commit comments

Comments
 (0)