This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/81409] New: Inefficient loops generated from range-v3 code
- From: "kristerw at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 12 Jul 2017 09:21:54 +0000
- Subject: [Bug tree-optimization/81409] New: Inefficient loops generated from range-v3 code
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81409
Bug ID: 81409
Summary: Inefficient loops generated from range-v3 code
Product: gcc
Version: 8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: kristerw at gcc dot gnu.org
Target Milestone: ---
Created attachment 41728
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=41728&action=edit
Preprocessed file for run_range()
The range-v3 (https://github.com/ericniebler/range-v3) function
long run_range(std::vector<int> const &lengths, long to_find)
{
auto const found_index = ranges::distance(lengths
| ranges::view::transform(ranges::convert_to<long>{})
| ranges::view::partial_sum()
| ranges::view::take_while([=](auto const i) {
return !(to_find < i);
}));
return found_index;
}
is generated as slow code with GCC, needing 3x the time to run compared to the
code generated by LLVM (when compiled with "-O3 -std=c++14 -DNDEBUG"). The
calculation done in run_range() is the equivalent of
long run_forloop(std::vector<int> const &vec, long to_find)
{
long len = vec.end() - vec.begin();
const int *p = &vec[0];
long i, acc = 0;
for (i = 0; i < len; i++) {
acc += p[i];
if (to_find < acc)
break;
}
return i;
}
and LLVM manages to generate similar code for both functions, while GCC seems
to be confused by the run_range() loop and generates extra comparisions and a
somewhat messy code flow...