91 lines · plain
1// RUN: mlir-translate -mlir-to-llvmir %s | FileCheck %s2 3// Verifies that the IR builder can handle reductions with multi-block combiner4// regions on the GPU.5 6module attributes {dlti.dl_spec = #dlti.dl_spec<"dlti.alloca_memory_space" = 5 : ui64, "dlti.global_memory_space" = 1 : ui64>, llvm.target_triple = "amdgcn-amd-amdhsa", omp.is_gpu = true, omp.is_target_device = true} {7 llvm.func @bar() {}8 llvm.func @baz() {}9 10 omp.declare_reduction @add_reduction_byref_box_5xf32 : !llvm.ptr attributes {byref_element_type = !llvm.array<5 x f32>} alloc {11 %0 = llvm.mlir.constant(1 : i64) : i6412 %1 = llvm.alloca %0 x !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8, array<1 x array<3 x i64>>)> : (i64) -> !llvm.ptr<5>13 %2 = llvm.addrspacecast %1 : !llvm.ptr<5> to !llvm.ptr14 omp.yield(%2 : !llvm.ptr)15 } init {16 ^bb0(%arg0: !llvm.ptr, %arg1: !llvm.ptr):17 omp.yield(%arg1 : !llvm.ptr)18 } combiner {19 ^bb0(%arg0: !llvm.ptr, %arg1: !llvm.ptr):20 llvm.call @bar() : () -> ()21 llvm.br ^bb322 23 ^bb3: // pred: ^bb124 llvm.call @baz() : () -> ()25 omp.yield(%arg0 : !llvm.ptr)26 } data_ptr_ptr {27 ^bb0(%arg0: !llvm.ptr):28 %0 = llvm.getelementptr %arg0[0, 0] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8)>29 omp.yield(%0 : !llvm.ptr)30 }31 32 llvm.func @foo_() {33 %c1 = llvm.mlir.constant(1 : i64) : i6434 %10 = llvm.alloca %c1 x !llvm.array<5 x f32> {bindc_name = "x"} : (i64) -> !llvm.ptr<5>35 %11 = llvm.addrspacecast %10 : !llvm.ptr<5> to !llvm.ptr36 %74 = omp.map.info var_ptr(%11 : !llvm.ptr, !llvm.array<5 x f32>) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = "x"}37 omp.target map_entries(%74 -> %arg0 : !llvm.ptr) {38 %c1_2 = llvm.mlir.constant(1 : i32) : i3239 %c10 = llvm.mlir.constant(10 : i32) : i3240 omp.teams reduction(byref @add_reduction_byref_box_5xf32 %arg0 -> %arg2 : !llvm.ptr) {41 omp.parallel {42 omp.distribute {43 omp.wsloop {44 omp.loop_nest (%arg5) : i32 = (%c1_2) to (%c10) inclusive step (%c1_2) {45 omp.yield46 }47 } {omp.composite}48 } {omp.composite}49 omp.terminator50 } {omp.composite}51 omp.terminator52 }53 omp.terminator54 }55 llvm.return56 }57}58 59// CHECK: call void @__kmpc_parallel_51({{.*}}, i32 1, i32 -1, i32 -1,60// CHECK-SAME: ptr @[[PAR_OUTLINED:.*]], ptr null, ptr %2, i64 1)61 62// CHECK: define internal void @[[PAR_OUTLINED]]{{.*}} {63// CHECK: .omp.reduction.then:64// CHECK: br label %omp.reduction.nonatomic.body65 66// CHECK: omp.reduction.nonatomic.body:67// CHECK: call void @bar()68// CHECK: br label %[[BODY_2ND_BB:.*]]69 70// CHECK: [[BODY_2ND_BB]]:71// CHECK: call void @baz()72// CHECK: br label %[[CONT_BB:.*]]73 74// CHECK: [[CONT_BB]]:75// CHECK-NEXT: %[[RED_RHS:.*]] = phi ptr [ %{{.*}}, %{{.*}} ]76// CHECK: }77 78// CHECK: define internal void @"{{.*}}$reduction$reduction_func"(ptr noundef %0, ptr noundef %1) #0 {79// CHECK: br label %omp.reduction.nonatomic.body80 81// CHECK: [[BODY_2ND_BB:.*]]:82// CHECK: call void @baz()83// CHECK: br label %omp.region.cont84 85 86// CHECK: omp.reduction.nonatomic.body:87// CHECK: call void @bar()88// CHECK: br label %[[BODY_2ND_BB]]89 90// CHECK: }91