https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64454
--- Comment #14 from Marc Glisse <glisse at gcc dot gnu.org> --- (In reply to Andrew Pinski from comment #13) > It might also be useful if the range is [0,10] for x%5 to be simplified down > to just "t = x-5; x>=5?t:x;" (I assume you meant [0,9]) I agree, but the profitability is less obvious with branches/cmov. > And yes this shows up in some places; mainly > dealing with character digit to number conversions. I expect one of the most common cases to be a loop that does x=(x+1)%5; at each iteration (so x is always in [0,4]), which can be rewritten as if(++x==5)x=0. Maybe we could open a new PR for those...