rucc-opt 0.8.0

The pass manager, the acyclic e-graph, the rewrite rules and the analyses.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
;; The identities.
;;
;; Tier one of `spec/optimizer/13-rewrite-rules.md` section 13.4: the rewrites that hold at every
;; value of every operand, need nothing known about the operands to fire, and leave a term that is
;; strictly smaller than the one they replaced. Adding nothing, multiplying by one, and'ing a value
;; with itself. None of them is clever and none of them is optional, because the passes above this
;; one produce them by the thousand and every later pass reads whatever is left behind.
;;
;; What every rule here says is that an IR term and another IR term compute the same thing, and
;; `rucc-verify` makes each of them prove it against `simplify.model` before any of them may be
;; used. That model is one line: it includes `crates/rucc-ir/rules/ir.model` and adds nothing,
;; because a rewrite from the IR to the IR has no terms in it beyond the ones the IR already has.
;;
;; A replacement is one of two shapes. `(value.iN x)` means the instruction's result is a value
;; the function already has, so every use of the result is pointed at that value instead and the
;; instruction is left for dead code elimination. `(iconst.iN k)` means the result is a constant,
;; and the instruction becomes that constant where it stands, which keeps the result value alive
;; and is why nothing else has to be rewritten.
;;
;; Every leaf says how wide it is, and each identity is written out at every width it holds at
;; rather than once with the width left open. That is four lines where a reader might want one,
;; and it is the same trade `crates/rucc-codegen/rules/x86-64.rules` makes: a rule that names its
;; width is a rule that can be read on its own and proved on its own, and the proof is at the
;; width the rule fires at rather than at some width standing in for the others.
;;
;; A constant of all ones is written `-1` at eight bits and above and `1` at one bit, because a
;; one bit integer is read unsigned and everything wider is read signed. Both spellings mean every
;; bit set.
;;
;; The order rules are written in is for reading. Specificity is the shape of the pattern rather
;; than a sort, so no rule here is reached only because another one is below it.

;; Adding and subtracting nothing.
;;
;; The first four, and the shape of every rule below them. A pattern names an instruction and says
;; what each of its operands is, a replacement says what the result is instead, and the `spec`
;; clause states the identity that makes the two the same. That clause is written by hand and is
;; checked against the model rather than trusted, so a rule whose stated claim is not what its
;; pattern means is refused rather than proved against its own mistake.
;;
;; Both orders of the addition, because nothing puts the constant on the right yet. Doing that is
;; tier three, and it is what would make half of these unnecessary. Until it exists a rule written
;; one way round fires on half the additions it should.

(rule (simplify (add.i8 (value.i8 x) (iconst.i8 0)))
      (value.i8 x)
      (spec (= (bvadd x 0) (result))))

(rule (simplify (add.i16 (value.i16 x) (iconst.i16 0)))
      (value.i16 x)
      (spec (= (bvadd x 0) (result))))

(rule (simplify (add.i32 (value.i32 x) (iconst.i32 0)))
      (value.i32 x)
      (spec (= (bvadd x 0) (result))))

(rule (simplify (add.i64 (value.i64 x) (iconst.i64 0)))
      (value.i64 x)
      (spec (= (bvadd x 0) (result))))

(rule (simplify (add.i8 (iconst.i8 0) (value.i8 x)))
      (value.i8 x)
      (spec (= (bvadd 0 x) (result))))

(rule (simplify (add.i16 (iconst.i16 0) (value.i16 x)))
      (value.i16 x)
      (spec (= (bvadd 0 x) (result))))

(rule (simplify (add.i32 (iconst.i32 0) (value.i32 x)))
      (value.i32 x)
      (spec (= (bvadd 0 x) (result))))

(rule (simplify (add.i64 (iconst.i64 0) (value.i64 x)))
      (value.i64 x)
      (spec (= (bvadd 0 x) (result))))

(rule (simplify (sub.i8 (value.i8 x) (iconst.i8 0)))
      (value.i8 x)
      (spec (= (bvsub x 0) (result))))

