[llvm-bugs] [Bug 39515] New: Missed optimization: useless for-loop must be eliminated
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Nov 1 06:19:17 PDT 2018
https://bugs.llvm.org/show_bug.cgi?id=39515
Bug ID: 39515
Summary: Missed optimization: useless for-loop must be
eliminated
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: zamazan4ik at tut.by
CC: dgregor at apple.com, llvm-bugs at lists.llvm.org,
richard-llvm at metafoo.co.uk
clang(trunk) with '-O3 -std=c++17' for this code:
#include <vector>
#include <algorithm>
int foo(std::vector<int> v) {
int l = v[0];
for(const auto& x : v) {
l = std::min(l, x);
}
for(const auto& x : v) {
l = std::max(l, x);
}
return l;
}
gcc doesn't eliminate first loop, but gcc can, because first loop has no effect
in this function.
Same result for the version without std::vector and std::max:
int min(int a, int b)
{
return a < b ? a : b;
}
int max(int a, int b)
{
return a > b ? a : b;
}
int foo(int* v, int size) {
int l = v[0];
for(int i=0; i < size; ++i)
{
l = min(l, v[i]);
}
for(int i=0; i < size; ++i)
{
l = max(l, v[i]);
}
return l;
}
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20181101/b639e294/attachment.html>
More information about the llvm-bugs
mailing list