public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/109849] New: suboptimal code for vector walking loop
@ 2023-05-13 22:26 hubicka at gcc dot gnu.org
  2023-05-13 22:32 ` [Bug middle-end/109849] " pinskia at gcc dot gnu.org
                   ` (36 more replies)
  0 siblings, 37 replies; 38+ messages in thread
From: hubicka at gcc dot gnu.org @ 2023-05-13 22:26 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109849

            Bug ID: 109849
           Summary: suboptimal code for vector walking loop
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hubicka at gcc dot gnu.org
  Target Milestone: ---

jan@localhost:/tmp> cat t.C
#include <vector>
typedef unsigned int uint32_t;
std::vector<std::pair<uint32_t, uint32_t>> stack;
void
test()
{
        while (!stack.empty()) {
                std::pair<uint32_t, uint32_t> cur = stack.back();
                stack.pop_back();
                if (cur.second)
                        break;
        }
}
jan@localhost:/tmp> gcc t.C -O3 -S 

yields to:

_Z4testv:
.LFB1264:
        .cfi_startproc
        movq    stack(%rip), %rcx
        movq    stack+8(%rip), %rax
        jmp     .L5
        .p2align 4,,10
        .p2align 3
.L6:
        movl    -4(%rax), %edx
        subq    $8, %rax
        movq    %rax, stack+8(%rip)
        testl   %edx, %edx
        jne     .L4
.L5:
        cmpq    %rax, %rcx
        jne     .L6
.L4:
        ret

We really should order the basic blocks putting cmpq before L6 saving a jump.
Moreover clang does

        .p2align        4, 0x90
.LBB1_1:                                # =>This Inner Loop Header: Depth=1
        cmpq    %rax, %rcx
        je      .LBB1_3
# %bb.2:                                #   in Loop: Header=BB1_1 Depth=1
        cmpl    $0, -4(%rcx)
        leaq    -8(%rcx), %rcx
        movq    %rcx, stack+8(%rip)
        je      .LBB1_1
.LBB1_3:
        retq

saving an instruction. Why we do not move stack+8 updating out of the loop?

^ permalink raw reply	[flat|nested] 38+ messages in thread

end of thread, other threads:[~2024-01-03 17:41 UTC | newest]

Thread overview: 38+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-13 22:26 [Bug middle-end/109849] New: suboptimal code for vector walking loop hubicka at gcc dot gnu.org
2023-05-13 22:32 ` [Bug middle-end/109849] " pinskia at gcc dot gnu.org
2023-05-13 22:40 ` pinskia at gcc dot gnu.org
2023-05-14  5:57 ` amonakov at gcc dot gnu.org
2023-05-14  9:58 ` hubicka at ucw dot cz
2023-05-14 10:01 ` hubicka at ucw dot cz
2023-05-15  6:56 ` rguenth at gcc dot gnu.org
2023-05-17 14:53 ` hubicka at gcc dot gnu.org
2023-05-17 20:36 ` rguenth at gcc dot gnu.org
2023-05-18  9:35 ` hubicka at gcc dot gnu.org
2023-05-18 11:54 ` rguenth at gcc dot gnu.org
2023-05-18 13:00 ` hubicka at gcc dot gnu.org
2023-05-23  9:57 ` cvs-commit at gcc dot gnu.org
2023-05-23 10:10 ` rguenth at gcc dot gnu.org
2023-05-24 11:19 ` cvs-commit at gcc dot gnu.org
2023-06-16 14:20 ` hubicka at gcc dot gnu.org
2023-06-18 16:59 ` cvs-commit at gcc dot gnu.org
2023-06-19 16:28 ` cvs-commit at gcc dot gnu.org
2023-06-26 16:30 ` cvs-commit at gcc dot gnu.org
2023-06-28  9:47 ` cvs-commit at gcc dot gnu.org
2023-06-29 20:46 ` cvs-commit at gcc dot gnu.org
2023-06-30 14:28 ` cvs-commit at gcc dot gnu.org
2023-11-19 15:25 ` hubicka at gcc dot gnu.org
2023-11-21 14:17 ` cvs-commit at gcc dot gnu.org
2023-11-21 15:12 ` hubicka at gcc dot gnu.org
2023-11-24 16:35 ` cvs-commit at gcc dot gnu.org
2023-11-24 17:00 ` cvs-commit at gcc dot gnu.org
2023-11-24 17:00 ` jamborm at gcc dot gnu.org
2023-11-27 14:39 ` rguenth at gcc dot gnu.org
2023-11-28  9:33 ` redi at gcc dot gnu.org
2023-11-28 10:32 ` jamborm at gcc dot gnu.org
2023-11-28 12:41 ` redi at gcc dot gnu.org
2023-11-28 13:29 ` redi at gcc dot gnu.org
2023-11-28 15:29 ` redi at gcc dot gnu.org
2023-11-28 22:21 ` redi at gcc dot gnu.org
2023-11-29 12:27 ` hubicka at ucw dot cz
2023-11-29 15:25 ` cvs-commit at gcc dot gnu.org
2024-01-03 17:41 ` jamborm 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).