(rule (simplify (sub.i16 (value.i16 x) (iconst.i16 0)))
      (value.i16 x)
      (spec (= (bvsub x 0) (result))))

(rule (simplify (sub.i32 (value.i32 x) (iconst.i32 0)))
      (value.i32 x)
      (spec (= (bvsub x 0) (result))))

(rule (simplify (sub.i64 (value.i64 x) (iconst.i64 0)))
      (value.i64 x)
      (spec (= (bvsub x 0) (result))))

(rule (simplify (sub.i8 (value.i8 x) (value.i8 x)))
      (iconst.i8 0)
      (spec (= (bvsub x x) (result))))

(rule (simplify (sub.i16 (value.i16 x) (value.i16 x)))
      (iconst.i16 0)
      (spec (= (bvsub x x) (result))))

(rule (simplify (sub.i32 (value.i32 x) (value.i32 x)))
      (iconst.i32 0)
      (spec (= (bvsub x x) (result))))

(rule (simplify (sub.i64 (value.i64 x) (value.i64 x)))
      (iconst.i64 0)
      (spec (= (bvsub x x) (result))))


;; Multiplying and dividing by one, and multiplying by nothing.
;;
;; A division by one is here and a division by two is not. The second is a shift, which is tier
;; two and is about making an operation cheaper rather than about making it disappear.
;;
;; The remainder by one is the other half of the division and is worth stating for the same reason
;; it is worth proving: it holds at every value including the most negative one, where the
;; division that goes with it would overflow if the divisor were minus one instead.

(rule (simplify (mul.i8 (value.i8 x) (iconst.i8 1)))
      (value.i8 x)
      (spec (= (bvmul x 1) (result))))

(rule (simplify (mul.i16 (value.i16 x) (iconst.i16 1)))
      (value.i16 x)
      (spec (= (bvmul x 1) (result))))

(rule (simplify (mul.i32 (value.i32 x) (iconst.i32 1)))
      (value.i32 x)
      (spec (= (bvmul x 1) (result))))

(rule (simplify (mul.i64 (value.i64 x) (iconst.i64 1)))
      (value.i64 x)
      (spec (= (bvmul x 1) (result))))

(rule (simplify (mul.i8 (iconst.i8 1) (value.i8 x)))
      (value.i8 x)
      (spec (= (bvmul 1 x) (result))))

(rule (simplify (mul.i16 (iconst.i16 1) (value.i16 x)))
      (value.i16 x)
      (spec (= (bvmul 1 x) (result))))

(rule (simplify (mul.i32 (iconst.i32 1) (value.i32 x)))
      (value.i32 x)
      (spec (= (bvmul 1 x) (result))))

(rule (simplify (mul.i64 (iconst.i64 1) (value.i64 x)))
      (value.i64 x)
      (spec (= (bvmul 1 x) (result))))

(rule (simplify (mul.i8 (value.i8 x) (iconst.i8 0)))
      (iconst.i8 0)
      (spec (= (bvmul x 0) (result))))

(rule (simplify (mul.i16 (value.i16 x) (iconst.i16 0)))
      (iconst.i16 0)
      (spec (= (bvmul x 0) (result))))

(rule (simplify (mul.i32 (value.i32 x) (iconst.i32 0)))
      (iconst.i32 0)
      (spec (= (bvmul x 0) (result))))

(rule (simplify (mul.i64 (value.i64 x) (iconst.i64 0)))
      (iconst.i64 0)
      (spec (= (bvmul x 0) (result))))

(rule (simplify (mul.i8 (iconst.i8 0) (value.i8 x)))
      (iconst.i8 0)
      (spec (= (bvmul 0 x) (result))))

(rule (simplify (mul.i16 (iconst.i16 0) (value.i16 x)))
      (iconst.i16 0)
      (spec (= (bvmul 0 x) (result))))

(rule (simplify (mul.i32 (iconst.i32 0) (value.i32 x)))
      (iconst.i32 0)
      (spec (= (bvmul 0 x) (result))))

(rule (simplify (mul.i64 (iconst.i64 0) (value.i64 x)))
      (iconst.i64 0)
      (spec (= (bvmul 0 x) (result))))

