Skip to content

Commit 67046a0

Browse files
committed
comment our aux rules
1 parent 2722fd3 commit 67046a0

5 files changed

Lines changed: 119 additions & 119 deletions

File tree

cranelift/codegen/src/opts/arithmetic.isle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
(iconst_u ty 0)))
1616
(subsume x))
1717
;; 0-x == (ineg x).
18-
(rule (simplify (isub ty
19-
(iconst_u ty 0)
20-
x))
21-
(ineg ty x))
18+
;; (rule (simplify (isub ty
19+
;; (iconst_u ty 0)
20+
;; x))
21+
;; (ineg ty x))
2222

2323
;; x + -y == -y + x == -(y - x) == x - y
2424
(rule (simplify (iadd ty x (ineg ty y)))

cranelift/codegen/src/opts/cprop.isle

Lines changed: 80 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -124,40 +124,40 @@
124124
;;
125125
;; (op k x) --> (op x k)
126126

127-
(rule (simplify
128-
(iadd ty k @ (iconst ty _) x))
129-
(iadd ty x k))
127+
;; (rule (simplify
128+
;; (iadd ty k @ (iconst ty _) x))
129+
;; (iadd ty x k))
130130
;; sub is not commutative, but we can flip the args and negate the
131131
;; whole thing.
132-
(rule (simplify
133-
(isub ty k @ (iconst ty _) x))
134-
(ineg ty (isub ty x k)))
135-
(rule (simplify
136-
(imul ty k @ (iconst ty _) x))
137-
(imul ty x k))
138-
139-
(rule (simplify
140-
(bor ty k @ (iconst ty _) x))
141-
(bor ty x k))
142-
(rule (simplify
143-
(band ty k @ (iconst ty _) x))
144-
(band ty x k))
145-
(rule (simplify
146-
(bxor ty k @ (iconst ty _) x))
147-
(bxor ty x k))
148-
149-
(rule (simplify
150-
(icmp ty cc k @ (iconst _ _) x))
151-
(icmp ty (intcc_swap_args cc) x k))
132+
;; (rule (simplify
133+
;; (isub ty k @ (iconst ty _) x))
134+
;; (ineg ty (isub ty x k)))
135+
;; (rule (simplify
136+
;; (imul ty k @ (iconst ty _) x))
137+
;; (imul ty x k))
138+
139+
;; (rule (simplify
140+
;; (bor ty k @ (iconst ty _) x))
141+
;; (bor ty x k))
142+
;; (rule (simplify
143+
;; (band ty k @ (iconst ty _) x))
144+
;; (band ty x k))
145+
;; (rule (simplify
146+
;; (bxor ty k @ (iconst ty _) x))
147+
;; (bxor ty x k))
148+
149+
;; (rule (simplify
150+
;; (icmp ty cc k @ (iconst _ _) x))
151+
;; (icmp ty (intcc_swap_args cc) x k))
152152

153153
;; Canonicalize via associativity: reassociate to a right-heavy tree
154154
;; for constants.
155155
;;
156156
;; (op (op x k) k) --> (op x (op k k))
157157

158-
(rule (simplify
159-
(iadd ty (iadd ty x k1 @ (iconst ty _)) k2 @ (iconst ty _)))
160-
(iadd ty x (iadd ty k1 k2)))
158+
;; (rule (simplify
159+
;; (iadd ty (iadd ty x k1 @ (iconst ty _)) k2 @ (iconst ty _)))
160+
;; (iadd ty x (iadd ty k1 k2)))
161161
;; sub is not directly associative, but we can flip a sub to an add to
162162
;; make it work:
163163
;; - (sub (sub x k1) k2) -> (sub x (add k1 k2))
@@ -186,18 +186,18 @@
186186
(iconst ty (u64_from_imm64 k2))))
187187
(isub ty (iconst ty (imm64_masked ty (u64_wrapping_add k1 k2))) x))
188188

