Skip to content

Commit ca0e890

Browse files
committed
comparison adopting format of previous other tests
1 parent 4909f9e commit ca0e890

File tree

1 file changed

+99
-34
lines changed

1 file changed

+99
-34
lines changed

mlir/test/Integration/Dialect/Arith/CPU/comparison.mlir

Lines changed: 99 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,54 +8,119 @@
88
// RUN: --shared-libs=%mlir_c_runner_utils | \
99
// RUN: FileCheck %s --match-full-lines
1010

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+
1261
// signed comparisons on i1s
1362
// 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
1588
// 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+
// ------------------------------------------------
2894
return
2995
}
3096

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
43101
return
44102
}
45103

46-
func.func @zero_ult_min_index() {
104+
func.func @unsigned_cmpi() {
105+
// ------------------------------------------------
106+
// Test index
107+
// ------------------------------------------------
47108
// 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
48113
// 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+
// ------------------------------------------------
53119
return
54120
}
55121

56122
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() : () -> ()
60125
return
61126
}

0 commit comments

Comments
 (0)