(rule (simplify (sdiv.i8 (value.i8 x) (iconst.i8 1)))
      (value.i8 x)
      (spec (= (bvsdiv x 1) (result))))

(rule (simplify (sdiv.i16 (value.i16 x) (iconst.i16 1)))
      (value.i16 x)
      (spec (= (bvsdiv x 1) (result))))

(rule (simplify (sdiv.i32 (value.i32 x) (iconst.i32 1)))
      (value.i32 x)
      (spec (= (bvsdiv x 1) (result))))

(rule (simplify (sdiv.i64 (value.i64 x) (iconst.i64 1)))
      (value.i64 x)
      (spec (= (bvsdiv x 1) (result))))

(rule (simplify (udiv.i8 (value.i8 x) (iconst.i8 1)))
      (value.i8 x)
      (spec (= (bvudiv x 1) (result))))

(rule (simplify (udiv.i16 (value.i16 x) (iconst.i16 1)))
      (value.i16 x)
      (spec (= (bvudiv x 1) (result))))

(rule (simplify (udiv.i32 (value.i32 x) (iconst.i32 1)))
      (value.i32 x)
      (spec (= (bvudiv x 1) (result))))

(rule (simplify (udiv.i64 (value.i64 x) (iconst.i64 1)))
      (value.i64 x)
      (spec (= (bvudiv x 1) (result))))

(rule (simplify (srem.i8 (value.i8 x) (iconst.i8 1)))
      (iconst.i8 0)
      (spec (= (bvsrem x 1) (result))))

(rule (simplify (srem.i16 (value.i16 x) (iconst.i16 1)))
      (iconst.i16 0)
      (spec (= (bvsrem x 1) (result))))

(rule (simplify (srem.i32 (value.i32 x) (iconst.i32 1)))
      (iconst.i32 0)
      (spec (= (bvsrem x 1) (result))))

(rule (simplify (srem.i64 (value.i64 x) (iconst.i64 1)))
      (iconst.i64 0)
      (spec (= (bvsrem x 1) (result))))

(rule (simplify (urem.i8 (value.i8 x) (iconst.i8 1)))
      (iconst.i8 0)
      (spec (= (bvurem x 1) (result))))

(rule (simplify (urem.i16 (value.i16 x) (iconst.i16 1)))
      (iconst.i16 0)
      (spec (= (bvurem x 1) (result))))

(rule (simplify (urem.i32 (value.i32 x) (iconst.i32 1)))
      (iconst.i32 0)
      (spec (= (bvurem x 1) (result))))

(rule (simplify (urem.i64 (value.i64 x) (iconst.i64 1)))
      (iconst.i64 0)
      (spec (= (bvurem x 1) (result))))


;; One value in both operands.
;;
;; These are what a pattern that writes one name in two places exists for. The two operands of an
;; instruction are two places, and what the rule asks is whether one value is in both, which is a
;; question about the function rather than about the shape of the term.

(rule (simplify (and.i8 (value.i8 x) (value.i8 x)))
      (value.i8 x)
      (spec (= (bvand x x) (result))))

(rule (simplify (and.i16 (value.i16 x) (value.i16 x)))
      (value.i16 x)
      (spec (= (bvand x x) (result))))

(rule (simplify (and.i32 (value.i32 x) (value.i32 x)))
      (value.i32 x)
      (spec (= (bvand x x) (result))))

(rule (simplify (and.i64 (value.i64 x) (value.i64 x)))
      (value.i64 x)
      (spec (= (bvand x x) (result))))

(rule (simplify (or.i8 (value.i8 x) (value.i8 x)))
      (value.i8 x)
      (spec (= (bvor x x) (result))))

(rule (simplify (or.i16 (value.i16 x) (value.i16 x)))
      (value.i16 x)
      (spec (= (bvor x x) (result))))

(rule (simplify (or.i32 (value.i32 x) (value.i32 x)))
      (value.i32 x)
      (spec (= (bvor x x) (result))))

