Hard
Auto-vectorizing a loop with a data-dependent if/else
f and g are both fully vectorizable pure functions with side effects only through their return value. data[i] > threshold is essentially random per element (no exploitable pattern). What's the realistic outcome when the compiler tries to auto-vectorize this loop?
main.cpp
for (int i = 0; i < n; ++i) {
if (data[i] > threshold) {
sum += f(data[i]);
} else {
sum += g(data[i]);
}
}14 of 47 in Computer Architecture