Skip to content

Commit 1c46fc0

Browse files
pingshiyukuharbanach-space
authored
[mlir][arith] Add comparison integration tests (#96974)
Comparison operations regression tests, from the original larger PR that has been broken down: #92272 --------- Co-authored-by: Jakub Kuderski <[email protected]> Co-authored-by: Andrzej Warzyński <[email protected]>
1 parent 1193f7d commit 1c46fc0

File tree

1 file changed

+174
-0
lines changed

1 file changed

+174
-0
lines changed
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
// RUN: mlir-opt %s --convert-scf-to-cf --convert-cf-to-llvm --convert-vector-to-llvm \
2+
// RUN: --convert-func-to-llvm --convert-arith-to-llvm | \
3+
// RUN: mlir-cpu-runner -e entry -entry-point-result=void \
4+
// RUN: --shared-libs=%mlir_c_runner_utils | \
5+
// RUN: FileCheck %s --match-full-lines
6+
7+
func.func @cmpi_eq_i1(%v1 : i1, %v2 : i1) {
8+
vector.print str "@cmpi_eq_i1\n"
9+
%res = arith.cmpi eq, %v1, %v2 : i1
10+
vector.print %res : i1
11+
return
12+
}
13+
14+
func.func @cmpi_slt_i1(%v1 : i1, %v2 : i1) {
15+
vector.print str "@cmpi_slt_i1\n"
16+
%res = arith.cmpi slt, %v1, %v2 : i1
17+
vector.print %res : i1
18+
return
19+
}
20+
21+
func.func @cmpi_sle_i1(%v1 : i1, %v2 : i1) {
22+
vector.print str "@cmpi_sle_i1\n"
23+
%res = arith.cmpi sle, %v1, %v2 : i1
24+
vector.print %res : i1
25+
return
26+
}
27+
28+
func.func @cmpi_sgt_i1(%v1 : i1, %v2 : i1) {
29+
vector.print str "@cmpi_sgt_i1\n"
30+
%res = arith.cmpi sgt, %v1, %v2 : i1
31+
vector.print %res : i1
32+
return
33+
}
34+
35+
func.func @cmpi_sge_i1(%v1 : i1, %v2 : i1) {
36+
vector.print str "@cmpi_sge_i1\n"
37+
%res = arith.cmpi sge, %v1, %v2 : i1
38+
vector.print %res : i1
39+
return
40+
}
41+
42+
func.func @cmpi_eq() {
43+
// ------------------------------------------------
44+
// Test i1
45+
// ------------------------------------------------
46+
%false_i1 = arith.constant 0 : i1
47+
%true_i1 = arith.constant 1 : i1
48+
%true_i1_n1 = arith.constant -1 : i1
49+
50+
// int values 1 and -1 are represented with the same bitvector (`0b1`)
51+
// CHECK-LABEL: @cmpi_eq_i1
52+
// CHECK-NEXT: 1
53+
func.call @cmpi_eq_i1(%true_i1, %true_i1_n1) : (i1, i1) -> ()
54+
55+
// CHECK-LABEL: @cmpi_eq_i1
56+
// CHECK-NEXT: 0
57+
func.call @cmpi_eq_i1(%false_i1, %true_i1) : (i1, i1) -> ()
58+
59+
// CHECK-LABEL: @cmpi_eq_i1
60+
// CHECK-NEXT: 0
61+
func.call @cmpi_eq_i1(%true_i1, %false_i1) : (i1, i1) -> ()
62+
63+
// CHECK-LABEL: @cmpi_eq_i1
64+
// CHECK-NEXT: 1
65+
func.call @cmpi_eq_i1(%true_i1, %true_i1) : (i1, i1) -> ()
66+
67+
// CHECK-LABEL: @cmpi_eq_i1
68+
// CHECK-NEXT: 1
69+
func.call @cmpi_eq_i1(%false_i1, %false_i1) : (i1, i1) -> ()
70+
71+
%false = arith.constant false
72+
%true = arith.constant true
73+
74+
// CHECK-LABEL: @cmpi_eq_i1
75+
// CHECK-NEXT: 1
76+
func.call @cmpi_eq_i1(%true, %true_i1) : (i1, i1) -> ()
77+
78+
// CHECK-LABEL: @cmpi_eq_i1
79+
// CHECK-NEXT: 1
80+
func.call @cmpi_eq_i1(%false, %false_i1) : (i1, i1) -> ()
81+
82+
// CHECK-LABEL: @cmpi_eq_i1
83+
// CHECK-NEXT: 1
84+
func.call @cmpi_eq_i1(%true, %true_i1_n1) : (i1, i1) -> ()
85+
86+
// ------------------------------------------------
87+
// TODO: Test i8, i16 etc..
88+
// ------------------------------------------------
89+
return
90+
}
91+
92+
func.func @cmpi_signed() {
93+
// ------------------------------------------------
94+
// Test i1
95+
// ------------------------------------------------
96+
%false_i1 = arith.constant 0 : i1
97+
%true_i1 = arith.constant 1 : i1
98+
%true_i1_n1 = arith.constant -1 : i1
99+
100+
// int values 1 and -1 are represented with the same bitvector (`0b1`)
101+
// But, bitvector `1` is interpreted as int value -1 in signed comparison
102+
103+
// CHECK-LABEL: @cmpi_sge_i1
104+
// CHECK-NEXT: 1
105+
func.call @cmpi_sge_i1(%false_i1, %true_i1_n1) : (i1, i1) -> ()
106+
107+
// CHECK-LABEL: @cmpi_sge_i1
108+
// CHECK-NEXT: 1
109+
func.call @cmpi_sge_i1(%false_i1, %true_i1) : (i1, i1) -> ()
110+
111+
// CHECK-LABEL: @cmpi_sge_i1
112+
// CHECK-NEXT: 0
113+
func.call @cmpi_sge_i1(%true_i1, %false_i1) : (i1, i1) -> ()
114+
115+
%false = arith.constant false
116+
%true = arith.constant true
117+
118+
// CHECK-LABEL: @cmpi_slt_i1
119+
// CHECK-NEXT: 0
120+
func.call @cmpi_slt_i1(%false, %true) : (i1, i1) -> ()
121+
122+
// CHECK-LABEL: @cmpi_sle_i1
123+
// CHECK-NEXT: 0
124+
func.call @cmpi_sle_i1(%false, %true) : (i1, i1) -> ()
125+
126+
// CHECK-LABEL: @cmpi_sgt_i1
127+
// CHECK-NEXT: 1
128+
func.call @cmpi_sgt_i1(%false, %true) : (i1, i1) -> ()
129+
130+
// CHECK-LABEL: @cmpi_sge_i1
131+
// CHECK-NEXT: 1
132+
func.call @cmpi_sge_i1(%false, %true) : (i1, i1) -> ()
133+
134+
// CHECK-LABEL: @cmpi_sge_i1
135+
// CHECK-NEXT: 0
136+
func.call @cmpi_sge_i1(%true, %false) : (i1, i1) -> ()
137+
138+
// ------------------------------------------------
139+
// TODO: Test i8, i16 etc..
140+
// ------------------------------------------------
141+
return
142+
}
143+
144+
func.func @cmpi_ult_index(%v1 : index, %v2 : index) {
145+
vector.print str "@cmpi_ult_index\n"
146+
%res = arith.cmpi ult, %v1, %v2 : index
147+
vector.print %res : i1
148+
return
149+
}
150+
151+
func.func @cmpi_unsigned() {
152+
// ------------------------------------------------
153+
// Test index
154+
// ------------------------------------------------
155+
// 0 `ult` -2^63 = true
156+
%zero = arith.constant 0 : index
157+
%index_min = arith.constant -9223372036854775808 : index
158+
159+
// CHECK-LABEL: @cmpi_ult_index
160+
// CHECK-NEXT: 1
161+
func.call @cmpi_ult_index(%zero, %index_min) : (index, index) -> ()
162+
163+
// ------------------------------------------------
164+
// TODO: i1, i8, i16, uge, ule etc..
165+
// ------------------------------------------------
166+
return
167+
}
168+
169+
func.func @entry() {
170+
func.call @cmpi_eq() : () -> ()
171+
func.call @cmpi_signed() : () -> ()
172+
func.call @cmpi_unsigned() : () -> ()
173+
return
174+
}

0 commit comments

Comments
 (0)