(rule (simplify (or.i64 (value.i64 x) (value.i64 x)))
      (value.i64 x)
      (spec (= (bvor x x) (result))))

(rule (simplify (xor.i8 (value.i8 x) (value.i8 x)))
      (iconst.i8 0)
      (spec (= (bvxor x x) (result))))

(rule (simplify (xor.i16 (value.i16 x) (value.i16 x)))
      (iconst.i16 0)
      (spec (= (bvxor x x) (result))))

(rule (simplify (xor.i32 (value.i32 x) (value.i32 x)))
      (iconst.i32 0)
      (spec (= (bvxor x x) (result))))

(rule (simplify (xor.i64 (value.i64 x) (value.i64 x)))
      (iconst.i64 0)
      (spec (= (bvxor x x) (result))))


;; The bitwise operations against all zeros and against all ones.
;;
;; Six identities and four absorbing halves. An `and` with nothing keeps nothing and an `or` with
;; everything keeps everything, which is why those four produce a constant where the other six
;; produce the operand.

(rule (simplify (and.i8 (value.i8 x) (iconst.i8 0)))
      (iconst.i8 0)
      (spec (= (bvand x 0) (result))))

(rule (simplify (and.i16 (value.i16 x) (iconst.i16 0)))
      (iconst.i16 0)
      (spec (= (bvand x 0) (result))))

(rule (simplify (and.i32 (value.i32 x) (iconst.i32 0)))
      (iconst.i32 0)
      (spec (= (bvand x 0) (result))))

(rule (simplify (and.i64 (value.i64 x) (iconst.i64 0)))
      (iconst.i64 0)
      (spec (= (bvand x 0) (result))))

(rule (simplify (and.i8 (iconst.i8 0) (value.i8 x)))
      (iconst.i8 0)
      (spec (= (bvand 0 x) (result))))

(rule (simplify (and.i16 (iconst.i16 0) (value.i16 x)))
      (iconst.i16 0)
      (spec (= (bvand 0 x) (result))))

(rule (simplify (and.i32 (iconst.i32 0) (value.i32 x)))
      (iconst.i32 0)
      (spec (= (bvand 0 x) (result))))

(rule (simplify (and.i64 (iconst.i64 0) (value.i64 x)))
      (iconst.i64 0)
      (spec (= (bvand 0 x) (result))))

(rule (simplify (and.i8 (value.i8 x) (iconst.i8 -1)))
      (value.i8 x)
      (spec (= (bvand x -1) (result))))

(rule (simplify (and.i16 (value.i16 x) (iconst.i16 -1)))
      (value.i16 x)
      (spec (= (bvand x -1) (result))))

(rule (simplify (and.i32 (value.i32 x) (iconst.i32 -1)))
      (value.i32 x)
      (spec (= (bvand x -1) (result))))

(rule (simplify (and.i64 (value.i64 x) (iconst.i64 -1)))
      (value.i64 x)
      (spec (= (bvand x -1) (result))))

(rule (simplify (and.i8 (iconst.i8 -1) (value.i8 x)))
      (value.i8 x)
      (spec (= (bvand -1 x) (result))))

(rule (simplify (and.i16 (iconst.i16 -1) (value.i16 x)))
      (value.i16 x)
      (spec (= (bvand -1 x) (result))))

(rule (simplify (and.i32 (iconst.i32 -1) (value.i32 x)))
      (value.i32 x)
      (spec (= (bvand -1 x) (result))))

(rule (simplify (and.i64 (iconst.i64 -1) (value.i64 x)))
      (value.i64 x)
      (spec (= (bvand -1 x) (result))))

(rule (simplify (or.i8 (value.i8 x) (iconst.i8 0)))
      (value.i8 x)
      (spec (= (bvor x 0) (result))))

(rule (simplify (or.i16 (value.i16 x) (iconst.i16 0)))
      (value.i16 x)
      (spec (= (bvor x 0) (result))))

(rule (simplify (or.i32 (value.i32 x) (iconst.i32 0)))
      (value.i32 x)
      (spec (= (bvor x 0) (result))))

