1// RUN: mlir-opt -int-range-optimizations --split-input-file %s | FileCheck %s 2 3// CHECK-LABEL: func @test 4// CHECK: %[[C:.*]] = arith.constant false 5// CHECK: return %[[C]] 6func.func @test() -> i1 { 7 %cst1 = arith.constant -1 : index 8 %0 = test.with_bounds { umin = 0 : index, umax = 0x7fffffffffffffff : index, smin = 0 : index, smax = 0x7fffffffffffffff : index } : index 9 %1 = arith.cmpi eq, %0, %cst1 : index 10 return %1: i1 11} 12 13// ----- 14 15// CHECK-LABEL: func @test 16// CHECK: %[[C:.*]] = arith.constant true 17// CHECK: return %[[C]] 18func.func @test() -> i1 { 19 %cst1 = arith.constant -1 : index 20 %0 = test.with_bounds { umin = 0 : index, umax = 0x7fffffffffffffff : index, smin = 0 : index, smax = 0x7fffffffffffffff : index } : index 21 %1 = arith.cmpi ne, %0, %cst1 : index 22 return %1: i1 23} 24 25// ----- 26 27 28// CHECK-LABEL: func @test 29// CHECK: %[[C:.*]] = arith.constant true 30// CHECK: return %[[C]] 31func.func @test() -> i1 { 32 %cst = arith.constant 0 : index 33 %0 = test.with_bounds { umin = 0 : index, umax = 0x7fffffffffffffff : index, smin = 0 : index, smax = 0x7fffffffffffffff : index } : index 34 %1 = arith.cmpi sge, %0, %cst : index 35 return %1: i1 36} 37 38// ----- 39 40// CHECK-LABEL: func @test 41// CHECK: %[[C:.*]] = arith.constant false 42// CHECK: return %[[C]] 43func.func @test() -> i1 { 44 %cst = arith.constant 0 : index 45 %0 = test.with_bounds { umin = 0 : index, umax = 0x7fffffffffffffff : index, smin = 0 : index, smax = 0x7fffffffffffffff : index } : index 46 %1 = arith.cmpi slt, %0, %cst : index 47 return %1: i1 48} 49 50// ----- 51 52 53// CHECK-LABEL: func @test 54// CHECK: %[[C:.*]] = arith.constant true 55// CHECK: return %[[C]] 56func.func @test() -> i1 { 57 %cst1 = arith.constant -1 : index 58 %0 = test.with_bounds { umin = 0 : index, umax = 0x7fffffffffffffff : index, smin = 0 : index, smax = 0x7fffffffffffffff : index } : index 59 %1 = arith.cmpi sgt, %0, %cst1 : index 60 return %1: i1 61} 62 63// ----- 64 65// CHECK-LABEL: func @test 66// CHECK: %[[C:.*]] = arith.constant false 67// CHECK: return %[[C]] 68func.func @test() -> i1 { 69 %cst1 = arith.constant -1 : index 70 %0 = test.with_bounds { umin = 0 : index, umax = 0x7fffffffffffffff : index, smin = 0 : index, smax = 0x7fffffffffffffff : index } : index 71 %1 = arith.cmpi sle, %0, %cst1 : index 72 return %1: i1 73} 74 75// ----- 76 77// CHECK-LABEL: func @test 78// CHECK: test.reflect_bounds {smax = 24 : si8, smin = 0 : si8, umax = 24 : ui8, umin = 0 : ui8} 79func.func @test() -> i8 { 80 %cst1 = arith.constant 1 : i8 81 %i8val = test.with_bounds { umin = 0 : i8, umax = 12 : i8, smin = 0 : i8, smax = 12 : i8 } : i8 82 %shifted = arith.shli %i8val, %cst1 : i8 83 %1 = test.reflect_bounds %shifted : i8 84 return %1: i8 85} 86 87// ----- 88 89// CHECK-LABEL: func @test 90// CHECK: test.reflect_bounds {smax = 127 : si8, smin = -128 : si8, umax = 254 : ui8, umin = 0 : ui8} 91func.func @test() -> i8 { 92 %cst1 = arith.constant 1 : i8 93 %i8val = test.with_bounds { umin = 0 : i8, umax = 127 : i8, smin = 0 : i8, smax = 127 : i8 } : i8 94 %shifted = arith.shli %i8val, %cst1 : i8 95 %1 = test.reflect_bounds %shifted : i8 96 return %1: i8 97} 98 99// ----- 100 101// CHECK-LABEL: func @trivial_rem 102// CHECK: [[val:%.+]] = test.with_bounds 103// CHECK: return [[val]] 104func.func @trivial_rem() -> i8 { 105 %c64 = arith.constant 64 : i8 106 %val = test.with_bounds { umin = 0 : ui8, umax = 63 : ui8, smin = 0 : si8, smax = 63 : si8 } : i8 107 %mod = arith.remsi %val, %c64 : i8 108 return %mod : i8 109} 110 111// ----- 112 113// CHECK-LABEL: func @non_const_rhs 114// CHECK: [[mod:%.+]] = arith.remui 115// CHECK: return [[mod]] 116func.func @non_const_rhs() -> i8 { 117 %c64 = arith.constant 64 : i8 118 %val = test.with_bounds { umin = 0 : ui8, umax = 2 : ui8, smin = 0 : si8, smax = 2 : si8 } : i8 119 %rhs = test.with_bounds { umin = 63 : ui8, umax = 64 : ui8, smin = 63 : si8, smax = 64 : si8 } : i8 120 %mod = arith.remui %val, %rhs : i8 121 return %mod : i8 122} 123 124// ----- 125 126// CHECK-LABEL: func @wraps 127// CHECK: [[mod:%.+]] = arith.remsi 128// CHECK: return [[mod]] 129func.func @wraps() -> i8 { 130 %c64 = arith.constant 64 : i8 131 %val = test.with_bounds { umin = 63 : ui8, umax = 65 : ui8, smin = 63 : si8, smax = 65 : si8 } : i8 132 %mod = arith.remsi %val, %c64 : i8 133 return %mod : i8 134} 135