Skip to content

Commit a74c21e

Browse files
authored
Fix a verifier error generated during optimizations (#11562)
This commit fixes an accidental regression from #11526 detected on OSS-Fuzz. The `imm64` constants created needed to be masked off to the type width to avoid having the upper bits set.
1 parent 5906a5d commit a74c21e

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

cranelift/codegen/src/opts/selects.isle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,5 @@
9696
(rule (simplify
9797
(iadd ty (select ty c (iconst_u ty x) (iconst_u ty y)) (iconst_u ty z)))
9898
(select ty c
99-
(iconst ty (imm64 (u64_add x z)))
100-
(iconst ty (imm64 (u64_add y z)))))
99+
(iconst ty (imm64_masked ty (u64_add x z)))
100+
(iconst ty (imm64_masked ty (u64_add y z)))))

cranelift/filetests/filetests/egraph/selects.clif

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,23 @@ block0(v0: i8):
2121
; return v8
2222
; }
2323

24+
25+
;; (iadd ty (select ty c x y) z) -> (select ty c (x + z) (y + z))
26+
function %simplify_iadd_select_const_i32_big_constants(i8) -> i8 fast {
27+
block0(v0: i8):
28+
v1 = iconst.i8 100
29+
v2 = iconst.i8 200
30+
v3 = select v0, v1, v2
31+
v4 = iconst.i8 200
32+
v5 = iadd v3, v4
33+
return v5
34+
}
35+
36+
; function %simplify_iadd_select_const_i32_big_constants(i8) -> i8 fast {
37+
; block0(v0: i8):
38+
; v6 = iconst.i8 44
39+
; v7 = iconst.i8 -112
40+
; v8 = select v0, v6, v7 ; v6 = 44, v7 = -112
41+
; return v8
42+
; }
43+

0 commit comments

Comments
 (0)