Skip to content

Commit e261738

Browse files
authored
add rule and tests (#10849)
1 parent 63a8ce3 commit e261738

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

cranelift/codegen/src/opts/icmp.isle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,3 +286,7 @@
286286
(ult ty a_lo @ (value_type $I64) b_lo @ (value_type $I64))
287287
(slt ty a_hi b_hi)))
288288
(slt ty (iconcat $I64 a_lo a_hi) (iconcat $I64 b_lo b_hi)))
289+
290+
291+
(rule (simplify (eq cty x (bxor bty x y))) (subsume (eq cty y (iconst_u bty 0))))
292+
(rule (simplify (ne cty x (bxor bty x y))) (subsume (ne cty y (iconst_u bty 0))))

cranelift/filetests/filetests/egraph/icmp.clif

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,34 @@ block0(v0: i8, v1: i8):
170170
; v5 = icmp uge v0, v1
171171
; return v5
172172
; }
173+
174+
;; `x == (x ^ y)` to `y == 0`.
175+
function %simplify_icmp_eq_x_bxor_x_y(i32, i32) -> i8 fast {
176+
block0(v0: i32, v1: i32):
177+
v2 = bxor v0, v1
178+
v3 = icmp eq v0, v2
179+
return v3
180+
}
181+
182+
; function %simplify_icmp_eq_x_bxor_x_y(i32, i32) -> i8 fast {
183+
; block0(v0: i32, v1: i32):
184+
; v4 = iconst.i32 0
185+
; v5 = icmp eq v1, v4 ; v4 = 0
186+
; return v5
187+
; }
188+
189+
190+
;; `x != (x ^ y)` to `y != 0`.
191+
function %simplify_icmp_ne_x_bxor_x_y(i32, i32) -> i8 fast {
192+
block0(v0: i32, v1: i32):
193+
v2 = bxor v0, v1
194+
v3 = icmp ne v0, v2
195+
return v3
196+
}
197+
198+
; function %simplify_icmp_ne_x_bxor_x_y(i32, i32) -> i8 fast {
199+
; block0(v0: i32, v1: i32):
200+
; v4 = iconst.i32 0
201+
; v5 = icmp ne v1, v4 ; v4 = 0
202+
; return v5
203+
; }

0 commit comments

Comments
 (0)