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
12 // placeholder for loop body code.
13 extern "C" void body(...) {}
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:.+]]
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:.+]]
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:.+]]
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]+]]
50 // IR-NEXT: [[FOR_END]]:
53 extern "C" void func(int start
, int end
, int step
) {
55 for (int i
= start
; i
< end
; i
+=step
)
56 body(start
, end
, step
, i
);
62 // IR: ![[LOOP2]] = distinct !{![[LOOP2]], ![[LOOPPROP3:[0-9]+]], ![[LOOPPROP4:[0-9]+]]}
63 // IR: ![[LOOPPROP3]] = !{!"llvm.loop.mustprogress"}
64 // IR: ![[LOOPPROP4]] = !{!"llvm.loop.unroll.enable"}