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: unassignedclangb...@nondot.org
Reporter: zamazan...@tut.by
CC: dgre...@apple.com, llvm-bugs@lists.llvm.org,
richard-l...@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs