Skip to content

Unnecessary updates #1

Description

@gaul

Can this tool find unnecessary updates, e.g., batching updates to a counter? I encountered a situation with string_view recently that looks like:

void func();

void test(std::string_view *p, size_t n)
{
    for (size_t i = 0; i < n; ++i) {
        p->remove_prefix(1);
        func();
    }
}

The loop translates into:

.L3:
        addq    $1, 8(%rbx)
        addq    $1, %rbp
        subq    $1, (%rbx)
        call    _Z4funcv
        cmpq    %rbp, %r12
        jne     .L3

Calling string_view::operator[] in the loop body and remove_prefix after the loop improved performance in my application. I believe that since the increment both reads and writes deadstores will not consider this redundant today.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions