https://godbolt.org/z/o7q1cjez1
void f() {
int arr[5] = {1, 2, 3, 4, 5};
for (int k = 0; k < 5; k++) {
arr[k] *= 2;
}
}
I haven't looked closely, but I suspect -O3 can simplify this loop as it unrolls and later finds out that the stores are dead. -Oz doesn't do that. IIRC at some point there was a loop re-roller that got removed which could potentially catch these cases.