This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/81461] Optimization for removing same variable comparisons in loop: while(it != end1 && it != end2)
- From: "antoshkka at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 17 Jul 2017 13:34:56 +0000
- Subject: [Bug tree-optimization/81461] Optimization for removing same variable comparisons in loop: while(it != end1 && it != end2)
- Auto-submitted: auto-generated
- References: <bug-81461-4@http.gcc.gnu.org/bugzilla/>
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
}