1f88a7975SAtmn Patel // This tests loop unrolling and loop deletion (enabled under -O1) 2*0d501f38SFangrui Song // RUN: %clang_cc1 -std=c11 -O1 -fno-unroll-loops -o - %s -emit-llvm | FileCheck %s 3*0d501f38SFangrui Song // RUN: %clang_cc1 -std=c99 -O1 -fno-unroll-loops -o - %s -emit-llvm | FileCheck %s --check-prefix C99 403bd5198SRoman Lebedev 5c3649a08SEric Christopher extern int a[16]; 6c3649a08SEric Christopher int b = 0; foo(void)7c3649a08SEric Christopherint foo(void) { 8c3649a08SEric Christopher #pragma unroll 9c3649a08SEric Christopher for (int i = 0; i < 16; ++i) 10c3649a08SEric Christopher a[i] = b += 2; 11c3649a08SEric Christopher return b; 12c3649a08SEric Christopher } 13c554c5e1SEric Christopher // Check br i1 to make sure that the loop is fully unrolled 1403bd5198SRoman Lebedev // CHECK-LABEL: foo 1503bd5198SRoman Lebedev // CHECK-NOT: br i1 16c3649a08SEric Christopher Helper(void)177de71613SAaron Ballmanvoid Helper(void) { 18c554c5e1SEric Christopher const int *nodes[5]; 19c554c5e1SEric Christopher int num_active = 5; 20c554c5e1SEric Christopher 21c554c5e1SEric Christopher while (num_active) 22c554c5e1SEric Christopher #pragma clang loop unroll(full) 23c554c5e1SEric Christopher for (int i = 0; i < 5; ++i) 24c554c5e1SEric Christopher if (nodes[i]) 25c554c5e1SEric Christopher --num_active; 26c554c5e1SEric Christopher } 27c554c5e1SEric Christopher 28c554c5e1SEric Christopher // Check br i1 to make sure the loop is gone, there will still be a label branch for the infinite loop. 29f88a7975SAtmn Patel // In C99, there was no forward progress requirement, so we expect the infinite loop to still exist, 30f88a7975SAtmn Patel // but for C11 and onwards, the infinite loop can be deleted. 3103bd5198SRoman Lebedev // CHECK-LABEL: Helper 32f88a7975SAtmn Patel // C99: br label 33f88a7975SAtmn Patel // C99-NOT: br i1 34f88a7975SAtmn Patel // C99: br label 35f88a7975SAtmn Patel // CHECK: entry: 3603bd5198SRoman Lebedev // CHECK-NOT: br i1 37f88a7975SAtmn Patel // CHECK-NEXT: ret void 38