| 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 %s |
| 3 |
// RUN: %clang_cc1 -std=c99 -O1 -fno-unroll-loops -o - %s -emit-llvm | FileCheck %s --check-prefix C99 |
| 4 |
|
| 5 |
extern int a[16]; |
| 6 |
int b = 0; |
| 7 |
int foo(void) { |
| 8 |
#pragma unroll |
| 9 |
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 unrolled |
| 14 |
// CHECK-LABEL: foo |
| 15 |
// CHECK-NOT: br i1 |
| 16 |
|
| 17 |
void 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: Helper |
| 32 |
// C99: br label |
| 33 |
// C99-NOT: br i1 |
| 34 |
// C99: br label |
| 35 |
// CHECK: entry: |
| 36 |
// CHECK-NOT: br i1 |
| 37 |
// CHECK-NEXT: ret void |