brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.3 KiB · 951624d Raw
67 lines · plain
1// RUN: mlir-opt -int-range-optimizations -canonicalize %s | FileCheck %s2 3// Most operations are covered by the `arith` tests, which use the same code4// Here, we add a few tests to ensure the "index can be 32- or 64-bit" handling5// code is operating as expected.6 7// CHECK-LABEL: func @add_same_for_both8// CHECK: %[[true:.*]] = index.bool.constant true9// CHECK: return %[[true]]10func.func @add_same_for_both(%arg0 : index) -> i1 {11  %c1 = index.constant 112  %calmostBig = index.constant 0xfffffffe13  %0 = index.minu %arg0, %calmostBig14  %1 = index.add %0, %c115  %2 = index.cmp uge(%1, %c1)16  func.return %2 : i117}18 19// CHECK-LABEL: func @add_unsigned_ov20// CHECK: %[[uge:.*]] = index.cmp uge21// CHECK: return %[[uge]]22func.func @add_unsigned_ov(%arg0 : index) -> i1 {23  %c1 = index.constant 124  %cu32_max = index.constant 0xffffffff25  %0 = index.minu %arg0, %cu32_max26  %1 = index.add %0, %c127  // On 32-bit, the add could wrap, so the result doesn't have to be >= 128  %2 = index.cmp uge(%1, %c1)29  func.return %2 : i130}31 32// CHECK-LABEL: func @add_signed_ov33// CHECK: %[[sge:.*]] = index.cmp sge34// CHECK: return %[[sge]]35func.func @add_signed_ov(%arg0 : index) -> i1 {36  %c0 = index.constant 037  %c1 = index.constant 138  %ci32_max = index.constant 0x7fffffff39  %0 = index.minu %arg0, %ci32_max40  %1 = index.add %0, %c141  // On 32-bit, the add could wrap, so the result doesn't have to be positive42  %2 = index.cmp sge(%1, %c0)43  func.return %2 : i144}45 46// CHECK-LABEL: func @add_big47// CHECK: %[[true:.*]] = index.bool.constant true48// CHECK: return %[[true]]49func.func @add_big(%arg0 : index) -> i1 {50  %c1 = index.constant 151  %cmin = index.constant 0x30000000052  %cmax = index.constant 0x30000ffff53  // Note: the order of the clamps matters.54  // If you go max, then min, you infer the ranges [0x300...0, 0xff..ff]55  // and then [0x30...0000, 0x30...ffff]56  // If you switch the order of the below operations, you instead first infer57  // the range [0,0x3...ffff]. Then, the min inference can't constraint58  // this intermediate, since in the 32-bit case we could have, for example59  // trunc(%arg0 = 0x2ffffffff) = 0xffffffff > trunc(0x30000ffff) = 0x0000ffff60  // which means we can't do any inference.61  %0 = index.maxu %arg0, %cmin62  %1 = index.minu %0, %cmax63  %2 = index.add %1, %c164  %3 = index.cmp uge(%1, %cmin)65  func.return %3 : i166}67