With the following C code, the loop is completely eliminated, thanks to loop unrolling and constant propagation. The resulting LLVM code just calls printf with 20. #include <stdio.h> #include <stddef.h> int main() { int v = 0; size_t i; for(i=0; i<5; i++) { v += i*2; } printf("%d\n", v); } However, if 5 is replaced by 100, loop unrolling doesn't occur, and for some reason constant propagation doesn't work anymore. The resulting code just needs to call printf with 9900, there is no need for any loop.
Yep, known. *** This bug has been marked as a duplicate of 1179 ***
This has been implemented, see PR1179 for details, -Chris