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

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
#include <vector>

void pop_many(std::vector<int>& v, unsigned n) {
    for (unsigned i = 0; i < n; ++i) {
        v.pop_back();
    }
}

With GCC 10 at -O2 and above this was optimized to simply subtract n from the
v.end() pointer:

_Z8pop_manyRSt6vectorIiSaIiEEm:
.LFB883:
        testq   %rsi, %rsi
        je      .L1
        salq    $2, %rsi
        subq    %rsi, 8(%rdi)
.L1:
        ret


But since r11-2238 it decrements the pointer n times:

_Z8pop_manyRSt6vectorIiSaIiEEm:
.LFB883:
        testq   %rsi, %rsi
        je      .L1
        movq    8(%rdi), %rdx
        xorl    %eax, %eax
        .p2align 4,,10
        .p2align 3
.L4:
        subq    $4, %rdx
        addq    $1, %rax
        movq    %rdx, 8(%rdi)
        cmpq    %rax, %rsi
        jne     .L4
.L1:
        ret


This regression is still present after the fixes for PR96721 and PR96722.
Should it be marked as [11/12 Regression] ?

Reply via email to