public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug tree-optimization/115040] New: Missed optimization opportunity in std::find @ 2024-05-10 22:42 sjames at gcc dot gnu.org 2024-05-10 22:52 ` [Bug tree-optimization/115040] Missed optimization opportunity in std::find of std::vector elements pinskia at gcc dot gnu.org ` (4 more replies) 0 siblings, 5 replies; 6+ messages in thread From: sjames at gcc dot gnu.org @ 2024-05-10 22:42 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115040 Bug ID: 115040 Summary: Missed optimization opportunity in std::find Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: hiraditya at msn dot com Target Milestone: --- https://gcc.godbolt.org/z/s3hv15935 ``` #include <algorithm> #include <vector> #include <cstdint> bool find_epi8(const std::vector<int8_t>& v) { return std::find(v.begin(), v.end(), 42) != v.end(); } bool find_epi32(const std::vector<int32_t>& v) { return std::find(v.begin(), v.end(), 42) != v.end(); } ``` $ gcc -O3 -ftree-vectorize -march=pantherlake ``` find_epi8(std::vector<signed char, std::allocator<signed char> > const&): mov rcx, QWORD PTR [rdi+8] mov rdx, QWORD PTR [rdi] mov rsi, rcx sub rsi, rdx mov rax, rsi sar rax, 2 test rax, rax jle .L2 lea rax, [rdx+rax*4] jmp .L8 .L3: cmp BYTE PTR [rdx+1], 42 je .L23 cmp BYTE PTR [rdx+2], 42 je .L24 cmp BYTE PTR [rdx+3], 42 je .L25 add rdx, 4 cmp rdx, rax je .L26 .L8: cmp BYTE PTR [rdx], 42 jne .L3 .L21: cmp rcx, rdx setne al ret .L26: mov rsi, rcx sub rsi, rdx .L2: cmp rsi, 2 je .L9 cmp rsi, 3 je .L10 cmp rsi, 1 je .L11 xor eax, eax ret .L10: cmp BYTE PTR [rdx], 42 je .L21 add rdx, 1 .L9: cmp BYTE PTR [rdx], 42 je .L21 add rdx, 1 .L11: cmp BYTE PTR [rdx], 42 sete al cmp rcx, rdx setne dl and eax, edx ret .L23: add rdx, 1 cmp rcx, rdx setne al ret .L24: add rdx, 2 cmp rcx, rdx setne al ret .L25: add rdx, 3 cmp rcx, rdx setne al ret find_epi32(std::vector<int, std::allocator<int> > const&): mov rcx, QWORD PTR [rdi+8] mov rdx, QWORD PTR [rdi] mov rax, rcx sub rax, rdx mov rsi, rax sar rax, 4 sar rsi, 2 test rax, rax jle .L28 sal rax, 4 add rax, rdx jmp .L34 .L29: cmp DWORD PTR [rdx+4], 42 je .L48 cmp DWORD PTR [rdx+8], 42 je .L49 cmp DWORD PTR [rdx+12], 42 je .L50 add rdx, 16 cmp rdx, rax je .L51 .L34: cmp DWORD PTR [rdx], 42 jne .L29 .L47: cmp rcx, rdx setne al ret .L51: mov rsi, rcx sub rsi, rdx sar rsi, 2 .L28: cmp rsi, 2 je .L35 cmp rsi, 3 je .L36 cmp rsi, 1 je .L37 xor eax, eax ret .L36: cmp DWORD PTR [rdx], 42 je .L47 add rdx, 4 .L35: cmp DWORD PTR [rdx], 42 je .L47 add rdx, 4 .L37: cmp DWORD PTR [rdx], 42 sete al cmp rcx, rdx setne dl and eax, edx ret .L48: add rdx, 4 cmp rcx, rdx setne al ret .L49: add rdx, 8 cmp rcx, rdx setne al ret .L50: add rdx, 12 cmp rcx, rdx setne al ret ``` clang lowers both the calls to (w)memchr --- Comment #1 from Sam James <sjames at gcc dot gnu.org> --- *** Bug 115041 has been marked as a duplicate of this bug. *** ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/115040] Missed optimization opportunity in std::find of std::vector elements 2024-05-10 22:42 [Bug tree-optimization/115040] New: Missed optimization opportunity in std::find sjames at gcc dot gnu.org @ 2024-05-10 22:52 ` pinskia at gcc dot gnu.org 2024-05-10 22:56 ` pinskia at gcc dot gnu.org ` (3 subsequent siblings) 4 siblings, 0 replies; 6+ messages in thread From: pinskia at gcc dot gnu.org @ 2024-05-10 22:52 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115040 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Severity|normal |enhancement ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/115040] Missed optimization opportunity in std::find of std::vector elements 2024-05-10 22:42 [Bug tree-optimization/115040] New: Missed optimization opportunity in std::find sjames at gcc dot gnu.org 2024-05-10 22:52 ` [Bug tree-optimization/115040] Missed optimization opportunity in std::find of std::vector elements pinskia at gcc dot gnu.org @ 2024-05-10 22:56 ` pinskia at gcc dot gnu.org 2024-05-10 23:04 ` sjames at gcc dot gnu.org ` (2 subsequent siblings) 4 siblings, 0 replies; 6+ messages in thread From: pinskia at gcc dot gnu.org @ 2024-05-10 22:56 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115040 --- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> --- > clang lowers both the calls to (w)memchr Is that with libc++ or libstdc++? ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/115040] Missed optimization opportunity in std::find of std::vector elements 2024-05-10 22:42 [Bug tree-optimization/115040] New: Missed optimization opportunity in std::find sjames at gcc dot gnu.org 2024-05-10 22:52 ` [Bug tree-optimization/115040] Missed optimization opportunity in std::find of std::vector elements pinskia at gcc dot gnu.org 2024-05-10 22:56 ` pinskia at gcc dot gnu.org @ 2024-05-10 23:04 ` sjames at gcc dot gnu.org 2024-05-10 23:10 ` [Bug libstdc++/115040] " pinskia at gcc dot gnu.org 2024-05-13 13:11 ` redi at gcc dot gnu.org 4 siblings, 0 replies; 6+ messages in thread From: sjames at gcc dot gnu.org @ 2024-05-10 23:04 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115040 --- Comment #3 from Sam James <sjames at gcc dot gnu.org> --- (In reply to Andrew Pinski from comment #2) > > clang lowers both the calls to (w)memchr > > Is that with libc++ or libstdc++? It's libc++. Checked locally too.. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug libstdc++/115040] Missed optimization opportunity in std::find of std::vector elements 2024-05-10 22:42 [Bug tree-optimization/115040] New: Missed optimization opportunity in std::find sjames at gcc dot gnu.org ` (2 preceding siblings ...) 2024-05-10 23:04 ` sjames at gcc dot gnu.org @ 2024-05-10 23:10 ` pinskia at gcc dot gnu.org 2024-05-13 13:11 ` redi at gcc dot gnu.org 4 siblings, 0 replies; 6+ messages in thread From: pinskia at gcc dot gnu.org @ 2024-05-10 23:10 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115040 --- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> --- (In reply to Sam James from comment #3) > (In reply to Andrew Pinski from comment #2) > > > clang lowers both the calls to (w)memchr > > > > Is that with libc++ or libstdc++? > > It's libc++. Checked locally too.. Then this is partly a dup of bug 88545 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug libstdc++/115040] Missed optimization opportunity in std::find of std::vector elements 2024-05-10 22:42 [Bug tree-optimization/115040] New: Missed optimization opportunity in std::find sjames at gcc dot gnu.org ` (3 preceding siblings ...) 2024-05-10 23:10 ` [Bug libstdc++/115040] " pinskia at gcc dot gnu.org @ 2024-05-13 13:11 ` redi at gcc dot gnu.org 4 siblings, 0 replies; 6+ messages in thread From: redi at gcc dot gnu.org @ 2024-05-13 13:11 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115040 --- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to Andrew Pinski from comment #4) > Then this is partly a dup of bug 88545 Yes, that would manually transform the find_epi8 case into a memchr call, but Clang doesn't need a manual transform in the library, it does it in the compiler. Tamar's plan to remove the manual loop unrolling in our std::find_if might help here, but I'm not sure. ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-05-13 13:11 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2024-05-10 22:42 [Bug tree-optimization/115040] New: Missed optimization opportunity in std::find sjames at gcc dot gnu.org 2024-05-10 22:52 ` [Bug tree-optimization/115040] Missed optimization opportunity in std::find of std::vector elements pinskia at gcc dot gnu.org 2024-05-10 22:56 ` pinskia at gcc dot gnu.org 2024-05-10 23:04 ` sjames at gcc dot gnu.org 2024-05-10 23:10 ` [Bug libstdc++/115040] " pinskia at gcc dot gnu.org 2024-05-13 13:11 ` redi at gcc dot gnu.org
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).