Skip to content

Commit a740e34

Browse files
authored
[Cranelift] fold (and (xor (not ..) ..) ..) (#11642)
* [Cranelift] add opts and tests * [Cranelift] add runtests
1 parent c16e6fe commit a740e34

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

cranelift/codegen/src/opts/bitops.isle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,5 @@
202202
(rule (simplify (band ty (band ty x y) y)) (band ty x y))
203203
(rule (simplify (band ty x (band ty x y))) (band ty x y))
204204
(rule (simplify (band ty y (band ty x y))) (band ty x y))
205+
206+
(rule (simplify (band ty (bxor ty x (bnot ty y)) x)) (band ty x y))
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
test optimize precise-output
2+
set opt_level=speed
3+
target x86_64
4+
5+
function %test1(i8, i8) -> i8 {
6+
block0(v0: i8, v1: i8):
7+
v2 = bnot v1
8+
v3 = bxor v0, v2
9+
v4 = band v3, v0
10+
return v4
11+
}
12+
13+
; function %test1(i8, i8) -> i8 fast {
14+
; block0(v0: i8, v1: i8):
15+
; v5 = band v0, v1
16+
; return v5
17+
; }
18+
19+
function %test2(i16, i16) -> i16 {
20+
block0(v0: i16, v1: i16):
21+
v2 = bnot v1
22+
v3 = bxor v0, v2
23+
v4 = band v3, v0
24+
return v4
25+
}
26+
27+
; function %test2(i16, i16) -> i16 fast {
28+
; block0(v0: i16, v1: i16):
29+
; v5 = band v0, v1
30+
; return v5
31+
; }
32+
33+
function %test3(i32, i32) -> i32 {
34+
block0(v0: i32, v1: i32):
35+
v2 = bnot v1
36+
v3 = bxor v0, v2
37+
v4 = band v3, v0
38+
return v4
39+
}
40+
41+
; function %test3(i32, i32) -> i32 fast {
42+
; block0(v0: i32, v1: i32):
43+
; v5 = band v0, v1
44+
; return v5
45+
; }
46+
47+
function %test4(i64, i64) -> i64 {
48+
block0(v0: i64, v1: i64):
49+
v2 = bnot v1
50+
v3 = bxor v0, v2
51+
v4 = band v3, v0
52+
return v4
53+
}
54+
55+
; function %test4(i64, i64) -> i64 fast {
56+
; block0(v0: i64, v1: i64):
57+
; v5 = band v0, v1
58+
; return v5
59+
; }
60+

cranelift/filetests/filetests/runtests/bitops.clif

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,13 @@ block0(v0: i32, v1: i32):
164164

165165
; run: %test_and_and4(4, 3) == 0
166166

167+
function %fold_and_xor_not(i32, i32) -> i32 {
168+
block0(v0: i32, v1: i32):
169+
v2 = bnot v1
170+
v3 = bxor v0, v2
171+
v4 = band v3, v0
172+
return v4
173+
}
174+
175+
; run: %fold_and_xor_not(4, 5) == 4
176+

0 commit comments

Comments
 (0)