stmt_vec_info stmt_info, slp_tree node,
tree vectype, int misalign,
vect_cost_model_location where) override;
+ void finish_cost (const vector_costs *) override;
};
/* Implement targetm.vectorize.create_costs. */
return retval;
}
+void
+ix86_vector_costs::finish_cost (const vector_costs *scalar_costs)
+{
+ loop_vec_info loop_vinfo = dyn_cast<loop_vec_info> (m_vinfo);
+ if (loop_vinfo && !m_costing_for_scalar)
+ {
+ /* We are currently not asking the vectorizer to compare costs
+ between different vector mode sizes. When using predication
+ that will end up always choosing the prefered mode size even
+ if there's a smaller mode covering all lanes. Test for this
+ situation and artificially reject the larger mode attempt.
+ ??? We currently lack masked ops for sub-SSE sized modes,
+ so we could restrict this rejection to AVX and AVX512 modes
+ but error on the safe side for now. */
+ if (LOOP_VINFO_USING_PARTIAL_VECTORS_P (loop_vinfo)
+ && !LOOP_VINFO_EPILOGUE_P (loop_vinfo)
+ && LOOP_VINFO_NITERS_KNOWN_P (loop_vinfo)
+ && (exact_log2 (LOOP_VINFO_VECT_FACTOR (loop_vinfo).to_constant ())
+ > ceil_log2 (LOOP_VINFO_INT_NITERS (loop_vinfo))))
+ m_costs[vect_body] = INT_MAX;
+ }
+
+ vector_costs::finish_cost (scalar_costs);
+}
+
/* Validate target specific memory model bits in VAL. */
static unsigned HOST_WIDE_INT
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -mavx512f -mavx512vl -mprefer-vector-width=512 --param vect-partial-vector-usage=1" } */
+
+void foo (int * __restrict a, int *b)
+{
+ for (int i = 0; i < 4; ++i)
+ a[i] = b[i] + 42;
+}
+
+/* We do not want to optimize this using masked AVX or AXV512
+ but unmasked SSE. */
+/* { dg-final { scan-assembler-not "\[yz\]mm" } } */
+/* { dg-final { scan-assembler "xmm" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -mavx512f -mavx512vl -mprefer-vector-width=512 --param vect-partial-vector-usage=1" } */
+
+void foo (int * __restrict a, int *b)
+{
+ for (int i = 0; i < 7; ++i)
+ a[i] = b[i] + 42;
+}
+
+/* We want to optimize this using masked AVX, not AXV512 or SSE. */
+/* { dg-final { scan-assembler-not "zmm" } } */
+/* { dg-final { scan-assembler "ymm\[^\r\n\]*\{%k" } } */