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

            Bug ID: 47794
           Summary: missed optimization to use MOVS to copy arrays
           Product: clang
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: LLVM Codegen
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected]

For example the following code generates `MOVSQ` with GCC, and `call memcpy`
with Clang:
https://godbolt.org/z/15bPh5
```
#include <iostream>
#include <array>
#include <random>
using namespace std;

random_device rd;

int main()
{
    std::array<char, 512> a;
    std::array<char, 512> b;

    for(auto& e : a) { // prevent optimizing away
        e = rd();
    }

    for(int i=0; i < a.size(); ++i) { // copy
        b[i] = a[i];
    }

    for(auto const& e : b) { // prevent optimizing away
        cout << e;
    }
}
```

It seems that using MOVSQ is about 4-5 times faster:
Clang: https://quick-bench.com/q/LK5SmbOYZc8T-Kvy48jsf1tAL9w
GCC: https://quick-bench.com/q/qG8ApWJV7Ad-ghub2of6C_WWMYM

-- 
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