[llvm-bugs] [Bug 43550] New: missed DCE optimization after loop unrolling

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Oct 3 16:19:58 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=43550

            Bug ID: 43550
           Summary: missed DCE optimization after loop unrolling
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Keywords: code-quality
          Severity: normal
          Priority: P
         Component: Common Code Generator Code
          Assignee: unassignedbugs at nondot.org
          Reporter: trass3r at gmail.com
                CC: llvm-bugs at lists.llvm.org

#include <cstdint>
#include <utility>

const int N = 4;
void bitreverse(int* data)
{
    uint32_t j = 0;
    for (uint32_t i = 0; i < N; ++i)
    {
        if (j > i)
            std::swap(data[i], data[j]);

        uint32_t k = N/2;
        while (k <= j)
        {
            j -= k;
            k /= 2;
        }
        j += k;
    }
}

Even with -O3 after everything is unrolled the while loop unnecessarily
remains: https://godbolt.org/z/cA-S8J
Of course it's even more severe with N=8: https://godbolt.org/z/niZPeS

Interestingly if you change the swap line slightly it suddenly starts using
pshufd which seems quite clever: https://godbolt.org/z/5YJnJ1

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20191003/1b7b898f/attachment.html>


More information about the llvm-bugs mailing list