Skip to content

Commit 9c1f3e8

Browse files
authored
Cranelift: mid-end: fix constant types in some icmp/select rules. (#12504)
* Cranelift: mid-end: fix constant types in some icmp/select rules. Fixes #12503. * Update tests.
1 parent 196a50c commit 9c1f3e8

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

cranelift/codegen/src/opts/icmp.isle

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -387,33 +387,33 @@
387387
;; constants can directly use the inner select condition.
388388
;; See: https://github.com/bytecodealliance/wasmtime/issues/11578
389389
(rule (simplify (eq _
390-
(select select_ty inner_cond
390+
(select select_ty inner_cond @ (value_type inner_ty)
391391
(iconst_u _ k1)
392392
(iconst_u _ k2))
393393
(iconst_u _ k1)))
394394
(if-let false (u64_eq k1 k2))
395-
(ne select_ty inner_cond (iconst_u select_ty 0)))
395+
(ne select_ty inner_cond (iconst_u inner_ty 0)))
396396

397397
(rule (simplify (eq _
398-
(select select_ty inner_cond
398+
(select select_ty inner_cond @ (value_type inner_ty)
399399
(iconst_u _ k1)
400400
(iconst_u _ k2))
401401
(iconst_u _ k2)))
402402
(if-let false (u64_eq k1 k2))
403-
(eq select_ty inner_cond (iconst_u select_ty 0)))
403+
(eq select_ty inner_cond (iconst_u inner_ty 0)))
404404

405405
(rule (simplify (ne _
406-
(select select_ty inner_cond
406+
(select select_ty inner_cond @ (value_type inner_ty)
407407
(iconst_u _ k1)
408408
(iconst_u _ k2))
409409
(iconst_u _ k1)))
410410
(if-let false (u64_eq k1 k2))
411-
(eq select_ty inner_cond (iconst_u select_ty 0)))
411+
(eq select_ty inner_cond (iconst_u inner_ty 0)))
412412

413413
(rule (simplify (ne _
414-
(select select_ty inner_cond
414+
(select select_ty inner_cond @ (value_type inner_ty)
415415
(iconst_u _ k1)
416416
(iconst_u _ k2))
417417
(iconst_u _ k2)))
418418
(if-let false (u64_eq k1 k2))
419-
(ne select_ty inner_cond (iconst_u select_ty 0)))
419+
(ne select_ty inner_cond (iconst_u inner_ty 0)))

cranelift/filetests/filetests/egraph/issue-11578-opt.clif

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ block0(v2: i64):
4343
; nextln: v14 = iconst.i64 -562949953421310
4444
; nextln: v3 = band v2, v14 ; v14 = -562949953421310
4545
; nextln: v16 = iconst.i64 0
46-
; nextln: v18 = icmp ne v3, v16 ; v16 = 0
47-
; nextln: return v18
46+
; nextln: v19 = icmp ne v3, v16 ; v16 = 0
47+
; nextln: return v19
4848
; nextln: }
4949

5050
function %ne_k1(i64) -> i8 {
@@ -65,8 +65,8 @@ block0(v2: i64):
6565
; nextln: v14 = iconst.i64 -562949953421310
6666
; nextln: v3 = band v2, v14 ; v14 = -562949953421310
6767
; nextln: v16 = iconst.i64 0
68-
; nextln: v18 = icmp ne v3, v16 ; v16 = 0
69-
; nextln: return v18
68+
; nextln: v19 = icmp ne v3, v16 ; v16 = 0
69+
; nextln: return v19
7070
; nextln: }
7171

7272
function %ne_k2(i64) -> i8 {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
test compile
2+
set opt_level=speed_and_size
3+
target aarch64
4+
5+
function u0:1360(i8) -> i8 system_v {
6+
block0(v0: i8):
7+
v1 = iconst.i64 0
8+
v2 = iconst.i64 1
9+
v3 = select v0, v1, v2
10+
v4 = icmp_imm eq v3, 1
11+
return v4
12+
}

0 commit comments

Comments
 (0)