https://bugs.llvm.org/show_bug.cgi?id=43657

            Bug ID: 43657
           Summary: Redundant computations should be optimized out
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: LLVM Codegen
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected]

For the following code:

#include <vector>

int foo(std::vector<int> a, std::vector<int> b)
{
    int res = 0;

    if(a.size() == b.size())
    {
        res = a.size() - b.size();
    }

    return res;
}

clang(trunk) with -O3 generates:

foo(std::vector<int, std::allocator<int> >, std::vector<int,
std::allocator<int> >):             # @foo(std::vector<int, std::allocator<int>
>, std::vector<int, std::allocator<int> >)
        mov     rcx, qword ptr [rdi + 8]
        sub     rcx, qword ptr [rdi]
        sar     rcx, 2
        mov     rdx, qword ptr [rsi + 8]
        sub     rdx, qword ptr [rsi]
        sar     rdx, 2
        mov     esi, ecx
        sub     esi, edx
        xor     eax, eax
        cmp     rcx, rdx
        cmove   eax, esi
        ret

gcc(trunk) with -O3 generates:

foo(std::vector<int, std::allocator<int> >, std::vector<int,
std::allocator<int> >):
        xor     eax, eax
        ret


Godbolt link: https://godbolt.org/z/s1cwUt

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to