38 lines · c
1// This tests loop unrolling and loop deletion (enabled under -O1)2// RUN: %clang_cc1 -std=c11 -O1 -fno-unroll-loops -o - %s -emit-llvm | FileCheck %s3// RUN: %clang_cc1 -std=c99 -O1 -fno-unroll-loops -o - %s -emit-llvm | FileCheck %s --check-prefix C994 5extern int a[16];6int b = 0;7int foo(void) {8#pragma unroll9 for (int i = 0; i < 16; ++i)10 a[i] = b += 2;11 return b;12}13// Check br i1 to make sure that the loop is fully unrolled14// CHECK-LABEL: foo15// CHECK-NOT: br i116 17void Helper(void) {18 const int *nodes[5] = {0};19 int num_active = 5;20 21 while (num_active)22#pragma clang loop unroll(full)23 for (int i = 0; i < 5; ++i)24 if (nodes[i])25 --num_active;26}27 28// Check br i1 to make sure the loop is gone, there will still be a label branch for the infinite loop.29// In C99, there was no forward progress requirement, so we expect the infinite loop to still exist,30// but for C11 and onwards, the infinite loop can be deleted.31// CHECK-LABEL: Helper32// C99: br label33// C99-NOT: br i134// C99: br label35// CHECK: entry:36// CHECK-NOT: br i137// CHECK-NEXT: ret void38