[llvm-dev] Difference between clang -Oz and opt -Oz
Fernando Magno Quintao Pereira via llvm-dev
llvm-dev at lists.llvm.org
Tue Dec 29 12:02:06 PST 2020
Dear LLVMers,
Why does opt -Oz and clang -Oz produce different codes? And could
someone point me to some documentation/discussion that explains the
differences between them?
Regards,
Fernando
------------------
Example
=======
This program below ends up with 74 instructions with opt -Oz, and 22
instructions with clang -Oz (LLVM 10.0). Opt unrolls the loop 2x,
whereas clang doesn't:
void prefix_sum(int *src, int *dst, int N) {
if (0 < N) {
int i = 0;
do {
int tmp = 0;
int j = 0;
if (j < i) {
do {
tmp += src[j];
j++;
} while (j < i);
dst[i] = tmp;
}
i++;
} while (i < N);
}
}
I can see some optimizations with clang, that might not run with opt when I do:
echo 'int;' | clang -xc -Oz - -o /dev/null -\#\#\#
Would that be the reason for the difference?
More information about the llvm-dev
mailing list