[PATCH] D22630: Loop rotation
Sanjoy Das via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 28 14:46:13 PDT 2016
Hi,
I know I'm late to the party, but I didn't understand this example:
On Thu, Jul 21, 2016 at 1:43 PM, Sebastian Pop <sebpop at gmail.com> wrote:
> int fun(const std::vector<char>* A, const std::vector<char>* B, int n, int m)
> {
> int res = 0;
>
> for (int i = 0; i < m; ++i)
> for (int j = 0; j < n; ++j)
> res += A->at(n * i + j) + B->at(n * i + j);
>
> return res;
> }
[snip]
> After loop rotate peels off one full iteration of the loop:
>
> for (int i = 0; i < m; ++i) {
> x = A->at(n * i);
> if (exception)
> throw;
> y = B->at(n*i);
> if(exception)
> throw;
> res += x + y;
> for (int j = 0; j < n; ++j)
> res += A->at(n * i + j) + B->at(n * i + j);
> }
After rotating the inner loop, won't the program have to be
for (int i = 0; i < m; ++i) {
x = A->at(n * i);
if (exception)
throw;
y = B->at(n*i);
if(exception)
throw;
res += x + y;
for (int j = 1; j < n; ++j) // << changed lower count
res += A->at(n * i + j) + B->at(n * i + j);
}
Where is the redundancy here ^?
-- Sanjoy
More information about the llvm-commits
mailing list