https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93002
--- Comment #4 from Uroš Bizjak <ubizjak at gmail dot com> --- (In reply to Jakub Jelinek from comment #2) > The question is where to do that. Is that something ivopts should do > (perhaps based on some rtl cost or whatever), or shall it be done during > expansion (unfortunately, expansion expands the decrement and comparison > separately, because the result of decrement is used multiple times, but on > the other hand has the range information, like for unsigned iterator: > # RANGE ~[999, 4294967294] > i_5 = i_12 + 4294967295; > if (i_5 != 4294967295) > or for signed one: > # RANGE [-1, 998] > i_4 = i_11 + -1; > if (i_4 != -1(OVF)) > or shall config/i386 enable the doloop patterns? Or peephole2? > Combine won't do anything, as the result of the decrement is used multiple > times. > Or compare-elim.c? That one fails, because it tries to > (parallel [ > (set (reg:CCZ 17 flags) > (compare:CCZ (plus:SI (reg/v:SI 0 ax [orig:83 i ] [83]) > (const_int -1 [0xffffffffffffffff])) > (const_int -1 [0xffffffffffffffff]))) > (set (reg/v:SI 0 ax [orig:83 i ] [83]) > (plus:SI (reg/v:SI 0 ax [orig:83 i ] [83]) > (const_int -1 [0xffffffffffffffff]))) > ]) > and the CCZmode is really wrong in this case, for this optimization we > really need CCmode or something similar and make try_eliminate_compare > adjust also the mode on the use of the flags register if possible. CCing > also Richard as compare-elim.c author. > Doing it in peephole2 would require that the 3 insns are consecutive, which > is the case here. Maybe we can introduce the above insn as insn_and_split pattern that is later split to CCmode insns? cmpelim pass will then be able to synthesize the insn.