1// RUN: mlir-opt -arith-unsigned-when-equivalent %s | FileCheck %s 2 3// CHECK-LABEL: func @not_with_maybe_overflow 4// CHECK: arith.divsi 5// CHECK: arith.ceildivsi 6// CHECK: arith.floordivsi 7// CHECK: arith.remsi 8// CHECK: arith.minsi 9// CHECK: arith.maxsi 10// CHECK: arith.extsi 11// CHECK: arith.cmpi sle 12// CHECK: arith.cmpi slt 13// CHECK: arith.cmpi sge 14// CHECK: arith.cmpi sgt 15func.func @not_with_maybe_overflow(%arg0 : i32) -> (i32, i32, i32, i32, i32, i32, i64, i1, i1, i1, i1) { 16 %ci32_smax = arith.constant 0x7fffffff : i32 17 %c1 = arith.constant 1 : i32 18 %c4 = arith.constant 4 : i32 19 %0 = arith.minui %arg0, %ci32_smax : i32 20 %1 = arith.addi %0, %c1 : i32 21 %2 = arith.divsi %1, %c4 : i32 22 %3 = arith.ceildivsi %1, %c4 : i32 23 %4 = arith.floordivsi %1, %c4 : i32 24 %5 = arith.remsi %1, %c4 : i32 25 %6 = arith.minsi %1, %c4 : i32 26 %7 = arith.maxsi %1, %c4 : i32 27 %8 = arith.extsi %1 : i32 to i64 28 %9 = arith.cmpi sle, %1, %c4 : i32 29 %10 = arith.cmpi slt, %1, %c4 : i32 30 %11 = arith.cmpi sge, %1, %c4 : i32 31 %12 = arith.cmpi sgt, %1, %c4 : i32 32 func.return %2, %3, %4, %5, %6, %7, %8, %9, %10, %11, %12 : i32, i32, i32, i32, i32, i32, i64, i1, i1, i1, i1 33} 34 35// CHECK-LABEL: func @yes_with_no_overflow 36// CHECK: arith.divui 37// CHECK: arith.ceildivui 38// CHECK: arith.divui 39// CHECK: arith.remui 40// CHECK: arith.minui 41// CHECK: arith.maxui 42// CHECK: arith.extui 43// CHECK: arith.cmpi ule 44// CHECK: arith.cmpi ult 45// CHECK: arith.cmpi uge 46// CHECK: arith.cmpi ugt 47func.func @yes_with_no_overflow(%arg0 : i32) -> (i32, i32, i32, i32, i32, i32, i64, i1, i1, i1, i1) { 48 %ci32_almost_smax = arith.constant 0x7ffffffe : i32 49 %c1 = arith.constant 1 : i32 50 %c4 = arith.constant 4 : i32 51 %0 = arith.minui %arg0, %ci32_almost_smax : i32 52 %1 = arith.addi %0, %c1 : i32 53 %2 = arith.divsi %1, %c4 : i32 54 %3 = arith.ceildivsi %1, %c4 : i32 55 %4 = arith.floordivsi %1, %c4 : i32 56 %5 = arith.remsi %1, %c4 : i32 57 %6 = arith.minsi %1, %c4 : i32 58 %7 = arith.maxsi %1, %c4 : i32 59 %8 = arith.extsi %1 : i32 to i64 60 %9 = arith.cmpi sle, %1, %c4 : i32 61 %10 = arith.cmpi slt, %1, %c4 : i32 62 %11 = arith.cmpi sge, %1, %c4 : i32 63 %12 = arith.cmpi sgt, %1, %c4 : i32 64 func.return %2, %3, %4, %5, %6, %7, %8, %9, %10, %11, %12 : i32, i32, i32, i32, i32, i32, i64, i1, i1, i1, i1 65} 66 67// CHECK-LABEL: func @preserves_structure 68// CHECK: scf.for %[[arg1:.*]] = 69// CHECK: %[[v:.*]] = arith.remui %[[arg1]] 70// CHECK: %[[w:.*]] = arith.addi %[[v]], %[[v]] 71// CHECK: %[[test:.*]] = arith.cmpi ule, %[[w]] 72// CHECK: scf.if %[[test]] 73// CHECK: memref.store %[[w]] 74func.func @preserves_structure(%arg0 : memref<8xindex>) { 75 %c0 = arith.constant 0 : index 76 %c1 = arith.constant 1 : index 77 %c4 = arith.constant 4 : index 78 %c8 = arith.constant 8 : index 79 scf.for %arg1 = %c0 to %c8 step %c1 { 80 %v = arith.remsi %arg1, %c4 : index 81 %w = arith.addi %v, %v : index 82 %test = arith.cmpi sle, %w, %c4 : index 83 scf.if %test { 84 memref.store %w, %arg0[%arg1] : memref<8xindex> 85 } 86 } 87 func.return 88} 89 90func.func private @external() -> i8 91 92// CHECK-LABEL: @dead_code 93func.func @dead_code() -> i8 { 94 %0 = call @external() : () -> i8 95 // CHECK: arith.floordivsi 96 %1 = arith.floordivsi %0, %0 : i8 97 return %1 : i8 98} 99 100// Make sure not crash. 101// CHECK-LABEL: @no_integer_or_index 102func.func @no_integer_or_index(%arg0: vector<1xi32>) -> vector<1xi1> { 103 // CHECK: arith.cmpi 104 %cst_0 = arith.constant dense<[0]> : vector<1xi32> 105 %cmp = arith.cmpi slt, %cst_0, %arg0 : vector<1xi32> 106 return %cmp : vector<1xi1> 107} 108 109// CHECK-LABEL: @gpu_func 110func.func @gpu_func(%arg0: memref<2x32xf32>, %arg1: memref<2x32xf32>, %arg2: memref<32xf32>, %arg3: f32, %arg4: !gpu.async.token, %arg5: index, %arg6: index) -> memref<2x32xf32> { 111 %c1 = arith.constant 1 : index 112 %2 = gpu.launch async [%arg4] blocks(%arg7, %arg8, %arg9) in (%arg13 = %c1, %arg14 = %c1, %arg15 = %c1) threads(%arg10, %arg11, %arg12) in (%arg16 = %c1, %arg17 = %c1, %arg18 = %c1) { 113 gpu.terminator 114 } 115 return %arg1 : memref<2x32xf32> 116} 117