https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68021
--- Comment #14 from Jakub Jelinek <jakub at gcc dot gnu.org> --- (In reply to amker from comment #13) > Hmm, I posted a patch at > https://gcc.gnu.org/ml/gcc-patches/2016-02/msg00447.html > But after digging deeper I think the posted is unnecessary and it should be > fixed in fold stuff. > > The ivopt logic is > 1) create iv use for original biv candidate chosen by the algorithm. > 2) rewrite iv use created in 1) using the original biv in > rewrite_use_nonlinear_expr. (Here we use nonlinear use as the example) > 3) If the iv use is exact the candidate increment stmt, then skip rewriting > since the computation is already there. > 4) If that's not the case (in 3), it falls through and uses get_computation > to rewrite the use. As commented in #10, this may introduce redundant code, > we rely on following passes to remove them. > > So for this case, the iv use created is direct for an original biv var. The > values of the iv use and the original biv are same to each other. Just the > iv use will be rewrite in a different form of computation to the original > biv. > > In other words, it is guaranteed that the iv use has same value as original > candidate when control flow comes to the ICE point. The ICE really is > caused by inconsistent fold behavior. > > So IMHO, we may have to fix the fold part... I'm afraid we can't guarantee you'll get always operand_equal_p results from the folding, if you start folding in different orders etc. The issue mentioned here is just one case we know of. So, IMHO it must be solved in the IVOPTs side, either by giving up somewhere and not using candidate that would not be recognized during rewriting, or by always folding the same operands in the same order if it is the same thing, or just noting it is the same thing somewhere (and/or remembering the multiply factor) and not trying the constant_multiple_of. Incremental improvements on the folding side will then incrementally improve stuff on the IVOPTs side, but you won't ICE on arbitrary cases that aren't handled yet.