https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103641

--- Comment #20 from Roger Sayle <roger at nextmovesoftware dot com> ---
IMHO, the problem is in tree-vect-patterns.cc's vect_synth_mult_by_constant.
The comment above line 3054 reads:
  /* Use MAX_COST here as we don't want to limit the sequence on rtx costs.
     The vectorizer's benefit analysis will decide whether it's beneficial
     to do this.  */
  bool possible = choose_mult_variant (mode, hwval, &alg, &variant, MAX_COST);

By using MAX_COST here, synth_mult is being allowed to take an unbounded
amount of time, considering all possible permutations/implementations to
find an optimal synthetic multiply sequence.  A more pragmatic bound might
be to compare the target's vector_multiply cost, or failing that use an
arbitrary, but reasonable limit, say COSTS_N_INSNS(8) machine instructions.
In the worst case, if it takes 100 instructions to do a vector multiply,
then the loop probably shouldn't be vectorized.

Reply via email to