Left-over empty loop after optimization


Compiling the following program with clang3.3 and -O3 --std=c++11 correctly
determines that the whole if(), the bool, and the inner for() is without
any effect, but still leaves the (now empty) outer for() in place.

int main(int argc, char *argv) {
  for (int j = 0; j < 0x7fffffff; j++) {
    for (int i = 0; i <= 2; i++) {
      bool arr { false, false, false };
      if (arr[i]) {
        arr[i] = true;
  return 0;

    .file "prog.cpp"
    .globl main
    .align 16, 0x90
    .type main,@function
main: # @main
# BB#0:
    movl $2147483647, %eax # imm = 0x7FFFFFFF
    .align 16, 0x90
.LBB0_1: # =>This Inner Loop Header: Depth=1
    decl %eax
    jne .LBB0_1
# BB#2:
    xorl %eax, %eax
    .size main, .Ltmp0-main

    .section ".note.GNU-stack","",@progbits

Why is Clang not removing the empty loop? e.g. GCC 4.8.2 does so, even in a
lot more complicated situations.