brintos

brintos / llvm-project-archived public Read only

0
0
Text · 8.7 KiB · 8e2343d Raw
248 lines · plain
1// RUN: mlir-opt -convert-scf-to-openmp -split-input-file %s | FileCheck %s2 3// CHECK: omp.declare_reduction @[[$REDF:.*]] : f324 5// CHECK: init6// CHECK: %[[INIT:.*]] = llvm.mlir.constant(0.000000e+00 : f32)7// CHECK: omp.yield(%[[INIT]] : f32)8 9// CHECK: combiner10// CHECK: ^{{.*}}(%[[ARG0:.*]]: f32, %[[ARG1:.*]]: f32)11// CHECK: %[[RES:.*]] = arith.addf %[[ARG0]], %[[ARG1]]12// CHECK: omp.yield(%[[RES]] : f32)13 14// CHECK: atomic15// CHECK: ^{{.*}}(%[[ARG0:.*]]: !llvm.ptr, %[[ARG1:.*]]: !llvm.ptr):16// CHECK: %[[RHS:.*]] = llvm.load %[[ARG1]] : !llvm.ptr -> f3217// CHECK: llvm.atomicrmw fadd %[[ARG0]], %[[RHS]] monotonic18 19// CHECK-LABEL: @reduction120func.func @reduction1(%arg0 : index, %arg1 : index, %arg2 : index,21                 %arg3 : index, %arg4 : index) {22  // CHECK: %[[CST:.*]] = arith.constant 0.023  // CHECK: %[[ONE:.*]] = llvm.mlir.constant(124  // CHECK: %[[BUF:.*]] = llvm.alloca %[[ONE]] x f3225  // CHECK: llvm.store %[[CST]], %[[BUF]]26  %step = arith.constant 1 : index27  %zero = arith.constant 0.0 : f3228  // CHECK: omp.parallel29  // CHECK: omp.wsloop30  // CHECK-SAME: reduction(@[[$REDF]] %[[BUF]] -> %[[PVT_BUF:[a-z0-9]+]]31  // CHECK: omp.loop_nest32  // CHECK: memref.alloca_scope33  scf.parallel (%i0, %i1) = (%arg0, %arg1) to (%arg2, %arg3)34                            step (%arg4, %step) init (%zero) -> (f32) {35    // CHECK: %[[CST_INNER:.*]] = arith.constant 1.036    %one = arith.constant 1.0 : f3237    // CHECK: %[[PVT_VAL:.*]] = llvm.load %[[PVT_BUF]] : !llvm.ptr -> f3238    // CHECK: %[[ADD_RESULT:.*]] = arith.addf %[[PVT_VAL]], %[[CST_INNER]] : f3239    // CHECK: llvm.store %[[ADD_RESULT]], %[[PVT_BUF]] : f32, !llvm.ptr40    scf.reduce(%one : f32) {41    ^bb0(%lhs : f32, %rhs: f32):42      %res = arith.addf %lhs, %rhs : f3243      scf.reduce.return %res : f3244    }45    // CHECK: omp.yield46  }47  // CHECK: omp.terminator48  // CHECK: llvm.load %[[BUF]]49  return50}51 52// -----53 54// Only check the declaration here, the rest is same as above.55// CHECK: omp.declare_reduction @{{.*}} : f3256 57// CHECK: init58// CHECK: %[[INIT:.*]] = llvm.mlir.constant(1.000000e+00 : f32)59// CHECK: omp.yield(%[[INIT]] : f32)60 61// CHECK: combiner62// CHECK: ^{{.*}}(%[[ARG0:.*]]: f32, %[[ARG1:.*]]: f32)63// CHECK: %[[RES:.*]] = arith.mulf %[[ARG0]], %[[ARG1]]64// CHECK: omp.yield(%[[RES]] : f32)65 66// CHECK-NOT: atomic67 68// CHECK-LABEL: @reduction269func.func @reduction2(%arg0 : index, %arg1 : index, %arg2 : index,70                 %arg3 : index, %arg4 : index) {71  %step = arith.constant 1 : index72  %zero = arith.constant 0.0 : f3273  scf.parallel (%i0, %i1) = (%arg0, %arg1) to (%arg2, %arg3)74                            step (%arg4, %step) init (%zero) -> (f32) {75    %one = arith.constant 1.0 : f3276    scf.reduce(%one : f32) {77    ^bb0(%lhs : f32, %rhs: f32):78      %res = arith.mulf %lhs, %rhs : f3279      scf.reduce.return %res : f3280    }81  }82  return83}84 85// -----86 87// Check the generation of declaration for arith.muli.88// Mostly, the same check as above, except for the types,89// the name of the op and the init value.90 91// CHECK: omp.declare_reduction @[[$REDI:.*]] : i3292 93// CHECK: init94// CHECK: %[[INIT:.*]] = llvm.mlir.constant(1 : i32)95// CHECK: omp.yield(%[[INIT]] : i32)96 97// CHECK: combiner98// CHECK: ^{{.*}}(%[[ARG0:.*]]: i32, %[[ARG1:.*]]: i32)99// CHECK: %[[RES:.*]] = arith.muli %[[ARG0]], %[[ARG1]]100// CHECK: omp.yield(%[[RES]] : i32)101 102// CHECK-NOT: atomic103 104// CHECK-LABEL: @reduction_muli105func.func @reduction_muli(%arg0 : index, %arg1 : index, %arg2 : index,106                 %arg3 : index, %arg4 : index) {107  %step = arith.constant 1 : index108  %one = arith.constant 1 : i32109  // CHECK: %[[RED_VAR:.*]] = llvm.alloca %{{.*}} x i32 : (i64) -> !llvm.ptr110  // CHECK: omp.wsloop reduction(@[[$REDI]] %[[RED_VAR]] -> %[[RED_PVT_VAR:.*]] : !llvm.ptr)111  // CHECK: omp.loop_nest112  scf.parallel (%i0, %i1) = (%arg0, %arg1) to (%arg2, %arg3)113                            step (%arg4, %step) init (%one) -> (i32) {114    // CHECK: %[[C2:.*]] = arith.constant 2 : i32115    %pow2 = arith.constant 2 : i32116    // CHECK: %[[RED_PVT_VAL:.*]] = llvm.load %[[RED_PVT_VAR]] : !llvm.ptr -> i32117    // CHECK: %[[MUL_RESULT:.*]] = arith.muli %[[RED_PVT_VAL]], %[[C2]] : i32118    // CHECK: llvm.store %[[MUL_RESULT]], %[[RED_PVT_VAR]] : i32, !llvm.ptr119    scf.reduce(%pow2 : i32) {120    ^bb0(%lhs : i32, %rhs: i32):121      %res = arith.muli %lhs, %rhs : i32122      scf.reduce.return %res : i32123    }124  }125  return126}127 128// -----129 130// Only check the declaration here, the rest is same as above.131// CHECK: omp.declare_reduction @{{.*}} : f32132 133// CHECK: init134// CHECK: %[[INIT:.*]] = llvm.mlir.constant(-3.4135// CHECK: omp.yield(%[[INIT]] : f32)136 137// CHECK: combiner138// CHECK: ^{{.*}}(%[[ARG0:.*]]: f32, %[[ARG1:.*]]: f32)139// CHECK: %[[CMP:.*]] = arith.cmpf oge, %[[ARG0]], %[[ARG1]]140// CHECK: %[[RES:.*]] = arith.select %[[CMP]], %[[ARG0]], %[[ARG1]]141// CHECK: omp.yield(%[[RES]] : f32)142 143// CHECK-NOT: atomic144 145// CHECK-LABEL: @reduction3146func.func @reduction3(%arg0 : index, %arg1 : index, %arg2 : index,147                 %arg3 : index, %arg4 : index) {148  %step = arith.constant 1 : index149  %zero = arith.constant 0.0 : f32150  scf.parallel (%i0, %i1) = (%arg0, %arg1) to (%arg2, %arg3)151                            step (%arg4, %step) init (%zero) -> (f32) {152    %one = arith.constant 1.0 : f32153    scf.reduce(%one : f32) {154    ^bb0(%lhs : f32, %rhs: f32):155      %cmp = arith.cmpf oge, %lhs, %rhs : f32156      %res = arith.select %cmp, %lhs, %rhs : f32157      scf.reduce.return %res : f32158    }159  }160  return161}162 163// -----164 165// CHECK: omp.declare_reduction @[[$REDF1:.*]] : f32166 167// CHECK: init168// CHECK: %[[INIT:.*]] = llvm.mlir.constant(-3.4169// CHECK: omp.yield(%[[INIT]] : f32)170 171// CHECK: combiner172// CHECK: ^{{.*}}(%[[ARG0:.*]]: f32, %[[ARG1:.*]]: f32)173// CHECK: %[[CMP:.*]] = arith.cmpf oge, %[[ARG0]], %[[ARG1]]174// CHECK: %[[RES:.*]] = arith.select %[[CMP]], %[[ARG0]], %[[ARG1]]175// CHECK: omp.yield(%[[RES]] : f32)176 177// CHECK-NOT: atomic178 179// CHECK: omp.declare_reduction @[[$REDF2:.*]] : i64180 181// CHECK: init182// CHECK: %[[INIT:.*]] = llvm.mlir.constant183// CHECK: omp.yield(%[[INIT]] : i64)184 185// CHECK: combiner186// CHECK: ^{{.*}}(%[[ARG0:.*]]: i64, %[[ARG1:.*]]: i64)187// CHECK: %[[CMP:.*]] = arith.cmpi slt, %[[ARG0]], %[[ARG1]]188// CHECK: %[[RES:.*]] = arith.select %[[CMP]], %[[ARG1]], %[[ARG0]]189// CHECK: omp.yield(%[[RES]] : i64)190 191// CHECK: atomic192// CHECK: ^{{.*}}(%[[ARG0:.*]]: !llvm.ptr, %[[ARG1:.*]]: !llvm.ptr):193// CHECK: %[[RHS:.*]] = llvm.load %[[ARG1]] : !llvm.ptr -> i64194// CHECK: llvm.atomicrmw max %[[ARG0]], %[[RHS]] monotonic195 196// CHECK-LABEL: @reduction4197func.func @reduction4(%arg0 : index, %arg1 : index, %arg2 : index,198                 %arg3 : index, %arg4 : index) -> (f32, i64) {199  %step = arith.constant 1 : index200  // CHECK: %[[ZERO:.*]] = arith.constant 0.0201  %zero = arith.constant 0.0 : f32202  // CHECK: %[[IONE:.*]] = arith.constant 1203  %ione = arith.constant 1 : i64204  // CHECK: %[[BUF1:.*]] = llvm.alloca %{{.*}} x f32205  // CHECK: llvm.store %[[ZERO]], %[[BUF1]]206  // CHECK: %[[BUF2:.*]] = llvm.alloca %{{.*}} x i64207  // CHECK: llvm.store %[[IONE]], %[[BUF2]]208 209  // CHECK: omp.parallel210  // CHECK: omp.wsloop211  // CHECK-SAME: reduction(@[[$REDF1]] %[[BUF1]] -> %[[PVT_BUF1:[a-z0-9]+]]212  // CHECK-SAME:           @[[$REDF2]] %[[BUF2]] -> %[[PVT_BUF2:[a-z0-9]+]]213  // CHECK: omp.loop_nest214  // CHECK: memref.alloca_scope215  %res:2 = scf.parallel (%i0, %i1) = (%arg0, %arg1) to (%arg2, %arg3)216                        step (%arg4, %step) init (%zero, %ione) -> (f32, i64) {217    // CHECK: %[[CST_ONE:.*]] = arith.constant 1.0{{.*}} : f32218    %one = arith.constant 1.0 : f32219    // CHECK: %[[CST_INT_ONE:.*]] = arith.fptosi220    %1 = arith.fptosi %one : f32 to i64221    // CHECK: %[[PVT_VAL1:.*]] = llvm.load %[[PVT_BUF1]] : !llvm.ptr -> f32222    // CHECK: %[[TEMP1:.*]] = arith.cmpf oge, %[[PVT_VAL1]], %[[CST_ONE]] : f32223    // CHECK: %[[CMP_VAL1:.*]] = arith.select %[[TEMP1]], %[[PVT_VAL1]], %[[CST_ONE]] : f32224    // CHECK: llvm.store %[[CMP_VAL1]], %[[PVT_BUF1]] : f32, !llvm.ptr225    // CHECK: %[[PVT_VAL2:.*]] = llvm.load %[[PVT_BUF2]] : !llvm.ptr -> i64226    // CHECK: %[[TEMP2:.*]] = arith.cmpi slt, %[[PVT_VAL2]], %[[CST_INT_ONE]] : i64227    // CHECK: %[[CMP_VAL2:.*]] = arith.select %[[TEMP2]], %[[CST_INT_ONE]], %[[PVT_VAL2]] : i64228    // CHECK: llvm.store %[[CMP_VAL2]], %[[PVT_BUF2]] : i64, !llvm.ptr229    scf.reduce(%one, %1 : f32, i64) {230    ^bb0(%lhs : f32, %rhs: f32):231      %cmp = arith.cmpf oge, %lhs, %rhs : f32232      %res = arith.select %cmp, %lhs, %rhs : f32233      scf.reduce.return %res : f32234    }, {235    ^bb1(%lhs: i64, %rhs: i64):236      %cmp = arith.cmpi slt, %lhs, %rhs : i64237      %res = arith.select %cmp, %rhs, %lhs : i64238      scf.reduce.return %res : i64239    }240    // CHECK: omp.yield241  }242  // CHECK: omp.terminator243  // CHECK: %[[RES1:.*]] = llvm.load %[[BUF1]] : !llvm.ptr -> f32244  // CHECK: %[[RES2:.*]] = llvm.load %[[BUF2]] : !llvm.ptr -> i64245  // CHECK: return %[[RES1]], %[[RES2]]246  return %res#0, %res#1 : f32, i64247}248