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: [email protected]
          Reporter: [email protected]
                CC: [email protected]

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.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to