https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81461

--- Comment #2 from Antony Polukhin <antoshkka at gmail dot com> ---
(In reply to Richard Biener from comment #1)
> jump threading

Thanks, now I know hot the transformation of

        for (;it != end && it != *chunks + 128; ++it) {
            sum += *it;
        }

into

        new_end = (it <= end && end <= *chunks + 128 ? end : *chunks + 128);
        for (;new_end; ++it) {
            sum += *it;
        }

is called!

Loop unswitching will also do the job, but it produces a ~5 instructions longer
assembly because of the loop's body duplication: 

    if (it <= end && end <= *chunks + 128) {
        for (;it != end;
          ++it) { sum += *it; } // duplicated
    } else {
        for (;it != *chunks + 128;
          ++it) { sum += *it; } // duplicated
    }

Reply via email to