189-
(rule (simplify
190-
(imul ty (imul ty x k1 @ (iconst ty _)) k2 @ (iconst ty _)))
191-
(imul ty x (imul ty k1 k2)))
192-
(rule (simplify
193-
(bor ty (bor ty x k1 @ (iconst ty _)) k2 @ (iconst ty _)))
194-
(bor ty x (bor ty k1 k2)))
195-
(rule (simplify
196-
(band ty (band ty x k1 @ (iconst ty _)) k2 @ (iconst ty _)))
197-
(band ty x (band ty k1 k2)))
198-
(rule (simplify
199-
(bxor ty (bxor ty x k1 @ (iconst ty _)) k2 @ (iconst ty _)))
200-
(bxor ty x (bxor ty k1 k2)))
189+
;; (rule (simplify
190+
;; (imul ty (imul ty x k1 @ (iconst ty _)) k2 @ (iconst ty _)))
191+
;; (imul ty x (imul ty k1 k2)))
192+
;; (rule (simplify
193+
;; (bor ty (bor ty x k1 @ (iconst ty _)) k2 @ (iconst ty _)))
194+
;; (bor ty x (bor ty k1 k2)))
195+
;; (rule (simplify
196+
;; (band ty (band ty x k1 @ (iconst ty _)) k2 @ (iconst ty _)))
197+
;; (band ty x (band ty k1 k2)))
198+
;; (rule (simplify
199+
;; (bxor ty (bxor ty x k1 @ (iconst ty _)) k2 @ (iconst ty _)))
200+
;; (bxor ty x (bxor ty k1 k2)))
201201

202202
(rule (simplify (select ty (iconst_u _ (u64_when_non_zero)) x _))
203203
(subsume x))
@@ -206,20 +206,20 @@
206206

207207
;; Reassociate across `==`/`!=` when we can simplify a constant
208208
;; `x + K1 == K2` --> `x == K2 - K1`
209-
(rule (simplify (eq ty1 (iadd ty2 x k1@(iconst _ _)) k2@(iconst _ _)))
210-
(eq ty1 x (isub ty2 k2 k1)))
211-
(rule (simplify (ne ty1 (iadd ty2 x k1@(iconst _ _)) k2@(iconst _ _)))
212-
(ne ty1 x (isub ty2 k2 k1)))
209+
;; (rule (simplify (eq ty1 (iadd ty2 x k1@(iconst _ _)) k2@(iconst _ _)))
210+
;; (eq ty1 x (isub ty2 k2 k1)))
211+
;; (rule (simplify (ne ty1 (iadd ty2 x k1@(iconst _ _)) k2@(iconst _ _)))
212+
;; (ne ty1 x (isub ty2 k2 k1)))
213213
;; `x - K1 == K2` --> `x == K2 + K1`
214-
(rule (simplify (eq ty1 (isub ty2 x k1@(iconst _ _)) k2@(iconst _ _)))
215-
(eq ty1 x (iadd ty2 k2 k1)))
216-
(rule (simplify (ne ty1 (isub ty2 x k1@(iconst _ _)) k2@(iconst _ _)))
217-
(ne ty1 x (iadd ty2 k2 k1)))
214+
;; (rule (simplify (eq ty1 (isub ty2 x k1@(iconst _ _)) k2@(iconst _ _)))
215+
;; (eq ty1 x (iadd ty2 k2 k1)))
216+
;; (rule (simplify (ne ty1 (isub ty2 x k1@(iconst _ _)) k2@(iconst _ _)))
217+
;; (ne ty1 x (iadd ty2 k2 k1)))
218218
;; `x + K1 == y + K2` --> `x == y + (K2 - K1)`
219-
(rule (simplify (eq ty1 (iadd ty2 x k1@(iconst _ _)) (iadd ty3 y k2@(iconst _ _))))
220-
(eq ty1 x (iadd ty2 y (isub ty3 k2 k1))))
221-
(rule (simplify (ne ty1 (iadd ty2 x k1@(iconst _ _)) (iadd ty3 y k2@(iconst _ _))))
222-
(ne ty1 x (iadd ty2 y (isub ty3 k2 k1))))
219+
;; (rule (simplify (eq ty1 (iadd ty2 x k1@(iconst _ _)) (iadd ty3 y k2@(iconst _ _))))
220+
;; (eq ty1 x (iadd ty2 y (isub ty3 k2 k1))))
221+
;; (rule (simplify (ne ty1 (iadd ty2 x k1@(iconst _ _)) (iadd ty3 y k2@(iconst _ _))))
222+
;; (ne ty1 x (iadd ty2 y (isub ty3 k2 k1))))
223223
;; An icmp rule normalizes (eq sub sub), so we don't need to handle it here.
224224

225225
;; Replace subtraction by a "negative" constant with addition.
@@ -228,10 +228,10 @@
228228
;; TODO: it would be nice to do this for `x + (-1) == x - 1` as well, but
229229
;; that needs work in lowering first to avoid regressing addressing modes.
230230

