|
| 1 | +// Tests comparison operations. |
| 2 | +// These tests are intended to be target agnostic: they should yield the same results |
| 3 | +// regardless of the target platform. |
| 4 | + |
| 5 | +// RUN: mlir-opt %s --convert-scf-to-cf --convert-cf-to-llvm --convert-vector-to-llvm \ |
| 6 | +// RUN: --convert-func-to-llvm --convert-arith-to-llvm | \ |
| 7 | +// RUN: mlir-cpu-runner -e entry -entry-point-result=void \ |
| 8 | +// RUN: --shared-libs=%mlir_c_runner_utils | \ |
| 9 | +// RUN: FileCheck %s --match-full-lines |
| 10 | + |
| 11 | +func.func @signed_comparison_on_i1s() { |
| 12 | + // signed comparisons on i1s |
| 13 | + // slt 0 1 = false, sle 0 1 = false, sgt 0 1 = true, sge 0 1 = true |
| 14 | + // CHECK: 0 |
| 15 | + // CHECK-NEXT: 0 |
| 16 | + // CHECK-NEXT: 1 |
| 17 | + // CHECK-NEXT: 1 |
| 18 | + %false = arith.constant false |
| 19 | + %true = arith.constant true |
| 20 | + %0 = arith.cmpi slt, %false, %true : i1 |
| 21 | + %1 = arith.cmpi sle, %false, %true : i1 |
| 22 | + %2 = arith.cmpi sgt, %false, %true : i1 |
| 23 | + %3 = arith.cmpi sge, %false, %true : i1 |
| 24 | + vector.print %0 : i1 |
| 25 | + vector.print %1 : i1 |
| 26 | + vector.print %2 : i1 |
| 27 | + vector.print %3 : i1 |
| 28 | + return |
| 29 | +} |
| 30 | + |
| 31 | +func.func @sge_0_1_is_true() { |
| 32 | + // sge 0 -1, sge 0 1, should be true |
| 33 | + // sge 0 -1 == sge 0 1 == true (1) |
| 34 | + // CHECK-NEXT: 1 |
| 35 | + // CHECK-NEXT: 1 |
| 36 | + %false = arith.constant 0 : i1 |
| 37 | + %true = arith.constant 1 : i1 |
| 38 | + %true_0 = arith.constant -1 : i1 |
| 39 | + %0 = arith.cmpi sge, %false, %true : i1 |
| 40 | + %1 = arith.cmpi sge, %false, %true_0 : i1 |
| 41 | + vector.print %0 : i1 |
| 42 | + vector.print %1 : i1 |
| 43 | + return |
| 44 | +} |
| 45 | + |
| 46 | +func.func @zero_ult_min_index() { |
| 47 | + // 0 `ult` -2^63 = true |
| 48 | + // CHECK-NEXT: 1 |
| 49 | + %c0 = arith.constant 0 : index |
| 50 | + %c-9223372036854775808 = arith.constant -9223372036854775808 : index |
| 51 | + %0 = arith.cmpi ult, %c0, %c-9223372036854775808 : index |
| 52 | + vector.print %0 : i1 |
| 53 | + return |
| 54 | +} |
| 55 | + |
| 56 | +func.func @entry() { |
| 57 | + func.call @signed_comparison_on_i1s() : () -> () |
| 58 | + func.call @sge_0_1_is_true() : () -> () |
| 59 | + func.call @zero_ult_min_index() : () -> () |
| 60 | + return |
| 61 | +} |
0 commit comments