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: unassignedb...@nondot.org
          Reporter: tras...@gmail.com
                CC: llvm-bugs@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to