231-
(rule (simplify (isub ty x (iconst_s ty k)))
232-
(if-let true (u64_lt (i64_cast_unsigned (i64_wrapping_neg k))
233-
(i64_cast_unsigned k)))
234-
(iadd ty x (iconst ty (imm64_masked ty (i64_cast_unsigned (i64_wrapping_neg k))))))
231+
;; (rule (simplify (isub ty x (iconst_s ty k)))
232+
;; (if-let true (u64_lt (i64_cast_unsigned (i64_wrapping_neg k))
233+
;; (i64_cast_unsigned k)))
234+
;; (iadd ty x (iconst ty (imm64_masked ty (i64_cast_unsigned (i64_wrapping_neg k))))))
235235

236236
;; A splat of a constant can become a direct `vconst` with the appropriate bit
237237
;; pattern.
@@ -260,39 +260,39 @@
260260
;; Reassociate nested shifts of constants to put constants together for cprop.
261261
;;
262262
;; ((A shift b) shift C) ==> ((A shift C) shift b)
263-
(rule (simplify (ishl ty (ishl ty a@(iconst _ _) b) c@(iconst _ _)))
264-
(ishl ty (ishl ty a c) b))
265-
(rule (simplify (ushr ty (ushr ty a@(iconst _ _) b) c@(iconst _ _)))
266-
(ushr ty (ushr ty a c) b))
267-
(rule (simplify (sshr ty (sshr ty a@(iconst _ _) b) c@(iconst _ _)))
268-
(sshr ty (sshr ty a c) b))
263+
;; (rule (simplify (ishl ty (ishl ty a@(iconst _ _) b) c@(iconst _ _)))
264+
;; (ishl ty (ishl ty a c) b))
265+
;; (rule (simplify (ushr ty (ushr ty a@(iconst _ _) b) c@(iconst _ _)))
266+
;; (ushr ty (ushr ty a c) b))
267+
;; (rule (simplify (sshr ty (sshr ty a@(iconst _ _) b) c@(iconst _ _)))
268+
;; (sshr ty (sshr ty a c) b))
269269

270270
;; When we operations that are both commutative and associative, reassociate
271271
;; constants together for cprop:
272272
;;
273273
;; ((a op B) op (c op D)) ==> ((a op c) op (B op D))
274274
;;
275275
;; Where `op` is one of: `iadd`, `imul`, `band`, `bor`, or `bxor`.
276-
(rule (simplify (iadd ty
277-
(iadd ty a b@(iconst _ _))
278-
(iadd ty c d@(iconst _ _))))
279-
(iadd ty (iadd ty a c) (iadd ty b d)))
280-
(rule (simplify (imul ty
281-
(imul ty a b@(iconst _ _))
282-
(imul ty c d@(iconst _ _))))
283-
(imul ty (imul ty a c) (imul ty b d)))
284-
(rule (simplify (band ty
285-
(band ty a b@(iconst _ _))
286-
(band ty c d@(iconst _ _))))
287-
(band ty (band ty a c) (band ty b d)))
288-
(rule (simplify (bor ty
289-
(bor ty a b@(iconst _ _))
290-
(bor ty c d@(iconst _ _))))
291-
(bor ty (bor ty a c) (bor ty b d)))
292-
(rule (simplify (bxor ty
293-
(bxor ty a b@(iconst _ _))
294-
(bxor ty c d@(iconst _ _))))
295-
(bxor ty (bxor ty a c) (bxor ty b d)))
276+
;; (rule (simplify (iadd ty
277+
;; (iadd ty a b@(iconst _ _))
278+
;; (iadd ty c d@(iconst _ _))))
279+
;; (iadd ty (iadd ty a c) (iadd ty b d)))
280+
;; (rule (simplify (imul ty
281+
;; (imul ty a b@(iconst _ _))
282+
;; (imul ty c d@(iconst _ _))))
283+
;; (imul ty (imul ty a c) (imul ty b d)))
284+
;; (rule (simplify (band ty
285+
;; (band ty a b@(iconst _ _))
286+
;; (band ty c d@(iconst _ _))))
287+
;; (band ty (band ty a c) (band ty b d)))
288+
;; (rule (simplify (bor ty
289+
;; (bor ty a b@(iconst _ _))
290+
;; (bor ty c d@(iconst _ _))))
291+
;; (bor ty (bor ty a c) (bor ty b d)))
292+
;; (rule (simplify (bxor ty
293+
;; (bxor ty a b@(iconst _ _))
294+
;; (bxor ty c d@(iconst _ _))))
295+
;; (bxor ty (bxor ty a c) (bxor ty b d)))
296296

