[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / OpenMP / unroll_codegen_heuristic.cpp
blobe57010aabcefc27febaa50543023e7963661256d
1 // Check code generation
2 // RUN: %clang_cc1 -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s --check-prefix=IR
4 // Check same results after serialization round-trip
5 // RUN: %clang_cc1 -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-pch -o %t %s
6 // RUN: %clang_cc1 -verify -triple x86_64-pc-linux-gnu -fopenmp -include-pch %t -emit-llvm %s -o - | FileCheck %s --check-prefix=IR
7 // expected-no-diagnostics
9 #ifndef HEADER
10 #define HEADER
12 // placeholder for loop body code.
13 extern "C" void body(...) {}
16 // IR-LABEL: @func(
17 // IR-NEXT: [[ENTRY:.*]]:
18 // IR-NEXT: %[[START_ADDR:.+]] = alloca i32, align 4
19 // IR-NEXT: %[[END_ADDR:.+]] = alloca i32, align 4
20 // IR-NEXT: %[[STEP_ADDR:.+]] = alloca i32, align 4
21 // IR-NEXT: %[[I:.+]] = alloca i32, align 4
22 // IR-NEXT: store i32 %[[START:.+]], ptr %[[START_ADDR]], align 4
23 // IR-NEXT: store i32 %[[END:.+]], ptr %[[END_ADDR]], align 4
24 // IR-NEXT: store i32 %[[STEP:.+]], ptr %[[STEP_ADDR]], align 4
25 // IR-NEXT: %[[TMP0:.+]] = load i32, ptr %[[START_ADDR]], align 4
26 // IR-NEXT: store i32 %[[TMP0]], ptr %[[I]], align 4
27 // IR-NEXT: br label %[[FOR_COND:.+]]
28 // IR-EMPTY:
29 // IR-NEXT: [[FOR_COND]]:
30 // IR-NEXT: %[[TMP1:.+]] = load i32, ptr %[[I]], align 4
31 // IR-NEXT: %[[TMP2:.+]] = load i32, ptr %[[END_ADDR]], align 4
32 // IR-NEXT: %[[CMP:.+]] = icmp slt i32 %[[TMP1]], %[[TMP2]]
33 // IR-NEXT: br i1 %[[CMP]], label %[[FOR_BODY:.+]], label %[[FOR_END:.+]]
34 // IR-EMPTY:
35 // IR-NEXT: [[FOR_BODY]]:
36 // IR-NEXT: %[[TMP3:.+]] = load i32, ptr %[[START_ADDR]], align 4
37 // IR-NEXT: %[[TMP4:.+]] = load i32, ptr %[[END_ADDR]], align 4
38 // IR-NEXT: %[[TMP5:.+]] = load i32, ptr %[[STEP_ADDR]], align 4
39 // IR-NEXT: %[[TMP6:.+]] = load i32, ptr %[[I]], align 4
40 // IR-NEXT: call void (...) @body(i32 noundef %[[TMP3]], i32 noundef %[[TMP4]], i32 noundef %[[TMP5]], i32 noundef %[[TMP6]])
41 // IR-NEXT: br label %[[FOR_INC:.+]]
42 // IR-EMPTY:
43 // IR-NEXT: [[FOR_INC]]:
44 // IR-NEXT: %[[TMP7:.+]] = load i32, ptr %[[STEP_ADDR]], align 4
45 // IR-NEXT: %[[TMP8:.+]] = load i32, ptr %[[I]], align 4
46 // IR-NEXT: %[[ADD:.+]] = add nsw i32 %[[TMP8]], %[[TMP7]]
47 // IR-NEXT: store i32 %[[ADD]], ptr %[[I]], align 4
48 // IR-NEXT: br label %[[FOR_COND]], !llvm.loop ![[LOOP2:[0-9]+]]
49 // IR-EMPTY:
50 // IR-NEXT: [[FOR_END]]:
51 // IR-NEXT: ret void
52 // IR-NEXT: }
53 extern "C" void func(int start, int end, int step) {
54 #pragma omp unroll
55 for (int i = start; i < end; i+=step)
56 body(start, end, step, i);
59 #endif /* HEADER */
62 // IR: ![[LOOP2]] = distinct !{![[LOOP2]], ![[LOOPPROP3:[0-9]+]], ![[LOOPPROP4:[0-9]+]]}
63 // IR: ![[LOOPPROP3]] = !{!"llvm.loop.mustprogress"}
64 // IR: ![[LOOPPROP4]] = !{!"llvm.loop.unroll.enable"}