(rule (simplify (or.i64 (value.i64 x) (iconst.i64 0)))
      (value.i64 x)
      (spec (= (bvor x 0) (result))))

(rule (simplify (or.i8 (iconst.i8 0) (value.i8 x)))
      (value.i8 x)
      (spec (= (bvor 0 x) (result))))

(rule (simplify (or.i16 (iconst.i16 0) (value.i16 x)))
      (value.i16 x)
      (spec (= (bvor 0 x) (result))))

(rule (simplify (or.i32 (iconst.i32 0) (value.i32 x)))
      (value.i32 x)
      (spec (= (bvor 0 x) (result))))

(rule (simplify (or.i64 (iconst.i64 0) (value.i64 x)))
      (value.i64 x)
      (spec (= (bvor 0 x) (result))))

(rule (simplify (or.i8 (value.i8 x) (iconst.i8 -1)))
      (iconst.i8 -1)
      (spec (= (bvor x -1) (result))))

(rule (simplify (or.i16 (value.i16 x) (iconst.i16 -1)))
      (iconst.i16 -1)
      (spec (= (bvor x -1) (result))))

(rule (simplify (or.i32 (value.i32 x) (iconst.i32 -1)))
      (iconst.i32 -1)
      (spec (= (bvor x -1) (result))))

(rule (simplify (or.i64 (value.i64 x) (iconst.i64 -1)))
      (iconst.i64 -1)
      (spec (= (bvor x -1) (result))))

(rule (simplify (or.i8 (iconst.i8 -1) (value.i8 x)))
      (iconst.i8 -1)
      (spec (= (bvor -1 x) (result))))

(rule (simplify (or.i16 (iconst.i16 -1) (value.i16 x)))
      (iconst.i16 -1)
      (spec (= (bvor -1 x) (result))))

(rule (simplify (or.i32 (iconst.i32 -1) (value.i32 x)))
      (iconst.i32 -1)
      (spec (= (bvor -1 x) (result))))

(rule (simplify (or.i64 (iconst.i64 -1) (value.i64 x)))
      (iconst.i64 -1)
      (spec (= (bvor -1 x) (result))))

(rule (simplify (xor.i8 (value.i8 x) (iconst.i8 0)))
      (value.i8 x)
      (spec (= (bvxor x 0) (result))))

(rule (simplify (xor.i16 (value.i16 x) (iconst.i16 0)))
      (value.i16 x)
      (spec (= (bvxor x 0) (result))))

(rule (simplify (xor.i32 (value.i32 x) (iconst.i32 0)))
      (value.i32 x)
      (spec (= (bvxor x 0) (result))))

(rule (simplify (xor.i64 (value.i64 x) (iconst.i64 0)))
      (value.i64 x)
      (spec (= (bvxor x 0) (result))))

(rule (simplify (xor.i8 (iconst.i8 0) (value.i8 x)))
      (value.i8 x)
      (spec (= (bvxor 0 x) (result))))

(rule (simplify (xor.i16 (iconst.i16 0) (value.i16 x)))
      (value.i16 x)
      (spec (= (bvxor 0 x) (result))))

(rule (simplify (xor.i32 (iconst.i32 0) (value.i32 x)))
      (value.i32 x)
      (spec (= (bvxor 0 x) (result))))

(rule (simplify (xor.i64 (iconst.i64 0) (value.i64 x)))
      (value.i64 x)
      (spec (= (bvxor 0 x) (result))))


;; Shifting by nothing, in all three directions. The model masks a shift count to the width below
;; it, so a count of zero is a count of zero at every width and none of these depends on that.

(rule (simplify (shl.i8 (value.i8 x) (iconst.i8 0)))
      (value.i8 x)
      (spec (= (bvshl x 0) (result))))

(rule (simplify (shl.i16 (value.i16 x) (iconst.i16 0)))
      (value.i16 x)
      (spec (= (bvshl x 0) (result))))

(rule (simplify (shl.i32 (value.i32 x) (iconst.i32 0)))
      (value.i32 x)
      (spec (= (bvshl x 0) (result))))

