https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87987
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- So I think LLVM's unrolling notices the load will become constant and the whole induction variable basically goes away for sum. Even for this C code LLVM does the optimization: static const int table[] = { 1,10,10, 1, 1,10, 1,10 , 1,10,10, 1, 1,10, 1,10 , 1,10,10, 1, 1,10, 1,10 , 1,10,10, 1, 1,10, 1,10 }; int check1() { int sum = 1; for (unsigned long i = 0; i < sizeof(table)/sizeof(table[0]);i++) sum += table[i]; return sum; }