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