The result of a signed remainder operation with a constant divisor is limited
in absolute value to less than the value of the divisor.  Following it with
code to force the remainder to be positive by adjusting the quotient and
remainder values is pretty straightforward.  However, if it's written as a loop
it doesn't get optimized well.

The rtl initially generated appears to have the loop transformed into
arithmetic to figure out the number of times the loop would run, in a branch
conditionalized on whether the loop would be run at all.  (Actually, it appears
to run the loop body once, and then do math to figure out how many more times.)
 However, the compiler doesn't figure out that in that branch, the loop body
would be run exactly once, either in the tree or rtl optimizations.


-- 
           Summary: limited range of remainder operation can prove loop runs
                    at most once
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: raeburn at raeburn dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33259

Reply via email to