deadstores icon indicating copy to clipboard operation
deadstores copied to clipboard

Unnecessary updates

Open gaul opened this issue 5 years ago • 0 comments

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.

gaul avatar Feb 03 '20 00:02 gaul