Break circular dependency between FIR dialect and utilities
[llvm-project.git] / flang / test / Lower / OpenMP / wsloop-collapse.f90
bloba122a41ba8b8fd2f2f241229b63d61518b8156d0
1 ! This test checks lowering of OpenMP DO Directive(Worksharing) with collapse.
3 ! RUN: bbc -fopenmp -emit-fir %s -o - | FileCheck %s
5 program wsloop_collapse
6 integer :: i, j, k
7 integer :: a, b, c
8 integer :: x
9 ! CHECK: %[[VAL_0:.*]] = fir.alloca i32 {bindc_name = "a", uniq_name = "_QFEa"}
10 ! CHECK: %[[VAL_1:.*]] = fir.alloca i32 {bindc_name = "b", uniq_name = "_QFEb"}
11 ! CHECK: %[[VAL_2:.*]] = fir.alloca i32 {bindc_name = "c", uniq_name = "_QFEc"}
12 ! CHECK: %[[VAL_3:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFEi"}
13 ! CHECK: %[[VAL_4:.*]] = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFEj"}
14 ! CHECK: %[[VAL_5:.*]] = fir.alloca i32 {bindc_name = "k", uniq_name = "_QFEk"}
15 ! CHECK: %[[VAL_6:.*]] = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFEx"}
16 a=3
17 ! CHECK: %[[VAL_7:.*]] = arith.constant 3 : i32
18 ! CHECK: fir.store %[[VAL_7]] to %[[VAL_0]] : !fir.ref<i32>
19 b=2
20 ! CHECK: %[[VAL_8:.*]] = arith.constant 2 : i32
21 ! CHECK: fir.store %[[VAL_8]] to %[[VAL_1]] : !fir.ref<i32>
22 c=5
23 ! CHECK: %[[VAL_9:.*]] = arith.constant 5 : i32
24 ! CHECK: fir.store %[[VAL_9]] to %[[VAL_2]] : !fir.ref<i32>
25 x=0
26 ! CHECK: %[[VAL_10:.*]] = arith.constant 0 : i32
27 ! CHECK: fir.store %[[VAL_10]] to %[[VAL_6]] : !fir.ref<i32>
29 !$omp do collapse(3)
30 ! CHECK: %[[VAL_20:.*]] = arith.constant 1 : i32
31 ! CHECK: %[[VAL_21:.*]] = fir.load %[[VAL_0]] : !fir.ref<i32>
32 ! CHECK: %[[VAL_22:.*]] = arith.constant 1 : i32
33 ! CHECK: %[[VAL_23:.*]] = arith.constant 1 : i32
34 ! CHECK: %[[VAL_24:.*]] = fir.load %[[VAL_1]] : !fir.ref<i32>
35 ! CHECK: %[[VAL_25:.*]] = arith.constant 1 : i32
36 ! CHECK: %[[VAL_26:.*]] = arith.constant 1 : i32
37 ! CHECK: %[[VAL_27:.*]] = fir.load %[[VAL_2]] : !fir.ref<i32>
38 ! CHECK: %[[VAL_28:.*]] = arith.constant 1 : i32
39 do i = 1, a
40 do j= 1, b
41 do k = 1, c
42 ! CHECK: omp.wsloop for (%[[ARG0:.*]], %[[ARG1:.*]], %[[ARG2:.*]]) : i32 = (%[[VAL_20]], %[[VAL_23]], %[[VAL_26]]) to (%[[VAL_21]], %[[VAL_24]], %[[VAL_27]]) inclusive step (%[[VAL_22]], %[[VAL_25]], %[[VAL_28]]) {
43 ! CHECK: fir.store %[[ARG0]] to %[[STORE_IV0:.*]] : !fir.ref<i32>
44 ! CHECK: fir.store %[[ARG1]] to %[[STORE_IV1:.*]] : !fir.ref<i32>
45 ! CHECK: fir.store %[[ARG2]] to %[[STORE_IV2:.*]] : !fir.ref<i32>
46 ! CHECK: %[[VAL_12:.*]] = fir.load %[[VAL_6]] : !fir.ref<i32>
47 ! CHECK: %[[LOAD_IV0:.*]] = fir.load %[[STORE_IV0]] : !fir.ref<i32>
48 ! CHECK: %[[VAL_13:.*]] = arith.addi %[[VAL_12]], %[[LOAD_IV0]] : i32
49 ! CHECK: %[[LOAD_IV1:.*]] = fir.load %[[STORE_IV1]] : !fir.ref<i32>
50 ! CHECK: %[[VAL_14:.*]] = arith.addi %[[VAL_13]], %[[LOAD_IV1]] : i32
51 ! CHECK: %[[LOAD_IV2:.*]] = fir.load %[[STORE_IV2]] : !fir.ref<i32>
52 ! CHECK: %[[VAL_15:.*]] = arith.addi %[[VAL_14]], %[[LOAD_IV2]] : i32
53 ! CHECK: fir.store %[[VAL_15]] to %[[VAL_6]] : !fir.ref<i32>
54 ! CHECK: omp.yield
55 ! CHECK: }
56 x = x + i + j + k
57 end do
58 end do
59 end do
60 !$omp end do
61 ! CHECK: return
62 ! CHECK: }
63 end program wsloop_collapse