(rule (simplify (shl.i64 (value.i64 x) (iconst.i64 0)))
      (value.i64 x)
      (spec (= (bvshl x 0) (result))))

(rule (simplify (lshr.i8 (value.i8 x) (iconst.i8 0)))
      (value.i8 x)
      (spec (= (bvlshr x 0) (result))))

(rule (simplify (lshr.i16 (value.i16 x) (iconst.i16 0)))
      (value.i16 x)
      (spec (= (bvlshr x 0) (result))))

(rule (simplify (lshr.i32 (value.i32 x) (iconst.i32 0)))
      (value.i32 x)
      (spec (= (bvlshr x 0) (result))))

(rule (simplify (lshr.i64 (value.i64 x) (iconst.i64 0)))
      (value.i64 x)
      (spec (= (bvlshr x 0) (result))))

(rule (simplify (ashr.i8 (value.i8 x) (iconst.i8 0)))
      (value.i8 x)
      (spec (= (bvashr x 0) (result))))

(rule (simplify (ashr.i16 (value.i16 x) (iconst.i16 0)))
      (value.i16 x)
      (spec (= (bvashr x 0) (result))))

(rule (simplify (ashr.i32 (value.i32 x) (iconst.i32 0)))
      (value.i32 x)
      (spec (= (bvashr x 0) (result))))

(rule (simplify (ashr.i64 (value.i64 x) (iconst.i64 0)))
      (value.i64 x)
      (spec (= (bvashr x 0) (result))))


;; The same three at one bit, which is the width a truth value comes in.
;;
;; A one bit `and` is a logical and, and the identities are the ones above read as truth rather
;; than as bits. They are written out because a comparison feeding another comparison is where
;; these come from and that shape is common, not because one bit is a special case: all ones at
;; this width is `1`, and it means every bit set exactly as `-1` does above.
;;
;; Nothing else has an entry here. There is no add and no shift at one bit, because there is no
;; instruction at one bit that leaves a zero or a one behind, and the IR has none for that
;; reason.

(rule (simplify (and.i1 (value.i1 x) (value.i1 x)))
      (value.i1 x)
      (spec (= (bvand x x) (result))))

(rule (simplify (or.i1 (value.i1 x) (value.i1 x)))
      (value.i1 x)
      (spec (= (bvor x x) (result))))

(rule (simplify (xor.i1 (value.i1 x) (value.i1 x)))
      (iconst.i1 0)
      (spec (= (bvxor x x) (result))))

(rule (simplify (and.i1 (value.i1 x) (iconst.i1 0)))
      (iconst.i1 0)
      (spec (= (bvand x 0) (result))))

(rule (simplify (and.i1 (iconst.i1 0) (value.i1 x)))
      (iconst.i1 0)
      (spec (= (bvand 0 x) (result))))

(rule (simplify (and.i1 (value.i1 x) (iconst.i1 1)))
      (value.i1 x)
      (spec (= (bvand x 1) (result))))

(rule (simplify (and.i1 (iconst.i1 1) (value.i1 x)))
      (value.i1 x)
      (spec (= (bvand 1 x) (result))))

(rule (simplify (or.i1 (value.i1 x) (iconst.i1 0)))
      (value.i1 x)
      (spec (= (bvor x 0) (result))))

(rule (simplify (or.i1 (iconst.i1 0) (value.i1 x)))
      (value.i1 x)
      (spec (= (bvor 0 x) (result))))

(rule (simplify (or.i1 (value.i1 x) (iconst.i1 1)))
      (iconst.i1 1)
      (spec (= (bvor x 1) (result))))

(rule (simplify (or.i1 (iconst.i1 1) (value.i1 x)))
      (iconst.i1 1)
      (spec (= (bvor 1 x) (result))))

(rule (simplify (xor.i1 (value.i1 x) (iconst.i1 0)))
      (value.i1 x)
      (spec (= (bvxor x 0) (result))))

(rule (simplify (xor.i1 (iconst.i1 0) (value.i1 x)))
      (value.i1 x)
      (spec (= (bvxor 0 x) (result))))