297297

298298
;; Constant fold int-to-float conversions.

cranelift/codegen/src/opts/extends.isle

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@
8080
;; Matches values where the high bits of the input don't affect lower bits of
8181
;; the output, and thus the inputs can be reduced before the operation rather
8282
;; than doing the wide operation then reducing afterwards.
83-
(rule (simplify (ireduce ty (ineg _ x))) (ineg ty (ireduce ty x)))
84-
(rule (simplify (ireduce ty (bnot _ x))) (bnot ty (ireduce ty x)))
83+
;; (rule (simplify (ireduce ty (ineg _ x))) (ineg ty (ireduce ty x)))
84+
;; (rule (simplify (ireduce ty (bnot _ x))) (bnot ty (ireduce ty x)))
8585

86-
(rule (simplify (ireduce ty (iadd _ x y))) (iadd ty (ireduce ty x) (ireduce ty y)))
87-
(rule (simplify (ireduce ty (isub _ x y))) (isub ty (ireduce ty x) (ireduce ty y)))
88-
(rule (simplify (ireduce ty (imul _ x y))) (imul ty (ireduce ty x) (ireduce ty y)))
89-
(rule (simplify (ireduce ty (bor _ x y))) (bor ty (ireduce ty x) (ireduce ty y)))
90-
(rule (simplify (ireduce ty (bxor _ x y))) (bxor ty (ireduce ty x) (ireduce ty y)))
91-
(rule (simplify (ireduce ty (band _ x y))) (band ty (ireduce ty x) (ireduce ty y)))
86+
;; (rule (simplify (ireduce ty (iadd _ x y))) (iadd ty (ireduce ty x) (ireduce ty y)))
87+
;; (rule (simplify (ireduce ty (isub _ x y))) (isub ty (ireduce ty x) (ireduce ty y)))
88+
;; (rule (simplify (ireduce ty (imul _ x y))) (imul ty (ireduce ty x) (ireduce ty y)))
89+
;; (rule (simplify (ireduce ty (bor _ x y))) (bor ty (ireduce ty x) (ireduce ty y)))
90+
;; (rule (simplify (ireduce ty (bxor _ x y))) (bxor ty (ireduce ty x) (ireduce ty y)))
91+
;; (rule (simplify (ireduce ty (band _ x y))) (band ty (ireduce ty x) (ireduce ty y)))
9292

9393
;; Try to transform an `iconcat` into an i128 into either an sextend or uextend
9494
(rule (simplify (iconcat $I128 x (iconst_u _ 0))) (uextend $I128 x))

cranelift/codegen/src/opts/icmp.isle

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@
3838
;; To avoid repeating all the above rules again, normalize isub to iadd
3939
;; (a - b) == (c - d) ⟹ (a + d) == (c + b)
4040

41-
(rule (simplify (eq ty1 (isub ty2 a b) (isub ty3 c d)))
42-
(eq ty1 (iadd ty2 a d) (iadd ty3 c b)))
43-
(rule (simplify (ne ty1 (isub ty2 a b) (isub ty3 c d)))
44-
(ne ty1 (iadd ty2 a d) (iadd ty3 c b)))
41+
;; (rule (simplify (eq ty1 (isub ty2 a b) (isub ty3 c d)))
42+
;; (eq ty1 (iadd ty2 a d) (iadd ty3 c b)))
43+
;; (rule (simplify (ne ty1 (isub ty2 a b) (isub ty3 c d)))
44+
;; (ne ty1 (iadd ty2 a d) (iadd ty3 c b)))
4545

4646
;; Optimize icmp-of-icmp.
4747
;; ne(icmp(ty, cc, x, y), 0) == icmp(ty, cc, x, y)
@@ -108,21 +108,21 @@
108108
(subsume (iconst_u bty 0)))
109109

110110
;; ule(x, 0) == eq(x, 0)
111-
(rule (simplify (ule (fits_in_64 (ty_int bty)) x zero @ (iconst_u _ 0)))
112-
(eq bty x zero))
111+
;; (rule (simplify (ule (fits_in_64 (ty_int bty)) x zero @ (iconst_u _ 0)))
112+
;; (eq bty x zero))
113113

114114
;; ugt(x, 0) == ne(x, 0).
115-
(rule (simplify (ugt (fits_in_64 (ty_int bty)) x zero @ (iconst_u _ 0)))
116-
(ne bty x zero))
115+
;; (rule (simplify (ugt (fits_in_64 (ty_int bty)) x zero @ (iconst_u _ 0)))
116+
;; (ne bty x zero))
117117

118118
;; uge(x, 0) == true.
119119
(rule (simplify (uge (fits_in_64 (ty_int bty)) x zero @ (iconst_u _ 0)))
120120
(subsume (iconst_u bty 1)))
121121

122122
;; ult(x, UMAX) == ne(x, UMAX).
123-
(rule (simplify (ult (fits_in_64 (ty_int bty)) x umax @ (iconst_u cty y)))
124-
(if-let true (u64_eq y (ty_umax cty)))
125-
(ne bty x umax))
123+
;; (rule (simplify (ult (fits_in_64 (ty_int bty)) x umax @ (iconst_u cty y)))
124+
;; (if-let true (u64_eq y (ty_umax cty)))
125+
;; (ne bty x umax))
126126

127127
;; ule(x, UMAX) == true.
128128
(rule (simplify (ule (fits_in_64 (ty_int bty)) x umax @ (iconst_u cty y)))
@@ -190,23 +190,23 @@
190190

191191
;; Prefer comparing against zero
192192
;; uge(x, 1) == ne(x, 0)
193-
(rule (simplify (uge ty x (iconst_u cty 1)))
194-
(ne ty x (iconst_u cty 0)))
193+
;;(rule (simplify (uge ty x (iconst_u cty 1)))
194+
;; (ne ty x (iconst_u cty 0)))
195195
;; ult(x, 1) == eq(x, 0)
196-
(rule (simplify (ult ty x (iconst_u cty 1)))
197-
(eq ty x (iconst_u cty 0)))
196+
;; (rule (simplify (ult ty x (iconst_u cty 1)))
197+
;; (eq ty x (iconst_u cty 0)))
198198
;; sge(x, 1) == sgt(x, 0)
199-
(rule (simplify (sge ty x (iconst_s cty 1)))
200-
(sgt ty x (iconst_s cty 0)))
199+
;; (rule (simplify (sge ty x (iconst_s cty 1)))
200+
;; (sgt ty x (iconst_s cty 0)))
201201
;; slt(x, 1) == sle(x, 0)
202-
(rule (simplify (slt ty x (iconst_s cty 1)))
203-
(sle ty x (iconst_s cty 0)))
202+
;; (rule (simplify (slt ty x (iconst_s cty 1)))
203+
;; (sle ty x (iconst_s cty 0)))
204204
;; sgt(x, -1) == sge(x, 0)
205-
(rule (simplify (sgt ty x (iconst_s cty -1)))
206-
(sge ty x (iconst_s cty 0)))
205+
;; (rule (simplify (sgt ty x (iconst_s cty -1)))
206+
;; (sge ty x (iconst_s cty 0)))
207207
;; sle(x, -1) == slt(x, 0)
208-
(rule (simplify (sle ty x (iconst_s cty -1)))
209-
(slt ty x (iconst_s cty 0)))
208+
;; (rule (simplify (sle ty x (iconst_s cty -1)))
209+
;; (slt ty x (iconst_s cty 0)))
210210

211211
(decl pure partial intcc_comparable (IntCC IntCC) bool)
212212
(rule (intcc_comparable x y)

cranelift/codegen/src/opts/selects.isle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
;; Push zeroes to the right -- this makes the select `truthy`, as used elsewhere
88
;; if icmp { 0 } else { nonzero } => if !icmp { nonzero } else { 0 }
9-
(rule (simplify (select sty (icmp cty cc x y)
10-
zero @ (iconst_u _ 0)
11-
nonzero @ (iconst_u _ (u64_when_non_zero))))
12-
(select sty (icmp cty (intcc_complement cc) x y) nonzero zero))
9+
;; (rule (simplify (select sty (icmp cty cc x y)
10+
;; zero @ (iconst_u _ 0)
11+
;; nonzero @ (iconst_u _ (u64_when_non_zero))))
12+
;; (select sty (icmp cty (intcc_complement cc) x y) nonzero zero))
1313

1414
;; if icmp(x, y) { 1 } else { 0 } => uextend(icmp(x, y))
1515
(rule (simplify (select ty cmp @ (icmp _ cc x y)

0 commit comments

Comments
 (0)