Skip to content

Commit f3b408d

Browse files
authored
Algebraic opts: Reuse iconst 0 from LHS (#5724)
We don't need to spend time going through the GVN map to dedup a newly-constructed `iconst 0` when we already matched that value on the left-hand side of these rules. Also, mark these rules as subsuming any others since we can't do better than reducing an expression to a constant.
1 parent 116e5a6 commit f3b408d

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

cranelift/codegen/src/opts/algebraic.isle

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@
3838

3939
;; x*0 == 0*x == x.
4040
(rule (simplify (imul ty
41-
x
42-
(iconst ty (u64_from_imm64 0))))
43-
(iconst ty (imm64 0)))
41+
_
42+
zero @ (iconst ty (u64_from_imm64 0))))
43+
(subsume zero))
4444
(rule (simplify (imul ty
45-
(iconst ty (u64_from_imm64 0))
46-
x))
47-
(iconst ty (imm64 0)))
45+
zero @ (iconst ty (u64_from_imm64 0))
46+
_))
47+
(subsume zero))
4848

4949
;; x/1 == x.
5050
(rule (simplify (sdiv ty
@@ -118,8 +118,8 @@
118118
(rule (simplify (band $I64 (iconst $I64 (u64_from_imm64 0xffff_ffff_ffff_ffff)) x)) (subsume x))
119119

120120
;; x & 0 == 0 & x == 0.
121-
(rule (simplify (band ty x (iconst ty (u64_from_imm64 0)))) (iconst ty (imm64 0)))
122-
(rule (simplify (band ty (iconst ty (u64_from_imm64 0)) x)) (iconst ty (imm64 0)))
121+
(rule (simplify (band ty _ zero @ (iconst ty (u64_from_imm64 0)))) (subsume zero))
122+
(rule (simplify (band ty zero @ (iconst ty (u64_from_imm64 0)) _)) (subsume zero))
123123

124124
;; not(not(x)) == x.
125125
(rule (simplify (bnot ty (bnot ty x))) (subsume x))

0 commit comments

Comments
 (0)