[clang-tidy][modernize-use-starts-ends-with] Fix operator rewriting false negative...
[llvm-project.git] / clang / test / Misc / loop-opt-setup.c
blob01643e6073b56a3370314049a1bccb5397e3f1d0
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
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;
13 // Check br i1 to make sure that the loop is fully unrolled
14 // CHECK-LABEL: foo
15 // CHECK-NOT: br i1
17 void Helper(void) {
18 const int *nodes[5];
19 int num_active = 5;
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;
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