|
8 | 8 | // RUN: --shared-libs=%mlir_c_runner_utils | \
|
9 | 9 | // RUN: FileCheck %s --match-full-lines
|
10 | 10 |
|
11 |
| -func.func @signed_comparison_on_i1s() { |
| 11 | +func.func @slt_cmpi_i1(%v1 : i1, %v2 : i1) { |
| 12 | + vector.print str "@slt_cmpi_i1\n" |
| 13 | + %res = arith.cmpi slt, %v1, %v2 : i1 |
| 14 | + vector.print %res : i1 |
| 15 | + return |
| 16 | +} |
| 17 | + |
| 18 | +func.func @sle_cmpi_i1(%v1 : i1, %v2 : i1) { |
| 19 | + vector.print str "@sle_cmpi_i1\n" |
| 20 | + %res = arith.cmpi sle, %v1, %v2 : i1 |
| 21 | + vector.print %res : i1 |
| 22 | + return |
| 23 | +} |
| 24 | + |
| 25 | +func.func @sgt_cmpi_i1(%v1 : i1, %v2 : i1) { |
| 26 | + vector.print str "@sgt_cmpi_i1\n" |
| 27 | + %res = arith.cmpi sgt, %v1, %v2 : i1 |
| 28 | + vector.print %res : i1 |
| 29 | + return |
| 30 | +} |
| 31 | + |
| 32 | +func.func @sge_cmpi_i1(%v1 : i1, %v2 : i1) { |
| 33 | + vector.print str "@sge_cmpi_i1\n" |
| 34 | + %res = arith.cmpi sge, %v1, %v2 : i1 |
| 35 | + vector.print %res : i1 |
| 36 | + return |
| 37 | +} |
| 38 | + |
| 39 | +func.func @signed_cmpi() { |
| 40 | + // ------------------------------------------------ |
| 41 | + // Test i1 |
| 42 | + // ------------------------------------------------ |
| 43 | + %false_i1 = arith.constant 0 : i1 |
| 44 | + %true_i1 = arith.constant 1 : i1 |
| 45 | + %true_i1_n1 = arith.constant -1 : i1 |
| 46 | + |
| 47 | + // sge 0 -1, sge 0 1, should be true |
| 48 | + // sge 0 -1 == sge 0 1 == true (1) |
| 49 | + |
| 50 | + // CHECK-LABEL: @sge_cmpi_i1 |
| 51 | + // CHECK-NEXT: 1 |
| 52 | + func.call @sge_cmpi_i1(%false_i1, %true_i1_n1) : (i1, i1) -> () |
| 53 | + |
| 54 | + // CHECK-LABEL: @sge_cmpi_i1 |
| 55 | + // CHECK-NEXT: 1 |
| 56 | + func.call @sge_cmpi_i1(%false_i1, %true_i1) : (i1, i1) -> () |
| 57 | + |
| 58 | + %false = arith.constant false |
| 59 | + %true = arith.constant true |
| 60 | + |
12 | 61 | // signed comparisons on i1s
|
13 | 62 | // slt 0 1 = false, sle 0 1 = false, sgt 0 1 = true, sge 0 1 = true
|
14 |
| - // CHECK: 0 |
| 63 | + |
| 64 | + // CHECK-LABEL: @slt_cmpi_i1 |
| 65 | + // CHECK-NEXT: 0 |
| 66 | + func.call @slt_cmpi_i1(%false, %true) : (i1, i1) -> () |
| 67 | + |
| 68 | + // CHECK-LABEL: @sle_cmpi_i1 |
| 69 | + // CHECK-NEXT: 0 |
| 70 | + func.call @sle_cmpi_i1(%false, %true) : (i1, i1) -> () |
| 71 | + |
| 72 | + // CHECK-LABEL: @sgt_cmpi_i1 |
| 73 | + // CHECK-NEXT: 1 |
| 74 | + func.call @sgt_cmpi_i1(%false, %true) : (i1, i1) -> () |
| 75 | + |
| 76 | + // CHECK-LABEL: @sge_cmpi_i1 |
| 77 | + // CHECK-NEXT: 1 |
| 78 | + func.call @sge_cmpi_i1(%false, %true) : (i1, i1) -> () |
| 79 | + |
| 80 | + // check that addui_extended overflow bit is treated as -1 in comparison operations |
| 81 | + // in the case of an overflow |
| 82 | + // addui_extended -1 -1 = (..., overflow_bit) |
| 83 | + // assert(overflow_bit <= 0) |
| 84 | + %n1_i64 = arith.constant -1 : i64 |
| 85 | + %sum, %overflow = arith.addui_extended %n1_i64, %n1_i64 : i64, i1 |
| 86 | + |
| 87 | + // CHECK-LABEL: @sge_cmpi_i1 |
15 | 88 | // 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 |
| 89 | + func.call @sge_cmpi_i1(%overflow, %false) : (i1, i1) -> () |
| 90 | + |
| 91 | + // ------------------------------------------------ |
| 92 | + // Test i8, i16 etc.. TODO |
| 93 | + // ------------------------------------------------ |
28 | 94 | return
|
29 | 95 | }
|
30 | 96 |
|
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 |
| 97 | +func.func @ult_cmpi_index(%v1 : index, %v2 : index) { |
| 98 | + vector.print str "@ult_cmpi_index\n" |
| 99 | + %res = arith.cmpi ult, %v1, %v2 : index |
| 100 | + vector.print %res : i1 |
43 | 101 | return
|
44 | 102 | }
|
45 | 103 |
|
46 |
| -func.func @zero_ult_min_index() { |
| 104 | +func.func @unsigned_cmpi() { |
| 105 | + // ------------------------------------------------ |
| 106 | + // Test index |
| 107 | + // ------------------------------------------------ |
47 | 108 | // 0 `ult` -2^63 = true
|
| 109 | + %zero = arith.constant 0 : index |
| 110 | + %index_min = arith.constant -9223372036854775808 : index |
| 111 | + |
| 112 | + // CHECK-LABEL: @ult_cmpi_index |
48 | 113 | // 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 |
| 114 | + func.call @ult_cmpi_index(%zero, %index_min) : (index, index) -> () |
| 115 | + |
| 116 | + // ------------------------------------------------ |
| 117 | + // Test i1, i8, i16 etc.. TODO |
| 118 | + // ------------------------------------------------ |
53 | 119 | return
|
54 | 120 | }
|
55 | 121 |
|
56 | 122 | 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() : () -> () |
| 123 | + func.call @signed_cmpi() : () -> () |
| 124 | + func.call @unsigned_cmpi() : () -> () |
60 | 125 | return
|
61 | 126 | }
|
0 commit comments