We have discussed scalar evolution in class. Consider the following C program:
int sum(int *a, int n)
{
int s = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 4; j++) {
s += a[4*i + j];
}
}
return s;
}
Convert this program to (slightly optimized) LLVM using the following command:
clang -O1 -S -emit-llvm -Xclang -disable-llvm-passes t.c -o - | opt -passes="mem2reg,loop-rotate" -S -o t.llThe
-emit-llvm flag instructs clang to emit LLVM IR; the mem2reg optimization pass converts local variables to pseudo-registers; the loop-rotate optimization pass implements the loop inversion (also called loop rotation) transformation) discussed in class.
Use the following command to print the information related to the Scalar Evolution (SCEV) analysis:
opt -passes='print<scalar-evolution>' -disable-output t.ll
Interpret the printed scalar evolution results, and briefly explain them in a short report. Submit the report.