134 lines · plain
1// RUN: mlir-opt %s -pass-pipeline="builtin.module(func.func(convert-vector-to-scf,lower-affine,convert-scf-to-cf,memref-expand,arith-expand),convert-vector-to-llvm,finalize-memref-to-llvm,convert-func-to-llvm,convert-arith-to-llvm,convert-cf-to-llvm,reconcile-unrealized-casts)" | \2// RUN: mlir-runner -e entry -entry-point-result=void \3// RUN: -shared-libs=%mlir_c_runner_utils | \4// RUN: FileCheck %s5// RUN: mlir-opt %s -pass-pipeline="builtin.module(func.func(convert-vector-to-scf,lower-affine,convert-scf-to-cf,memref-expand,arith-expand),convert-vector-to-llvm,finalize-memref-to-llvm,convert-func-to-llvm,convert-arith-to-llvm,convert-cf-to-llvm,reconcile-unrealized-casts)" | \6// RUN: mlir-runner -e main -entry-point-result=void \7// RUN: -shared-libs=%mlir_c_runner_utils | \8// RUN: FileCheck %s --check-prefix=SCHECK9 10func.func @transfer_read_2d(%A : memref<40xi32>, %base1: index) {11 %i42 = arith.constant -42: i3212 %f = vector.transfer_read %A[%base1], %i4213 {permutation_map = affine_map<(d0) -> (d0)>} :14 memref<40xi32>, vector<40xi32>15 vector.print %f: vector<40xi32>16 return17}18 19func.func @entry() {20 %c0 = arith.constant 0: index21 %c20 = arith.constant 20: i3222 %c10 = arith.constant 10: i3223 %cmin10 = arith.constant -10: i3224 %cmax_int = arith.constant 2147483647: i3225 %A = memref.alloc() : memref<40xi32>26 27 // print numerator28 affine.for %i = 0 to 40 {29 %ii = arith.index_cast %i: index to i3230 %ii30 = arith.subi %ii, %c20 : i3231 memref.store %ii30, %A[%i] : memref<40xi32>32 }33 call @transfer_read_2d(%A, %c0) : (memref<40xi32>, index) -> ()34 35 // test with ceil(*, 10)36 affine.for %i = 0 to 40 {37 %ii = arith.index_cast %i: index to i3238 %ii30 = arith.subi %ii, %c20 : i3239 %val = arith.ceildivsi %ii30, %c10 : i3240 memref.store %val, %A[%i] : memref<40xi32>41 }42 call @transfer_read_2d(%A, %c0) : (memref<40xi32>, index) -> ()43 44 // test with floor(*, 10)45 affine.for %i = 0 to 40 {46 %ii = arith.index_cast %i: index to i3247 %ii30 = arith.subi %ii, %c20 : i3248 %val = arith.floordivsi %ii30, %c10 : i3249 memref.store %val, %A[%i] : memref<40xi32>50 }51 call @transfer_read_2d(%A, %c0) : (memref<40xi32>, index) -> ()52 53 54 // test with ceil(*, -10)55 affine.for %i = 0 to 40 {56 %ii = arith.index_cast %i: index to i3257 %ii30 = arith.subi %ii, %c20 : i3258 %val = arith.ceildivsi %ii30, %cmin10 : i3259 memref.store %val, %A[%i] : memref<40xi32>60 }61 call @transfer_read_2d(%A, %c0) : (memref<40xi32>, index) -> ()62 63 // test with floor(*, -10)64 affine.for %i = 0 to 40 {65 %ii = arith.index_cast %i: index to i3266 %ii30 = arith.subi %ii, %c20 : i3267 %val = arith.floordivsi %ii30, %cmin10 : i3268 memref.store %val, %A[%i] : memref<40xi32>69 }70 call @transfer_read_2d(%A, %c0) : (memref<40xi32>, index) -> ()71 72 // test with ceildivui(*, 10)73 affine.for %i = 0 to 40 {74 %ii = arith.index_cast %i: index to i3275 %val = arith.ceildivui %ii, %c10 : i3276 memref.store %val, %A[%i] : memref<40xi32>77 }78 call @transfer_read_2d(%A, %c0) : (memref<40xi32>, index) -> ()79 80 // test with ceildivui(*, -1)81 affine.for %i = 0 to 40 {82 %ii = arith.index_cast %i: index to i3283 %ii30 = arith.subi %ii, %c20 : i3284 %val = arith.ceildivui %ii30, %cmax_int : i3285 memref.store %val, %A[%i] : memref<40xi32>86 }87 call @transfer_read_2d(%A, %c0) : (memref<40xi32>, index) -> ()88 89 memref.dealloc %A : memref<40xi32>90 return91}92 93// List below is aligned for easy manual check94// legend: num, signed_ceil(num, 10), floor(num, 10), signed_ceil(num, -10), floor(num, -10), unsigned_ceil(num, 10), unsigned_ceil(num, max_int)95// ( -20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 )96// ( -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2 )97// ( -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 )98// ( 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 )99// ( 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, -2, -2, -2, -2, -2, -2, -2, -2 )100 101// CHECK:( -20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 )102// CHECK:( -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2 )103// CHECK:( -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 )104// CHECK:( 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 )105// CHECK:( 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, -2, -2, -2, -2, -2, -2, -2, -2 )106// CHECK:( 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4 )107// CHECK:( 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 )108 109// -----110 111func.func @non_inline_function() -> (i64, i64, i64, i64, i64, i64) {112 %MIN_INT_MINUS_ONE = arith.constant -9223372036854775807 : i64113 %NEG_ONE = arith.constant -1 : i64114 %MIN_INT = arith.constant -9223372036854775808 : i64115 %ONE = arith.constant 1 : i64116 %MAX_INT = arith.constant 9223372036854775807 : i64117 return %MIN_INT_MINUS_ONE, %NEG_ONE, %MIN_INT, %ONE, %MAX_INT, %NEG_ONE : i64, i64, i64, i64, i64, i64118}119 120func.func @main() {121 %0:6 = call @non_inline_function() : () -> (i64, i64, i64, i64, i64, i64)122 %1 = arith.floordivsi %0#0, %0#1 : i64123 %2 = arith.floordivsi %0#2, %0#3 : i64124 %3 = arith.floordivsi %0#4, %0#5 : i64125 vector.print %1 : i64126 vector.print %2 : i64127 vector.print %3 : i64128 return129}130 131// SCHECK: 9223372036854775807132// SCHECK: -9223372036854775808133// SCHECK: -9223372036854775807134