Issue |
151390
|
Summary |
Missing optimization for return vector used inside a function.
|
Labels |
new issue
|
Assignees |
|
Reporter |
AlexgitHubAlex
|
Optimization that removes vector allocations works correctly in simple cases. When the code becomes more complex, optimization is disabled.
`
#include <vector>
#include <iostream>
int foo() {
std::vector<int> vec1 = {16,2,77,29};
return vec1[3];
} // OK
int bar() {
std::vector<int> vec1 = {16,2,77,29};
std::cout << vec1[0]<< vec1[1];
return 0;
} // OK
int baz() {
std::vector<int> vec1 = {16,2,77,29};
std::cout << vec1[0]<< vec1[1];
return vec1[3];
} // Return value of part object broken remove allocation in vector implementation
`
The baz function preserves memory allocation which can be optimized.
https://godbolt.org/z/xz9jxr8GP
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs