This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug tree-optimization/81461] Optimization for removing same variable comparisons in loop: while(it != end1 && it != end2)


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
    }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]