1 // RUN: mlir-translate -mlir-to-llvmir %s | FileCheck %s
3 omp.declare_reduction @add_reduction_f32 : f32 init {
5 %0 = llvm.mlir.constant(0.000000e+00 : f32) : f32
8 ^bb0(%arg0: f32, %arg1: f32):
9 %0 = llvm.fadd %arg0, %arg1 {fastmathFlags = #llvm.fastmath<contract>} : f32
12 llvm.func @sections_(%arg0: !llvm.ptr {fir.bindc_name = "x"}) attributes {fir.internal_name = "_QPsections"} {
13 %0 = llvm.mlir.constant(2.000000e+00 : f32) : f32
14 %1 = llvm.mlir.constant(1.000000e+00 : f32) : f32
16 omp.sections reduction(@add_reduction_f32 %arg0 -> %arg1 : !llvm.ptr) {
18 ^bb0(%arg2: !llvm.ptr):
19 %2 = llvm.load %arg2 : !llvm.ptr -> f32
20 %3 = llvm.fadd %2, %1 {fastmathFlags = #llvm.fastmath<contract>} : f32
21 llvm.store %3, %arg2 : f32, !llvm.ptr
25 ^bb0(%arg2: !llvm.ptr):
26 %2 = llvm.load %arg2 : !llvm.ptr -> f32
27 %3 = llvm.fadd %2, %0 {fastmathFlags = #llvm.fastmath<contract>} : f32
28 llvm.store %3, %arg2 : f32, !llvm.ptr
38 // CHECK-LABEL: define internal void @sections_..omp_par
39 // CHECK: omp.par.entry:
40 // CHECK: %[[VAL_9:.*]] = getelementptr { ptr }, ptr %[[VAL_10:.*]], i32 0, i32 0
41 // CHECK: %[[VAL_11:.*]] = load ptr, ptr %[[VAL_9]], align 8
42 // CHECK: %[[VAL_12:.*]] = alloca i32, align 4
43 // CHECK: %[[VAL_13:.*]] = alloca i32, align 4
44 // CHECK: %[[VAL_14:.*]] = alloca i32, align 4
45 // CHECK: %[[VAL_15:.*]] = alloca i32, align 4
46 // CHECK: %[[VAL_16:.*]] = alloca i32, align 4
47 // CHECK: %[[VAL_17:.*]] = load i32, ptr %[[VAL_18:.*]], align 4
48 // CHECK: store i32 %[[VAL_17]], ptr %[[VAL_16]], align 4
49 // CHECK: %[[VAL_19:.*]] = load i32, ptr %[[VAL_16]], align 4
50 // CHECK: %[[VAL_20:.*]] = alloca float, align 4
51 // CHECK: %[[VAL_21:.*]] = alloca [1 x ptr], align 8
52 // CHECK: br label %[[VAL_22:.*]]
53 // CHECK: omp.reduction.init: ; preds = %[[VAL_23:.*]]
54 // CHECK: store float 0.000000e+00, ptr %[[VAL_20]], align 4
55 // CHECK: br label %[[VAL_24:.*]]
56 // CHECK: omp.par.region: ; preds = %[[VAL_22]]
57 // CHECK: br label %[[VAL_25:.*]]
58 // CHECK: omp.par.region1: ; preds = %[[VAL_24]]
59 // CHECK: br label %[[VAL_26:.*]]
60 // CHECK: omp_section_loop.preheader: ; preds = %[[VAL_25]]
61 // CHECK: store i32 0, ptr %[[VAL_13]], align 4
62 // CHECK: store i32 1, ptr %[[VAL_14]], align 4
63 // CHECK: store i32 1, ptr %[[VAL_15]], align 4
64 // CHECK: %[[VAL_27:.*]] = call i32 @__kmpc_global_thread_num(ptr @1)
65 // CHECK: call void @__kmpc_for_static_init_4u(ptr @1, i32 %[[VAL_27]], i32 34, ptr %[[VAL_12]], ptr %[[VAL_13]], ptr %[[VAL_14]], ptr %[[VAL_15]], i32 1, i32 0)
66 // CHECK: %[[VAL_28:.*]] = load i32, ptr %[[VAL_13]], align 4
67 // CHECK: %[[VAL_29:.*]] = load i32, ptr %[[VAL_14]], align 4
68 // CHECK: %[[VAL_30:.*]] = sub i32 %[[VAL_29]], %[[VAL_28]]
69 // CHECK: %[[VAL_31:.*]] = add i32 %[[VAL_30]], 1
70 // CHECK: br label %[[VAL_32:.*]]
71 // CHECK: omp_section_loop.header: ; preds = %[[VAL_33:.*]], %[[VAL_26]]
72 // CHECK: %[[VAL_34:.*]] = phi i32 [ 0, %[[VAL_26]] ], [ %[[VAL_35:.*]], %[[VAL_33]] ]
73 // CHECK: br label %[[VAL_36:.*]]
74 // CHECK: omp_section_loop.cond: ; preds = %[[VAL_32]]
75 // CHECK: %[[VAL_37:.*]] = icmp ult i32 %[[VAL_34]], %[[VAL_31]]
76 // CHECK: br i1 %[[VAL_37]], label %[[VAL_38:.*]], label %[[VAL_39:.*]]
77 // CHECK: omp_section_loop.exit: ; preds = %[[VAL_36]]
78 // CHECK: call void @__kmpc_for_static_fini(ptr @1, i32 %[[VAL_27]])
79 // CHECK: %[[VAL_40:.*]] = call i32 @__kmpc_global_thread_num(ptr @1)
80 // CHECK: call void @__kmpc_barrier(ptr @2, i32 %[[VAL_40]])
81 // CHECK: br label %[[VAL_41:.*]]
82 // CHECK: omp_section_loop.after: ; preds = %[[VAL_39]]
83 // CHECK: br label %[[VAL_42:.*]]
84 // CHECK: omp_section_loop.aftersections.fini: ; preds = %[[VAL_41]]
85 // CHECK: %[[VAL_43:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_21]], i64 0, i64 0
86 // CHECK: store ptr %[[VAL_20]], ptr %[[VAL_43]], align 8
87 // CHECK: %[[VAL_44:.*]] = call i32 @__kmpc_global_thread_num(ptr @1)
88 // CHECK: %[[VAL_45:.*]] = call i32 @__kmpc_reduce(ptr @1, i32 %[[VAL_44]], i32 1, i64 8, ptr %[[VAL_21]], ptr @.omp.reduction.func, ptr @.gomp_critical_user_.reduction.var)
89 // CHECK: switch i32 %[[VAL_45]], label %[[VAL_46:.*]] [
90 // CHECK: i32 1, label %[[VAL_47:.*]]
91 // CHECK: i32 2, label %[[VAL_48:.*]]
93 // CHECK: reduce.switch.atomic: ; preds = %[[VAL_42]]
95 // CHECK: reduce.switch.nonatomic: ; preds = %[[VAL_42]]
96 // CHECK: %[[VAL_49:.*]] = load float, ptr %[[VAL_11]], align 4
97 // CHECK: %[[VAL_50:.*]] = load float, ptr %[[VAL_20]], align 4
98 // CHECK: %[[VAL_51:.*]] = fadd contract float %[[VAL_49]], %[[VAL_50]]
99 // CHECK: store float %[[VAL_51]], ptr %[[VAL_11]], align 4
100 // CHECK: call void @__kmpc_end_reduce(ptr @1, i32 %[[VAL_44]], ptr @.gomp_critical_user_.reduction.var)
101 // CHECK: br label %[[VAL_46]]
102 // CHECK: reduce.finalize: ; preds = %[[VAL_47]], %[[VAL_42]]
103 // CHECK: %[[VAL_52:.*]] = call i32 @__kmpc_global_thread_num(ptr @1)
104 // CHECK: call void @__kmpc_barrier(ptr @2, i32 %[[VAL_52]])
105 // CHECK: br label %[[VAL_53:.*]]
106 // CHECK: omp.region.cont: ; preds = %[[VAL_46]]
107 // CHECK: br label %[[VAL_54:.*]]
108 // CHECK: omp.par.pre_finalize: ; preds = %[[VAL_53]]
109 // CHECK: br label %[[VAL_55:.*]]
110 // CHECK: omp_section_loop.body: ; preds = %[[VAL_36]]
111 // CHECK: %[[VAL_56:.*]] = add i32 %[[VAL_34]], %[[VAL_28]]
112 // CHECK: %[[VAL_57:.*]] = mul i32 %[[VAL_56]], 1
113 // CHECK: %[[VAL_58:.*]] = add i32 %[[VAL_57]], 0
114 // CHECK: switch i32 %[[VAL_58]], label %[[VAL_59:.*]] [
115 // CHECK: i32 0, label %[[VAL_60:.*]]
116 // CHECK: i32 1, label %[[VAL_61:.*]]
118 // CHECK: omp_section_loop.body.case3: ; preds = %[[VAL_38]]
119 // CHECK: br label %[[VAL_62:.*]]
120 // CHECK: omp.section.region5: ; preds = %[[VAL_61]]
121 // CHECK: %[[VAL_63:.*]] = load float, ptr %[[VAL_20]], align 4
122 // CHECK: %[[VAL_64:.*]] = fadd contract float %[[VAL_63]], 2.000000e+00
123 // CHECK: store float %[[VAL_64]], ptr %[[VAL_20]], align 4
124 // CHECK: br label %[[VAL_65:.*]]
125 // CHECK: omp.region.cont4: ; preds = %[[VAL_62]]
126 // CHECK: br label %[[VAL_59]]
127 // CHECK: omp_section_loop.body.case: ; preds = %[[VAL_38]]
128 // CHECK: br label %[[VAL_66:.*]]
129 // CHECK: omp.section.region: ; preds = %[[VAL_60]]
130 // CHECK: %[[VAL_67:.*]] = load float, ptr %[[VAL_20]], align 4
131 // CHECK: %[[VAL_68:.*]] = fadd contract float %[[VAL_67]], 1.000000e+00
132 // CHECK: store float %[[VAL_68]], ptr %[[VAL_20]], align 4
133 // CHECK: br label %[[VAL_69:.*]]
134 // CHECK: omp.region.cont2: ; preds = %[[VAL_66]]
135 // CHECK: br label %[[VAL_59]]
136 // CHECK: omp_section_loop.body.sections.after: ; preds = %[[VAL_65]], %[[VAL_69]], %[[VAL_38]]
137 // CHECK: br label %[[VAL_33]]
138 // CHECK: omp_section_loop.inc: ; preds = %[[VAL_59]]
139 // CHECK: %[[VAL_35]] = add nuw i32 %[[VAL_34]], 1
140 // CHECK: br label %[[VAL_32]]
141 // CHECK: omp.par.outlined.exit.exitStub: ; preds = %[[VAL_54]]
143 // CHECK: %[[VAL_70:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_71:.*]], i64 0, i64 0
144 // CHECK: %[[VAL_72:.*]] = load ptr, ptr %[[VAL_70]], align 8
145 // CHECK: %[[VAL_73:.*]] = load float, ptr %[[VAL_72]], align 4
146 // CHECK: %[[VAL_74:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_75:.*]], i64 0, i64 0
147 // CHECK: %[[VAL_76:.*]] = load ptr, ptr %[[VAL_74]], align 8
148 // CHECK: %[[VAL_77:.*]] = load float, ptr %[[VAL_76]], align 4
149 // CHECK: %[[VAL_78:.*]] = fadd contract float %[[VAL_73]], %[[VAL_77]]
150 // CHECK: store float %[[VAL_78]], ptr %[[VAL_72]], align 4