This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/64454] optimize (x%5)%5
- From: "glisse at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 15 May 2015 18:30:49 +0000
- Subject: [Bug tree-optimization/64454] optimize (x%5)%5
- Auto-submitted: auto-generated
- References: <bug-64454-4 at http dot gcc dot gnu dot org/bugzilla/>
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...