On Mon, Jun 3, 2019 at 12:38 PM Eric Botcazou <ebotca...@adacore.com> wrote: > > > Hmm, ISTR we had such mitigations in place (or have) elsewhere keying > > on the most significant bit set instead of power-of-two. But your case > > likely recurses and runs into the extract_multiv limiting to eventually > > stop, even for (N + 4) * 8, right? If so shouldn't we prevent this > > even for !TYPE_OVERFLOW_WRAPS? Also > > > > + && !(tree_fits_shwi_p (c) > > + && exact_log2 (absu_hwi (tree_to_shwi (c))) > 0)) > > > > is better written as > > > > && exact_log2 (wi::to_wide (c)) > 0 > > It turns out that pow2p_hwi can be used instead and is cheaper, so I have > changed both extract_muldiv_1 and fold_plusminus_mult_expr to using it.
OK, thanks. Richard. > > * fold-const.c (extract_muldiv_1) <PLUS_EXPR>: Do not distribute a > multiplication by a power-of-two value. > (fold_plusminus_mult_expr): Use pow2p_hwi to detect a power-of-two > value > and turn the modulo operation into a masking operation. > > -- > Eric Botcazou