Skip to content

Missed optimization of empty for loop function into just ret #69833

Closed
@Rageking8

Description

#include <unordered_map>

void foo(std::unordered_map<int, int> umap)
{
    for (const auto& i : umap) {}
}
foo(std::unordered_map<int, int, std::hash<int>, std::equal_to<int>, std::allocator<std::pair<int const, int> > >): # @foo(std::unordered_map<int, int, std::hash<int>, std::equal_to<int>, std::allocator<std::pair<int const, int> > >)
        add     rdi, 16
.LBB0_1:                                # =>This Inner Loop Header: Depth=1
        mov     rdi, qword ptr [rdi]
        test    rdi, rdi
        jne     .LBB0_1
        ret

https://godbolt.org/z/cdavsPGq5

Tested on x86-64 clang (trunk), the above function get fully optimized to just ret on gcc (trunk).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions