@@ -296,6 +296,8 @@ scalar_chain::scalar_chain (enum machine_mode smode_, enum machine_mode vmode_)
n_sse_to_integer = 0;
n_integer_to_sse = 0;
+
+ max_visits = x86_stv_max_visits;
}
/* Free chain's data. */
@@ -354,10 +356,12 @@ scalar_chain::mark_dual_mode_def (df_ref def)
}
/* Check REF's chain to add new insns into a queue
- and find registers requiring conversion. */
+ and find registers requiring conversion. Return true if OK, false
+ if the analysis was aborted. */
-void
-scalar_chain::analyze_register_chain (bitmap candidates, df_ref ref)
+bool
+scalar_chain::analyze_register_chain (bitmap candidates, df_ref ref,
+ bitmap disallowed)
{
df_link *chain;
bool mark_def = false;
@@ -371,6 +375,9 @@ scalar_chain::analyze_register_chain (bitmap candidates, df_ref ref)
if (!NONDEBUG_INSN_P (DF_REF_INSN (chain->ref)))
continue;
+ if (--max_visits == 0)
+ return false;
+
if (!DF_REF_REG_MEM_P (chain->ref))
{
if (bitmap_bit_p (insns, uid))
@@ -381,6 +388,10 @@ scalar_chain::analyze_register_chain (bitmap candidates, df_ref ref)
add_to_queue (uid);
continue;
}
+
+ /* If we run into parts of an aborted chain discovery abort. */
+ if (bitmap_bit_p (disallowed, uid))
+ return false;
}
if (DF_REF_REG_DEF_P (chain->ref))
@@ -401,15 +412,19 @@ scalar_chain::analyze_register_chain (bitmap candidates, df_ref ref)
if (mark_def)
mark_dual_mode_def (ref);
+
+ return true;
}
-/* Add instruction into a chain. */
+/* Add instruction into a chain. Return true if OK, false if the search
+ was aborted. */
-void
-scalar_chain::add_insn (bitmap candidates, unsigned int insn_uid)
+bool
+scalar_chain::add_insn (bitmap candidates, unsigned int insn_uid,
+ bitmap disallowed)
{
if (!bitmap_set_bit (insns, insn_uid))
- return;
+ return true;
if (dump_file)
fprintf (dump_file, " Adding insn %d to chain #%d\n", insn_uid, chain_id);
@@ -426,22 +441,27 @@ scalar_chain::add_insn (bitmap candidates, unsigned int insn_uid)
df_ref ref;
for (ref = DF_INSN_UID_DEFS (insn_uid); ref; ref = DF_REF_NEXT_LOC (ref))
if (!HARD_REGISTER_P (DF_REF_REG (ref)))
- analyze_register_chain (candidates, ref);
+ if (!analyze_register_chain (candidates, ref, disallowed))
+ return false;
/* The operand(s) of VEC_SELECT don't need to be converted/convertible. */
if (def_set && GET_CODE (SET_SRC (def_set)) == VEC_SELECT)
- return;
+ return true;
for (ref = DF_INSN_UID_USES (insn_uid); ref; ref = DF_REF_NEXT_LOC (ref))
if (!DF_REF_REG_MEM_P (ref))
- analyze_register_chain (candidates, ref);
+ if (!analyze_register_chain (candidates, ref, disallowed))
+ return false;
+
+ return true;
}
/* Build new chain starting from insn INSN_UID recursively
- adding all dependent uses and definitions. */
+ adding all dependent uses and definitions. Return true if OK, false
+ if the chain discovery was aborted. */
-void
-scalar_chain::build (bitmap candidates, unsigned insn_uid)
+bool
+scalar_chain::build (bitmap candidates, unsigned insn_uid, bitmap disallowed)
{
queue = BITMAP_ALLOC (NULL);
bitmap_set_bit (queue, insn_uid);
@@ -454,7 +474,17 @@ scalar_chain::build (bitmap candidates, unsigned insn_uid)
insn_uid = bitmap_first_set_bit (queue);
bitmap_clear_bit (queue, insn_uid);
bitmap_clear_bit (candidates, insn_uid);
- add_insn (candidates, insn_uid);
+ if (!add_insn (candidates, insn_uid, disallowed))
+ {
+ /* If we aborted the search put sofar found insn on the set of
+ disallowed insns so that further searches reaching them also
+ abort and thus we abort the whole but yet undiscovered chain. */
+ bitmap_ior_into (disallowed, insns);
+ if (dump_file)
+ fprintf (dump_file, "Aborted chain #%d discovery\n", chain_id);
+ BITMAP_FREE (queue);
+ return false;
+ }
}
if (dump_file)
@@ -478,6 +508,8 @@ scalar_chain::build (bitmap candidates, unsigned insn_uid)
}
BITMAP_FREE (queue);
+
+ return true;
}
/* Return a cost of building a vector costant
@@ -2282,6 +2314,7 @@ convert_scalars_to_vector (bool timode_p)
for (unsigned i = 0; i <= 2; ++i)
{
+ auto_bitmap disallowed;
bitmap_tree_view (&candidates[i]);
while (!bitmap_empty_p (&candidates[i]))
{
@@ -2296,14 +2329,14 @@ convert_scalars_to_vector (bool timode_p)
/* Find instructions chain we want to convert to vector mode.
Check all uses and definitions to estimate all required
conversions. */
- chain->build (&candidates[i], uid);
-
- if (chain->compute_convert_gain () > 0)
- converted_insns += chain->convert ();
- else
- if (dump_file)
- fprintf (dump_file, "Chain #%d conversion is not profitable\n",
- chain->chain_id);
+ if (chain->build (&candidates[i], uid, disallowed))
+ {
+ if (chain->compute_convert_gain () > 0)
+ converted_insns += chain->convert ();
+ else if (dump_file)
+ fprintf (dump_file, "Chain #%d conversion is not profitable\n",
+ chain->chain_id);
+ }
delete chain;
}
@@ -148,12 +148,15 @@ class scalar_chain
/* Registers used in both vector and sclar modes. */
bitmap defs_conv;
+ /* Limit on chain discovery. */
+ unsigned max_visits;
+
bitmap insns_conv;
hash_map<rtx, rtx> defs_map;
unsigned n_sse_to_integer;
unsigned n_integer_to_sse;
- void build (bitmap candidates, unsigned insn_uid);
+ bool build (bitmap candidates, unsigned insn_uid, bitmap disallowed);
virtual int compute_convert_gain () = 0;
int convert ();
@@ -168,8 +171,9 @@ class scalar_chain
void convert_registers ();
private:
- void add_insn (bitmap candidates, unsigned insn_uid);
- void analyze_register_chain (bitmap candidates, df_ref ref);
+ bool add_insn (bitmap candidates, unsigned insn_uid, bitmap disallowed);
+ bool analyze_register_chain (bitmap candidates, df_ref ref,
+ bitmap disallowed);
virtual void convert_insn (rtx_insn *insn) = 0;
virtual void convert_op (rtx *op, rtx_insn *insn) = 0;
};
@@ -599,6 +599,10 @@ Target Mask(STV) Save
Disable Scalar to Vector optimization pass transforming 64-bit integer
computations into a vector ones.
+-param=x86-stv-max-visits=
+Target Joined UInteger Var(x86_stv_max_visits) Init(10000) IntegerRange(1, 1000000) Param
+The maximum number of use and def visits when discovering a STV chain before the discovery is aborted.
+
mdispatch-scheduler
Target RejectNegative Var(flag_dispatch_scheduler)
Do dispatch scheduling if processor is bdver1, bdver2, bdver3, bdver4
@@ -16229,6 +16229,10 @@ The following choices of @var{name} are available on i386 and x86_64 targets:
@item x86-stlf-window-ninsns
Instructions number above which STFL stall penalty can be compensated.
+@item x86-stv-max-visits
+The maximum number of use and def visits when discovering a STV chain before
+the discovery is aborted.
+
@end table
@end table