[llvm-bugs] [Bug 40581] New: Loop flattening not performed?

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Feb 4 02:43:35 PST 2019


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

            Bug ID: 40581
           Summary: Loop flattening not performed?
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: lebedev.ri at gmail.com
                CC: llvm-bugs at lists.llvm.org

https://godbolt.org/z/B3VM2A

void v0(int n, int *A, int *B) {
        int k = 0;
        for(int i = 0; i < n; i++)
                for(int j = 0; j < n; j++) {
                        A[k] = B[k];
                        k++;
                }
}

is equivalent to

void v1(int n, int *A, int *B) {
        for(int i = 0; i < n; i++)
                for(int j = 0; j < n; j++) {
                        int k = i*n+j;
                        A[k] = B[k];
                        k++;
                }
}

(Also, which one of these ^ is better? clang does not optimize them into the
same IR)

Shouldn't that be transformed into

void v2(int n, int *A, int *B) {
        for(int k = 0; k < n * n; k++)
        A[k] = B[k];
}

?

-- 
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/20190204/def224c7/attachment.html>


More information about the llvm-bugs mailing list