-
Notifications
You must be signed in to change notification settings - Fork 1
/
Infrules.v
1973 lines (1922 loc) · 100 KB
/
Infrules.v
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
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Require Import syntax.
Require Import alist.
Require Import FMapWeakList.
Require Import Coqlib.
Require Import infrastructure.
Require Import Metatheory.
Import LLVMsyntax.
Import LLVMinfra.
Require Import Integers.
Require Import Exprs.
Require Import Hints.
Require Import TODO.
Require Import Decs.
Require Import Debug.
Require Import String.
Set Implicit Arguments.
(* Copied from validator/basic_aux.v because ocaml-extracted version of this code cannot find validator/basic_aux.v *)
Fixpoint power_sz (s:sz) : positive :=
match s with
| O => xH
| S n => xO (power_sz n)
end.
(* Copied from validator/basic_aux.v because ocaml-extracted version of this code cannot find validator/basic_aux.v *)
Definition signbit_of (s:sz) : option Int :=
match s with
| O => None
| S n => Some (Zneg (power_sz n))
end.
Definition is_ghost (g:IdT.t) :=
match g with
| (tag, _) => if Tag.eq_dec tag Tag.ghost then true else false
end.
Definition get_bitsize (ty:typ) (m:module) : option sz :=
match ty with
| typ_int sz1 => Some sz1
| typ_pointer _ =>
(match m with
| module_intro ls _ _ =>
match (List.find
(fun h => match h with| layout_ptr _ _ _ => true | _ => false end) ls) with
| None => None
| Some (layout_ptr sz _ _) => Some sz
| Some _ => None
end
end)
| _ => None
end.
Definition cond_uint_fitinsize (s:sz) (c:INTEGER.t) : bool :=
Z.leb 0%Z (INTEGER.to_Z c) && Z.ltb (INTEGER.to_Z c) (Zpos (power_sz s)).
Definition cond_plus (s:sz) (c1 c2 c3: INTEGER.t) : bool :=
(Int.eq_dec _)
(Int.repr (Size.to_nat s - 1) (INTEGER.to_Z c3))
(Int.add (Size.to_nat s - 1)
(Int.repr (Size.to_nat s - 1) (INTEGER.to_Z c1))
(Int.repr (Size.to_nat s - 1) (INTEGER.to_Z c2))).
Definition cond_minus (s:sz) (c1 c2 c3: INTEGER.t) : bool :=
(Int.eq_dec (Size.to_nat s - 1))
(Int.repr (Size.to_nat s - 1) (INTEGER.to_Z c3))
(Int.sub (Size.to_nat s - 1)
(Int.repr (Size.to_nat s - 1) (INTEGER.to_Z c1))
(Int.repr (Size.to_nat s - 1) (INTEGER.to_Z c2))).
Definition cond_mul (s:sz) (c1 c2 c3: INTEGER.t) : bool :=
(Int.eq_dec _)
(Int.repr (Size.to_nat s - 1) (INTEGER.to_Z c3))
(Int.mul (Size.to_nat s - 1)
(Int.repr (Size.to_nat s - 1) (INTEGER.to_Z c1))
(Int.repr (Size.to_nat s - 1) (INTEGER.to_Z c2))).
Definition cond_or (s:sz) (c1 c2 c3: INTEGER.t) : bool :=
(Int.eq_dec _)
(Int.repr (Size.to_nat s - 1) (INTEGER.to_Z c3))
(Int.or (Size.to_nat s - 1)
(Int.repr (Size.to_nat s - 1) (INTEGER.to_Z c1))
(Int.repr (Size.to_nat s - 1) (INTEGER.to_Z c2))).
Definition cond_le (s:sz) (c1 c2: INTEGER.t) : bool :=
Z.leb (INTEGER.to_Z c1) (INTEGER.to_Z c2).
Definition cond_and (s:sz) (c1 c2 c3: INTEGER.t) : bool :=
(Int.eq_dec (Size.to_nat s - 1))
(Int.repr (Size.to_nat s - 1) (INTEGER.to_Z c3))
(Int.and (Size.to_nat s - 1)
(Int.repr (Size.to_nat s - 1) (INTEGER.to_Z c1))
(Int.repr (Size.to_nat s - 1) (INTEGER.to_Z c2))).
Definition cond_xor (s:sz) (c1 c2 c3: INTEGER.t) : bool :=
(Int.eq_dec (Size.to_nat s - 1))
(Int.repr (Size.to_nat s - 1) (INTEGER.to_Z c3))
(Int.xor (Size.to_nat s - 1)
(Int.repr (Size.to_nat s - 1) (INTEGER.to_Z c1))
(Int.repr (Size.to_nat s - 1) (INTEGER.to_Z c2))).
Definition cond_mask_up (s:sz) (c1i c2i:INTEGER.t) : bool :=
let ws := (Size.to_nat s - 1)%nat in
let c1 := (Int.repr ws (INTEGER.to_Z c1i)) in
let mc1 := (Int.sub ws (Int.zero ws) c1) in
let c2 := (Int.repr ws (INTEGER.to_Z c2i)) in
let c1up := (Int.not ws (Int.sub ws (Int.and ws c1 mc1) (Int.one ws))) in
(Int.eq_dec ws) (Int.and ws c1up c2) c1up.
(* cond_double_to_i64 : is (bitcast double d to i64 == i)? *)
Definition cond_double_to_i64 (d:const) (i:INTEGER.t) : bool :=
match d with
| const_floatpoint fpty f =>
match fpty with
| fp_double =>
true (* XXX : This should be fixed.. *)
| _ => false
end
| _ => false
end.
Definition cond_signbit (s:sz) (v:ValueT.t) : bool :=
match signbit_of s, v with
| None, _ => false
| Some n, ValueT.const (const_int s' n') =>
sz_dec s s' && INTEGER.dec n n'
| _, _ => false
end.
Definition cond_gep_zero (v':ValueT.t) (e:Expr.t) : bool :=
match e with
| Expr.gep inbound ty1 v idxlist ty2 =>
ValueT.eq_dec v v' &&
(List.forallb
(fun itm =>
match itm with
| (sz,idx) =>
match idx with
| (ValueT.const (const_int sz_i i)) =>
sz_dec sz sz_i &&
const_eqb (const_int sz_i i) (const_int sz_i (INTEGER.of_Z (Size.to_Z sz_i) 0%Z true))
| _ => false
end
end)
idxlist)
| Expr.value vl =>
match (vl, v') with
| (ValueT.const e, ValueT.const v') =>
match e with
| const_gep inbound v idxlist =>
const_eqb v v' &&
(List.forallb
(fun idx =>
match idx with
| (const_int sz_i i) =>
INTEGER.dec i (INTEGER.of_Z (Size.to_Z sz_i) 0%Z true)
| _ => false
end)
idxlist)
| _ => false
end
| _ => false
end
| _ => false
end.
Definition cond_bitcast_ptr (v':ValueT.t) (e:Expr.t) : bool :=
match e with
| Expr.cast eop fromty v toty =>
(match eop with
| castop_bitcast =>
(match fromty, toty with
| typ_pointer _, typ_pointer _ => ValueT.eq_dec v v'
| _, _ => false
end)
| _ => false
end)
| Expr.value vt =>
match (vt, v') with
| (ValueT.const e, ValueT.const v') =>
match e with
| const_castop eop v toty =>
(match eop with
| castop_bitcast =>
(match toty with
| typ_pointer _ => const_eqb v v'
| _ => false
end)
| _ => false
end)
| _ => false
end
| _ => false
end
| _ => false
end.
Definition cond_pointertyp (t:typ) : bool :=
match t with
| typ_pointer _ => true
| _ => false
end.
Definition cond_same_bitsize (ty1:typ) (ty2:typ) (m_src:module) : bool :=
match (ty1, ty2) with
| (typ_int sz1, typ_int sz2) => sz_dec sz1 sz2
| (typ_int sz1, typ_pointer _) =>
sz_dec sz1
(match m_src with
| module_intro ls _ _ =>
match (List.find
(fun h => match h with| layout_ptr _ _ _ => true | _ => false end) ls) with
| None => Size.from_Z 0%Z
| Some (layout_ptr sz _ _) => sz
| Some _ => Size.from_Z 0%Z
end
end)
| _ => false
end.
(* NOTE : pointer type in Vellvm does not remember address space *)
Definition cond_sameaddrspace (t1:typ) (t2:typ) : bool :=
match (t1,t2) with
| (typ_pointer _, typ_pointer _) => true
| _ => false
end.
(* NOTE : Vellvm does not support vector type *)
Definition cond_vectortyp (t:typ) : bool :=
false.
Definition cond_inttyp (t:typ): bool :=
match t with
| typ_int _ => true
| _ => false
end.
Definition cond_floatpointtyp (t:typ) : bool :=
match t with
| typ_floatpoint _ => true
| _ => false
end.
Definition cond_onebit (s:sz) : bool :=
sz_dec s (Size.One).
Definition cond_neg (s:sz) (c1 c2:INTEGER.t) : bool :=
cond_plus s c1 c2 (INTEGER.of_Z (Size.to_Z s) (-1)%Z true).
Definition const_newint (s:sz) (i:INTEGER.t) : const :=
(const_int s (INTEGER.of_Z (Size.to_Z s) (INTEGER.to_Z i) true)).
Definition const_mone (s:sz) : const :=
(const_int s (INTEGER.of_Z (Size.to_Z s) (-1)%Z true)).
Definition const_zero (s:sz) : const :=
(const_int s (INTEGER.of_Z (Size.to_Z s) (0)%Z true)).
(* getInversePredicate in lib/IR/Instructions.cpp *)
Definition get_inverse_icmp_cond (c:cond) : cond :=
match c with
| cond_eq => cond_ne
| cond_ne => cond_eq
| cond_ugt => cond_ule
| cond_uge => cond_ult
| cond_ult => cond_uge
| cond_ule => cond_ugt
| cond_sgt => cond_sle
| cond_sge => cond_slt
| cond_slt => cond_sge
| cond_sle => cond_sgt
end.
Definition get_inverse_boolean_Int (b:INTEGER.t) : INTEGER.t :=
if (Z.eq_dec (INTEGER.to_Z b) 0)
then INTEGER.of_Z 1 1 true
else INTEGER.of_Z 1 0 true.
(* getSwappedPredicate in lib/IR/Instructions.cpp *)
Definition get_swapped_icmp_cond (c:cond) : cond :=
match c with
| cond_eq => cond_eq
| cond_ne => cond_ne
| cond_ugt => cond_ult
| cond_uge => cond_ule
| cond_ult => cond_ugt
| cond_ule => cond_uge
| cond_sgt => cond_slt
| cond_sge => cond_sle
| cond_slt => cond_sgt
| cond_sle => cond_sge
end.
Definition get_swapped_fcmp_cond (c:fcond) : fcond :=
match c with
| fcond_false => fcond_false
| fcond_oeq => fcond_oeq
| fcond_ogt => fcond_olt
| fcond_oge => fcond_ole
| fcond_olt => fcond_ogt
| fcond_ole => fcond_oge
| fcond_one => fcond_one
| fcond_ord => fcond_ord
| fcond_ueq => fcond_ueq
| fcond_ugt => fcond_ult
| fcond_uge => fcond_ule
| fcond_ult => fcond_ugt
| fcond_ule => fcond_uge
| fcond_une => fcond_une
| fcond_uno => fcond_uno
| fcond_true => fcond_true
end.
Definition is_commutative_bop (opcode:bop) :=
match opcode with
| bop_add | bop_mul | bop_and | bop_or | bop_xor => true
| _ => false
end.
Definition is_commutative_fbop (opcode:fbop) :=
match opcode with
| fbop_fadd | fbop_fmul => true
| _ => false
end.
Definition load_realign (e1: Expr.t): Expr.t :=
match e1 with
| Expr.load v ty a => Expr.load v ty Align.One
| _ => e1
end
.
Notation "$$ inv |-src y >= rhs $$" := (Assertion.lessdef_expr (y, rhs) inv.(Assertion.src).(Assertion.lessdef)) (at level 41, inv, y, rhs at level 41).
Notation "$$ inv |-tgt y >= rhs $$" := (Assertion.lessdef_expr (y, rhs) inv.(Assertion.tgt).(Assertion.lessdef)) (at level 41, inv, y, rhs at level 41).
Notation "$$ inv |-src y 'unique' $$" :=
((Tag.eq_dec (fst y) Tag.physical) &&
(AtomSetImpl.mem (snd y) inv.(Assertion.src).(Assertion.unique))) (at level 41, inv, y at level 41).
Notation "$$ inv |-tgt y 'unique' $$" :=
((Tag.eq_dec (fst y) Tag.physical) &&
(AtomSetImpl.mem (snd y) inv.(Assertion.tgt).(Assertion.unique))) (at level 41, inv, y at level 41).
Notation "$$ inv |-src x _|_ y $$" := ((PtrPairSet.mem (x, y) inv.(Assertion.src).(Assertion.alias).(Assertion.noalias)) || (PtrPairSet.mem (y, x) inv.(Assertion.src).(Assertion.alias).(Assertion.noalias))) (at level 41, inv, x, y at level 41).
Notation "$$ inv |-tgt x _|_ y $$" := ((PtrPairSet.mem (x, y) inv.(Assertion.tgt).(Assertion.alias).(Assertion.noalias)) || (PtrPairSet.mem (y, x) inv.(Assertion.tgt).(Assertion.alias).(Assertion.noalias))) (at level 41, inv, x, y at level 41).
Notation "$$ inv |-src x _||_ y $$" := ((ValueTPairSet.mem (x, y) inv.(Assertion.src).(Assertion.alias).(Assertion.diffblock)) || (ValueTPairSet.mem (y, x) inv.(Assertion.src).(Assertion.alias).(Assertion.diffblock))) (at level 41, inv, x, y at level 41).
Notation "$$ inv |-tgt x _||_ y $$" := ((ValueTPairSet.mem (x, y) inv.(Assertion.tgt).(Assertion.alias).(Assertion.diffblock)) || (ValueTPairSet.mem (y, x) inv.(Assertion.tgt).(Assertion.alias).(Assertion.diffblock))) (at level 41, inv, x, y at level 41).
Notation "{{ inv +++src y >= rhs }}" := (Assertion.update_src (Assertion.update_lessdef (ExprPairSet.add (y, rhs))) inv) (at level 41, inv, y, rhs at level 41).
Notation "{{ inv +++tgt y >= rhs }}" := (Assertion.update_tgt (Assertion.update_lessdef (ExprPairSet.add (y, rhs))) inv) (at level 41, inv, y, rhs at level 41).
Notation "{{ inv +++src y _|_ x }}" := (Assertion.update_src (Assertion.update_noalias (PtrPairSet.add (y, x))) inv) (at level 41, inv, y, x at level 41).
Notation "{{ inv +++tgt y _|_ x }}" := (Assertion.update_tgt (Assertion.update_noalias (PtrPairSet.add (y, x))) inv) (at level 41, inv, y, x at level 41).
Notation "{{ inv +++src y _||_ x }}" := (Assertion.update_src (Assertion.update_diffblock (ValueTPairSet.add (y, x))) inv) (at level 41, inv, y, x at level 41).
Notation "{{ inv +++tgt y _||_ x }}" := (Assertion.update_tgt (Assertion.update_diffblock (ValueTPairSet.add (y, x))) inv) (at level 41, inv, y, x at level 41).
Notation "{{ inv --- x }}" := (Assertion.update_maydiff (IdTSet.filter (fun y => negb (IdT.eq_dec x y))) inv) (at level 41, inv, x at level 41).
Definition load_align_one (e1: Expr.t): Expr.t :=
match e1 with
| Expr.load v ty a => Expr.load v ty Align.One
| _ => e1
end
.
Definition reduce_maydiff_preserved (used_ids: list IdT.t) :=
(fun idt => (Tag.eq_dec (fst idt) Tag.physical) || (List.find (IdT.eq_dec idt) used_ids)).
(* Non-physical that is only in maydiff is safe to remove *)
Definition reduce_maydiff_non_physical (inv0: Assertion.t): Assertion.t :=
let used_ids := (Assertion.get_idTs_unary inv0.(Assertion.src))
++ (Assertion.get_idTs_unary inv0.(Assertion.tgt))
in
Assertion.update_maydiff (IdTSet.filter (reduce_maydiff_preserved used_ids)) inv0.
Definition reduce_maydiff_lessdef (inv0:Assertion.t): Assertion.t :=
let lessdef_src := inv0.(Assertion.src).(Assertion.lessdef) in
let lessdef_tgt := inv0.(Assertion.tgt).(Assertion.lessdef) in
Assertion.update_maydiff
(IdTSet.filter
(fun id =>
negb (ExprPairSet.exists_
(fun p => ExprPairSet.exists_
(fun q => Assertion.inject_expr inv0 (snd p) (fst q))
(Assertion.get_lhs lessdef_tgt (fst p)))
(Assertion.get_rhs lessdef_src
(Expr.value (ValueT.id id)))))) inv0.
(* Definition reduce_maydiff_old_fun (inv0:Assertion.t): Assertion.t := *)
(* let inv1 := reduce_maydiff_non_physical_old inv0 in *)
(* reduce_maydiff_lessdef_old inv1. *)
Definition exclusive_bool (c1 c2:const) : bool :=
match c1, c2 with
| const_int sz1 i1, const_int sz2 i2 =>
Size.dec sz1 Size.One && Size.dec sz2 Size.One &&
match INTEGER.to_Z i1, INTEGER.to_Z i2 with
| 0, -1 => true
| -1, 0 => true
| _, _ => false
end
| _, _ => false
end.
Definition apply_infrule
(m_src m_tgt:module)
(infrule:Infrule.t)
(inv0:Assertion.t): Assertion.t :=
let apply_fail := (fun _: unit => (debug_print2 infrule_printer infrule
(debug_string "Infrule application failed!" inv0))) in
let no_match_fail := (fun _: unit => debug_string "Infrule match failed!"
(debug_print2 infrule_printer infrule inv0)) in
match infrule with
| Infrule.add_const_not z y x c1 c2 s =>
if $$ inv0 |-src (Expr.value (ValueT.id y)) >= (Expr.bop bop_xor s x (ValueT.const (const_int s (INTEGER.of_Z (Size.to_Z s) (-1)%Z true)))) $$ &&
$$ inv0 |-src (Expr.value (ValueT.id z)) >= (Expr.bop bop_add s (ValueT.id y) (ValueT.const (const_int s c1))) $$ &&
cond_minus s c1 (INTEGER.of_Z (Size.to_Z s) 1%Z true) c2
then {{inv0 +++src (Expr.value (ValueT.id z)) >= (Expr.bop bop_sub s (ValueT.const (const_int s c2)) x)}}
else apply_fail tt
| Infrule.add_dist_sub z minusx minusy w x y s =>
if $$ inv0 |-tgt (Expr.value (ValueT.id minusx))
>= (Expr.bop bop_sub s (ValueT.const (const_int s (INTEGER.of_Z (Size.to_Z s) 0%Z true))) x) $$
&& $$ inv0 |-tgt (Expr.value minusy)
>= (Expr.bop bop_sub s (ValueT.const (const_int s (INTEGER.of_Z (Size.to_Z s) 0%Z true))) y) $$
&& $$ inv0 |-tgt (Expr.bop bop_add s x y)
>= (Expr.value (ValueT.id w)) $$
&& $$ inv0 |-tgt (Expr.bop bop_sub s (ValueT.const (const_int s (INTEGER.of_Z (Size.to_Z s) 0%Z true))) (ValueT.id w))
>= (Expr.value (ValueT.id z)) $$
then {{inv0 +++tgt (Expr.bop bop_add s (ValueT.id minusx) minusy) >= (Expr.value (ValueT.id z))}}
else apply_fail tt
| Infrule.add_onebit z x y =>
if $$ inv0 |-src (Expr.value (ValueT.id z)) >= (Expr.bop bop_add Size.One x y) $$
then {{inv0 +++src (Expr.value (ValueT.id z)) >= (Expr.bop bop_xor Size.One x y)}}
else apply_fail tt
| Infrule.add_sub z minusy x y s =>
if $$ inv0 |-src (Expr.value minusy) >= (Expr.bop bop_sub s (const_int s (INTEGER.of_Z (Size.to_Z s) 0%Z true)) y) $$ &&
$$ inv0 |-src (Expr.value z) >= (Expr.bop bop_add s x minusy) $$
then {{inv0 +++src (Expr.value z) >= (Expr.bop bop_sub s x y)}}
else apply_fail tt
| Infrule.add_commutative_tgt z x y s =>
if $$ inv0 |-tgt (Expr.bop bop_add s x y) >= (Expr.value z) $$
then {{inv0 +++tgt (Expr.bop bop_add s y x) >= (Expr.value z) }}
else apply_fail tt
| Infrule.add_mask z y y' x c1 c2 s =>
if $$ inv0 |-tgt (Expr.bop bop_and s x (ValueT.const (const_int s c2))) >= (Expr.value (ValueT.id y)) $$ &&
$$ inv0 |-tgt (Expr.bop bop_add s x (ValueT.const (const_int s c1))) >= (Expr.value (ValueT.id y')) $$ &&
$$ inv0 |-tgt (Expr.bop bop_and s (ValueT.id y') (ValueT.const (const_int s c2))) >= (Expr.value (ValueT.id z)) $$ &&
cond_mask_up s c1 c2
then {{inv0 +++tgt (Expr.bop bop_add s (ValueT.id y) (ValueT.const (const_int s c1))) >= (Expr.value (ValueT.id z)) }}
else apply_fail tt
| Infrule.add_or_and z a b x y s =>
if $$ inv0 |-src (Expr.value (ValueT.id x)) >= (Expr.bop bop_or s a b) $$ &&
$$ inv0 |-src (Expr.value (ValueT.id y)) >= (Expr.bop bop_and s a b) $$ &&
$$ inv0 |-src (Expr.value (ValueT.id z)) >= (Expr.bop bop_add s (ValueT.id x) (ValueT.id y)) $$
then {{inv0 +++src (Expr.value (ValueT.id z)) >= (Expr.bop bop_add s a b)}}
else apply_fail tt
| Infrule.add_select_zero z x y c n a s =>
if $$ inv0 |-src (Expr.value (ValueT.id x)) >= (Expr.bop bop_sub s n a) $$ &&
$$ inv0 |-src (Expr.value (ValueT.id y)) >= (Expr.select c (typ_int s) (ValueT.id x) (ValueT.const (const_int s (INTEGER.of_Z (Size.to_Z s) 0%Z true)))) $$ &&
$$ inv0 |-src (Expr.value (ValueT.id z)) >= (Expr.bop bop_add s (ValueT.id y) a) $$
then {{inv0 +++src (Expr.value (ValueT.id z)) >= (Expr.select c (typ_int s) n a) }}
else apply_fail tt
| Infrule.add_select_zero2 z x y c n a s =>
if $$ inv0 |-src (Expr.value (ValueT.id x)) >= (Expr.bop bop_sub s n a) $$ &&
$$ inv0 |-src (Expr.value (ValueT.id y)) >= (Expr.select c (typ_int s) (ValueT.const (const_int s (INTEGER.of_Z (Size.to_Z s) 0%Z true))) (ValueT.id x)) $$ &&
$$ inv0 |-src (Expr.value (ValueT.id z)) >= (Expr.bop bop_add s (ValueT.id y) a) $$
then {{inv0 +++src (Expr.value (ValueT.id z)) >= (Expr.select c (typ_int s) a n) }}
else apply_fail tt
| Infrule.add_shift y v s =>
if $$ inv0 |-src (Expr.value y) >= (Expr.bop bop_add s v v) $$
then {{inv0 +++src (Expr.value y) >= (Expr.bop bop_shl s v (const_int s (INTEGER.of_Z (Size.to_Z s) 1%Z true)))}}
else apply_fail tt
| Infrule.add_signbit x e1 e2 s =>
if $$ inv0 |-src (Expr.value x) >= (Expr.bop bop_add s e1 e2) $$ &&
cond_signbit s e2
then {{inv0 +++src (Expr.value x) >= (Expr.bop bop_xor s e1 e2)}}
else apply_fail tt
| Infrule.add_xor_and z a b x y s =>
if $$ inv0 |-src (Expr.value (ValueT.id x)) >= (Expr.bop bop_xor s a b) $$ &&
$$ inv0 |-src (Expr.value (ValueT.id y)) >= (Expr.bop bop_and s a b) $$ &&
$$ inv0 |-src (Expr.value (ValueT.id z)) >= (Expr.bop bop_add s (ValueT.id x) (ValueT.id y)) $$
then {{inv0 +++src (Expr.value (ValueT.id z)) >= (Expr.bop bop_or s a b)}}
else apply_fail tt
| Infrule.add_zext_bool x y b c c' sz =>
if $$ inv0 |-src (Expr.value (ValueT.id x)) >= (Expr.ext extop_z (typ_int Size.One) b (typ_int sz)) $$ &&
$$ inv0 |-src (Expr.value (ValueT.id y)) >= (Expr.bop bop_add sz (ValueT.id x) (ValueT.const (const_int sz c))) $$ &&
cond_plus sz c (INTEGER.of_Z (Size.to_Z sz) 1%Z true) c'
then {{ inv0 +++src (Expr.value (ValueT.id y)) >= (Expr.select b (typ_int sz) (ValueT.const (const_int sz c')) (ValueT.const (const_int sz c))) }}
else apply_fail tt
| Infrule.and_de_morgan z x y z' a b s =>
if $$ inv0 |-tgt (Expr.bop bop_xor s a (ValueT.const (const_int s (INTEGER.of_Z (Size.to_Z s) (-1)%Z true)))) >= (Expr.value (ValueT.id x)) $$ &&
$$ inv0 |-tgt (Expr.bop bop_xor s b (ValueT.const (const_int s (INTEGER.of_Z (Size.to_Z s) (-1)%Z true)))) >= (Expr.value (ValueT.id y))$$ &&
$$ inv0 |-tgt (Expr.bop bop_or s a b) >= (Expr.value (ValueT.id z')) $$ &&
$$ inv0 |-tgt (Expr.bop bop_xor s (ValueT.id z') (ValueT.const (const_int s (INTEGER.of_Z (Size.to_Z s) (-1)%Z true)))) >= (Expr.value (ValueT.id z)) $$
then {{inv0 +++tgt (Expr.bop bop_and s (ValueT.id x) (ValueT.id y)) >= (Expr.value (ValueT.id z))}}
else apply_fail tt
| Infrule.and_mone z x s =>
if $$ inv0 |-src (Expr.value z) >= (Expr.bop bop_and s x (ValueT.const (const_int s (INTEGER.of_Z (Size.to_Z s) (-1)%Z true)))) $$
then {{inv0 +++src (Expr.value z) >= (Expr.value x) }}
else apply_fail tt
| Infrule.and_not z x y s =>
if $$ inv0 |-src (Expr.value z) >= (Expr.bop bop_and s x y) $$ &&
$$ inv0 |-src (Expr.value y) >= (Expr.bop bop_xor s x (ValueT.const (const_int s (INTEGER.of_Z (Size.to_Z s) (-1)%Z true)))) $$
then {{inv0 +++src (Expr.value z) >= (Expr.value (ValueT.const (const_int s (INTEGER.of_Z (Size.to_Z s) 0%Z true)))) }}
else apply_fail tt
| Infrule.and_or z x y a s =>
if $$ inv0 |-src (Expr.value z) >= (Expr.bop bop_and s x y) $$ &&
$$ inv0 |-src (Expr.value y) >= (Expr.bop bop_or s x a) $$
then {{inv0 +++src (Expr.value z) >= (Expr.value x) }}
else apply_fail tt
| Infrule.and_or_const2 z y y' x c1 c2 c3 s =>
if $$ inv0 |-tgt (Expr.bop bop_or s x (const_int s c1)) >= (Expr.value (ValueT.id y')) $$ &&
$$ inv0 |-tgt (Expr.bop bop_and s x (const_int s c3)) >= (Expr.value (ValueT.id y)) $$ &&
$$ inv0 |-tgt (Expr.bop bop_or s y (const_int s c1)) >= (Expr.value (ValueT.id z)) $$ &&
cond_xor s c1 c2 c3 && cond_and s c1 c2 c1
then {{inv0 +++tgt (Expr.bop bop_and s y' (const_int s c2)) >= (Expr.value (ValueT.id z)) }}
else apply_fail tt
| Infrule.and_same z x s =>
if $$ inv0 |-src (Expr.value z) >= (Expr.bop bop_and s x x) $$
then {{inv0 +++src (Expr.value z) >= (Expr.value x)}}
else apply_fail tt
| Infrule.and_true_bool x y =>
let true_expr := Expr.value (ValueT.const (const_int Size.One (INTEGER.of_Z (Size.to_Z Size.One) (-1)%Z true))) in
if $$ inv0 |-src true_expr >= (Expr.bop bop_and Size.One x y) $$
then {{
{{
{{
{{inv0 +++src true_expr >= (Expr.value x)}}
+++src (Expr.value x) >= true_expr
}}
+++src true_expr >= (Expr.value y)
}}
+++src (Expr.value y) >= true_expr
}}
else apply_fail tt
| Infrule.and_true_bool_tgt x y =>
let true_expr := Expr.value (ValueT.const (const_int Size.One (INTEGER.of_Z (Size.to_Z Size.One) (-1)%Z true))) in
if $$ inv0 |-tgt true_expr >= (Expr.bop bop_and Size.One x y) $$
then {{
{{
{{
{{inv0 +++tgt true_expr >= (Expr.value x)}}
+++tgt (Expr.value x) >= true_expr
}}
+++tgt true_expr >= (Expr.value y)
}}
+++tgt (Expr.value y) >= true_expr
}}
else apply_fail tt
| Infrule.and_undef z x s =>
if $$ inv0 |-src (Expr.value z) >= (Expr.bop bop_and s x (ValueT.const (const_undef (typ_int s)))) $$
then {{ inv0 +++src (Expr.value z) >= (Expr.value
(ValueT.const (const_int s (INTEGER.of_Z (Size.to_Z s) (0)%Z true)))) }}
else apply_fail tt
| Infrule.and_xor_const z y y' x c1 c2 c3 s =>
if $$ inv0 |-tgt (Expr.bop bop_xor s x (const_int s c1)) >= (Expr.value (ValueT.id y')) $$ &&
$$ inv0 |-tgt (Expr.bop bop_and s x (const_int s c2)) >= (Expr.value (ValueT.id y)) $$ &&
$$ inv0 |-tgt (Expr.bop bop_xor s y (const_int s c3)) >= (Expr.value (ValueT.id z)) $$ &&
cond_and s c1 c2 c3
then {{inv0 +++tgt (Expr.bop bop_and s y' (const_int s c2)) >= (Expr.value (ValueT.id z)) }}
else apply_fail tt
| Infrule.and_zero z x s =>
if $$ inv0 |-src (Expr.value z) >= (Expr.bop bop_and s x (ValueT.const (const_int s (INTEGER.of_Z (Size.to_Z s) 0%Z true)))) $$
then {{ inv0 +++src (Expr.value z) >= (Expr.value (ValueT.const (const_int s (INTEGER.of_Z (Size.to_Z s) 0%Z true)))) }}
else apply_fail tt
| Infrule.and_or_not1 z x y a b s =>
if $$ inv0 |-tgt (Expr.bop bop_xor s b (ValueT.const (const_int s (INTEGER.of_Z (Size.to_Z s) (-1)%Z true)))) >= (Expr.value (ValueT.id x)) $$ &&
$$ inv0 |-tgt (Expr.bop bop_or s (ValueT.id x) a) >= (Expr.value (ValueT.id y)) $$ &&
$$ inv0 |-tgt (Expr.bop bop_and s a b) >= (Expr.value (ValueT.id z)) $$
then {{ inv0 +++tgt (Expr.bop bop_and s y b) >= (Expr.value (ValueT.id z)) }}
else apply_fail tt
| Infrule.bitcast_bitcast src mid dst srcty midty dstty =>
if $$ inv0 |-src (Expr.value mid) >= (Expr.cast castop_bitcast srcty src midty) $$ &&
$$ inv0 |-src (Expr.value dst) >= (Expr.cast castop_bitcast midty mid dstty) $$
then {{ inv0 +++src (Expr.value dst) >= (Expr.cast castop_bitcast srcty src dstty) }}
else apply_fail tt
| Infrule.bitcast_bitcast_rev_tgt src mid dst srcty midty dstty =>
if $$ inv0 |-tgt (Expr.cast castop_bitcast srcty src midty) >= (Expr.value mid) $$ &&
$$ inv0 |-tgt (Expr.cast castop_bitcast midty mid dstty) >= (Expr.value dst) $$
then {{ inv0 +++tgt (Expr.cast castop_bitcast srcty src dstty) >= (Expr.value dst) }}
else apply_fail tt
| Infrule.bitcast_double_i64 src tgt =>
let s := Size.from_Z 64%Z in
if cond_double_to_i64 src tgt
then {{ inv0 +++tgt (Expr.cast castop_bitcast
(typ_floatpoint fp_double)
(ValueT.const src)
(typ_int s))
>=
(Expr.value (ValueT.const (const_int s tgt))) }}
else apply_fail tt
| Infrule.bitcast_load ptr ty v1 ty2 v2 a =>
if $$ inv0 |-src (Expr.load ptr ty a) >= (Expr.value v1) $$ &&
$$ inv0 |-src (Expr.cast castop_bitcast ty v1 ty2) >= (Expr.value v2) $$
then {{inv0 +++src (Expr.load ptr ty2 a) >= (Expr.value v2)}}
else apply_fail tt
| Infrule.bitcast_inttoptr src mid dst srcty midty dstty =>
if $$ inv0 |-src (Expr.value mid) >= (Expr.cast castop_inttoptr srcty src midty) $$ &&
$$ inv0 |-src (Expr.value dst) >= (Expr.cast castop_bitcast midty mid dstty) $$
then {{ inv0 +++src (Expr.value dst) >= (Expr.cast castop_inttoptr srcty src dstty) }}
else apply_fail tt
| Infrule.bop_distributive_over_selectinst opcode r s t' t x y z c bopsz selty =>
if $$ inv0 |-tgt (Expr.bop opcode bopsz x y) >= (Expr.value (ValueT.id r)) $$ &&
$$ inv0 |-tgt (Expr.bop opcode bopsz x z) >= (Expr.value (ValueT.id s)) $$ &&
$$ inv0 |-tgt (Expr.select c (typ_int bopsz) y z) >= (Expr.value (ValueT.id t')) $$ &&
$$ inv0 |-tgt (Expr.bop opcode bopsz x t') >= (Expr.value (ValueT.id t)) $$
then {{ inv0 +++tgt (Expr.select c (typ_int bopsz) (ValueT.id r) (ValueT.id s)) >= (Expr.value (ValueT.id t)) }}
else apply_fail tt
| Infrule.bop_distributive_over_selectinst2 opcode r s t' t x y z c bopsz selty =>
if $$ inv0 |-tgt (Expr.bop opcode bopsz y x) >= (Expr.value (ValueT.id r)) $$ &&
$$ inv0 |-tgt (Expr.bop opcode bopsz z x) >= (Expr.value (ValueT.id s)) $$ &&
$$ inv0 |-tgt (Expr.select c (typ_int bopsz) y z) >= (Expr.value (ValueT.id t')) $$ &&
$$ inv0 |-tgt (Expr.bop opcode bopsz t' x) >= (Expr.value (ValueT.id t)) $$
then {{ inv0 +++tgt (Expr.select c (typ_int bopsz) (ValueT.id r) (ValueT.id s)) >= (Expr.value (ValueT.id t)) }}
else apply_fail tt
| Infrule.sdiv_mone z x s =>
if $$ inv0 |-src (Expr.value z) >= (Expr.bop bop_sdiv s x (ValueT.const (const_int s (INTEGER.of_Z (Size.to_Z s) (-1)%Z true)))) $$
then {{inv0 +++src (Expr.value (ValueT.id z)) >= (Expr.bop bop_sub s (ValueT.const (const_int s (INTEGER.of_Z (Size.to_Z s) 0%Z true))) x) }}
else apply_fail tt
| Infrule.bitcastptr v' bitcastinst =>
if cond_bitcast_ptr v' bitcastinst
then
let inv0 := {{inv0 +++src bitcastinst >= (Expr.value v')}} in
{{inv0 +++src (Expr.value v') >= bitcastinst}}
else apply_fail tt
| Infrule.bitcast_fpext src mid dst srcty midty dstty =>
if $$ inv0 |-src (Expr.value mid) >= (Expr.ext extop_fp srcty src midty) $$ &&
$$ inv0 |-src (Expr.value dst) >= (Expr.cast castop_bitcast midty mid dstty) $$ &&
cond_floatpointtyp dstty
then {{ inv0 +++src (Expr.value dst) >= (Expr.ext extop_fp srcty src dstty) }}
else apply_fail tt
| Infrule.bitcast_fptosi src mid dst srcty midty dstty =>
if $$ inv0 |-src (Expr.value mid) >= (Expr.cast castop_fptosi srcty src midty) $$ &&
$$ inv0 |-src (Expr.value dst) >= (Expr.cast castop_bitcast midty mid dstty) $$ &&
negb (cond_vectortyp srcty) && cond_inttyp dstty
then {{ inv0 +++src (Expr.value dst) >= (Expr.cast castop_fptosi srcty src dstty) }}
else apply_fail tt
| Infrule.bitcast_fptoui src mid dst srcty midty dstty =>
if $$ inv0 |-src (Expr.value mid) >= (Expr.cast castop_fptoui srcty src midty) $$ &&
$$ inv0 |-src (Expr.value dst) >= (Expr.cast castop_bitcast midty mid dstty) $$ &&
negb (cond_vectortyp srcty) && cond_inttyp dstty
then {{ inv0 +++src (Expr.value dst) >= (Expr.cast castop_fptoui srcty src dstty) }}
else apply_fail tt
| Infrule.bitcast_fptrunc src mid dst srcty midty dstty =>
if $$ inv0 |-src (Expr.value mid) >= (Expr.trunc truncop_fp srcty src midty) $$ &&
$$ inv0 |-src (Expr.value dst) >= (Expr.cast castop_bitcast midty mid dstty) $$ &&
cond_floatpointtyp dstty
then {{ inv0 +++src (Expr.value dst) >= (Expr.trunc truncop_fp srcty src dstty) }}
else apply_fail tt
| Infrule.bitcast_ptrtoint src mid dst srcty midty dstty =>
if $$ inv0 |-src (Expr.value mid) >= (Expr.cast castop_ptrtoint srcty src midty) $$ &&
$$ inv0 |-src (Expr.value dst) >= (Expr.cast castop_bitcast midty mid dstty) $$ &&
negb(cond_vectortyp srcty) && cond_inttyp dstty
then {{ inv0 +++src (Expr.value dst) >= (Expr.cast castop_ptrtoint srcty src dstty) }}
else apply_fail tt
| Infrule.bitcast_sext src mid dst srcty midty dstty =>
if $$ inv0 |-src (Expr.value mid) >= (Expr.ext extop_s srcty src midty) $$ &&
$$ inv0 |-src (Expr.value dst) >= (Expr.cast castop_bitcast midty mid dstty) $$ &&
negb(cond_vectortyp srcty) && cond_inttyp dstty
then {{ inv0 +++src (Expr.value dst) >= (Expr.ext extop_s srcty src dstty) }}
else apply_fail tt
| Infrule.bitcast_sametype src dst tty =>
if $$ inv0 |-src (Expr.value dst) >= (Expr.cast castop_bitcast tty src tty) $$
then {{ inv0 +++src (Expr.value dst) >= (Expr.value src) }}
else apply_fail tt
| Infrule.bitcast_sitofp src mid dst srcty midty dstty =>
if $$ inv0 |-src (Expr.value mid) >= (Expr.cast castop_sitofp srcty src midty) $$ &&
$$ inv0 |-src (Expr.value dst) >= (Expr.cast castop_bitcast midty mid dstty) $$ &&
cond_floatpointtyp dstty
then {{ inv0 +++src (Expr.value dst) >= (Expr.cast castop_sitofp srcty src dstty) }}
else apply_fail tt
| Infrule.bitcast_trunc src mid dst srcty midty dstty =>
if $$ inv0 |-src (Expr.value mid) >= (Expr.trunc truncop_int srcty src midty) $$ &&
$$ inv0 |-src (Expr.value dst) >= (Expr.cast castop_bitcast midty mid dstty) $$ &&
negb(cond_vectortyp srcty) && cond_inttyp dstty
then {{ inv0 +++src (Expr.value dst) >= (Expr.trunc truncop_int srcty src dstty) }}
else apply_fail tt
| Infrule.bitcast_uitofp src mid dst srcty midty dstty =>
if $$ inv0 |-src (Expr.value mid) >= (Expr.cast castop_uitofp srcty src midty) $$ &&
$$ inv0 |-src (Expr.value dst) >= (Expr.cast castop_bitcast midty mid dstty) $$ &&
cond_floatpointtyp dstty
then {{ inv0 +++src (Expr.value dst) >= (Expr.cast castop_uitofp srcty src dstty) }}
else apply_fail tt
| Infrule.bitcast_zext src mid dst srcty midty dstty =>
if $$ inv0 |-src (Expr.value mid) >= (Expr.ext extop_z srcty src midty) $$ &&
$$ inv0 |-src (Expr.value dst) >= (Expr.cast castop_bitcast midty mid dstty) $$ &&
negb(cond_vectortyp srcty) && cond_inttyp dstty
then {{ inv0 +++src (Expr.value dst) >= (Expr.ext extop_z srcty src dstty) }}
else apply_fail tt
| Infrule.bop_associative x y z opcode c1 c2 c3 s =>
if $$ inv0 |-src (Expr.value y) >= (Expr.bop opcode s x (const_int s c1)) $$ &&
$$ inv0 |-src (Expr.value z) >= (Expr.bop opcode s y (const_int s c2)) $$
then
(* There are 5 cases (see Instruction::isAssociative(unsigned).) *)
let cond_func_result :=
match opcode with
| bop_and => cond_and s c1 c2 c3
| bop_or => cond_or s c1 c2 c3
| bop_xor => cond_xor s c1 c2 c3
| bop_add => cond_plus s c1 c2 c3
| bop_mul => cond_mul s c1 c2 c3
| _ => false (* The bop is not associative.. *)
end
in
if cond_func_result
then
{{inv0 +++src (Expr.value z) >= (Expr.bop opcode s x (const_int s c3))}}
else apply_fail tt
else apply_fail tt
| Infrule.bop_commutative e opcode x y s =>
if $$ inv0 |-src e >= (Expr.bop opcode s x y) $$ &&
(is_commutative_bop opcode)
then {{ inv0 +++src e >= (Expr.bop opcode s y x) }}
else apply_fail tt
| Infrule.bop_commutative_rev e opcode x y s =>
if $$ inv0 |-src (Expr.bop opcode s x y) >= e $$ &&
(is_commutative_bop opcode)
then {{ inv0 +++src (Expr.bop opcode s y x) >= e }}
else apply_fail tt
| Infrule.bop_commutative_tgt e opcode x y s =>
if $$ inv0 |-tgt e >= (Expr.bop opcode s x y) $$ &&
(is_commutative_bop opcode)
then {{ inv0 +++tgt e >= (Expr.bop opcode s y x) }}
else apply_fail tt
| Infrule.bop_commutative_rev_tgt e opcode x y s =>
if $$ inv0 |-tgt (Expr.bop opcode s x y) >= e $$ &&
(is_commutative_bop opcode)
then {{ inv0 +++tgt (Expr.bop opcode s y x) >= e }}
else apply_fail tt
| Infrule.fbop_commutative e opcode x y fty =>
if $$ inv0 |-src e >= (Expr.fbop opcode fty x y) $$ &&
(is_commutative_fbop opcode)
then {{ inv0 +++src e >= (Expr.fbop opcode fty y x) }}
else apply_fail tt
| Infrule.fbop_commutative_rev e opcode x y fty =>
if $$ inv0 |-src (Expr.fbop opcode fty x y) >= e $$ &&
(is_commutative_fbop opcode)
then {{ inv0 +++src (Expr.fbop opcode fty y x) >= e }}
else apply_fail tt
| Infrule.fbop_commutative_tgt e opcode x y fty =>
if $$ inv0 |-tgt e >= (Expr.fbop opcode fty x y) $$ &&
(is_commutative_fbop opcode)
then {{ inv0 +++tgt e >= (Expr.fbop opcode fty y x) }}
else apply_fail tt
| Infrule.fbop_commutative_rev_tgt e opcode x y fty =>
if $$ inv0 |-tgt (Expr.fbop opcode fty x y) >= e $$ &&
(is_commutative_fbop opcode)
then {{ inv0 +++tgt (Expr.fbop opcode fty y x) >= e }}
else apply_fail tt
| Infrule.fadd_commutative_tgt z x y fty =>
if $$ inv0 |-tgt (Expr.fbop fbop_fadd fty x y) >= (Expr.value (ValueT.id z)) $$
then {{ inv0 +++tgt (Expr.fbop fbop_fadd fty y x) >= (Expr.value (ValueT.id z)) }}
else apply_fail tt
| Infrule.fbop_distributive_over_selectinst fbopcode r s t' t x y z c fbopty selty =>
if $$ inv0 |-tgt (Expr.fbop fbopcode fbopty x y) >= (Expr.value (ValueT.id r)) $$ &&
$$ inv0 |-tgt (Expr.fbop fbopcode fbopty x z) >= (Expr.value (ValueT.id s)) $$ &&
$$ inv0 |-tgt (Expr.select c (typ_floatpoint fbopty) y z) >= (Expr.value (ValueT.id t')) $$ &&
$$ inv0 |-tgt (Expr.fbop fbopcode fbopty x t') >= (Expr.value (ValueT.id t)) $$
then {{ inv0 +++tgt (Expr.select c (typ_floatpoint fbopty) (ValueT.id r) (ValueT.id s)) >= (Expr.value (ValueT.id t)) }}
else apply_fail tt
| Infrule.fbop_distributive_over_selectinst2 fbopcode r s t' t x y z c fbopty selty =>
if $$ inv0 |-tgt (Expr.fbop fbopcode fbopty y x) >= (Expr.value (ValueT.id r)) $$ &&
$$ inv0 |-tgt (Expr.fbop fbopcode fbopty z x) >= (Expr.value (ValueT.id s)) $$ &&
$$ inv0 |-tgt (Expr.select c (typ_floatpoint fbopty) y z) >= (Expr.value (ValueT.id t')) $$ &&
$$ inv0 |-tgt (Expr.fbop fbopcode fbopty t' x) >= (Expr.value (ValueT.id t)) $$
then {{ inv0 +++tgt (Expr.select c (typ_floatpoint fbopty) (ValueT.id r) (ValueT.id s)) >= (Expr.value (ValueT.id t)) }}
else apply_fail tt
| Infrule.fmul_commutative_tgt z x y fty =>
if $$ inv0 |-tgt (Expr.fbop fbop_fmul fty x y) >= (Expr.value (ValueT.id z)) $$
then {{ inv0 +++tgt (Expr.fbop fbop_fmul fty y x) >= (Expr.value (ValueT.id z)) }}
else apply_fail tt
| Infrule.fpext_bitcast src mid dst srcty midty dstty =>
if $$ inv0 |-src (Expr.value mid) >= (Expr.cast castop_bitcast srcty src midty) $$ &&
$$ inv0 |-src (Expr.value dst) >= (Expr.ext extop_fp midty mid dstty) $$ &&
cond_floatpointtyp dstty
then {{ inv0 +++src (Expr.value dst) >= (Expr.ext extop_fp srcty src dstty) }}
else apply_fail tt
| Infrule.fpext_fpext src mid dst srcty midty dstty =>
if $$ inv0 |-src (Expr.value mid) >= (Expr.ext extop_fp srcty src midty) $$ &&
$$ inv0 |-src (Expr.value dst) >= (Expr.ext extop_fp midty mid dstty) $$
then {{ inv0 +++src (Expr.value dst) >= (Expr.ext extop_fp srcty src dstty) }}
else apply_fail tt
| Infrule.fptosi_bitcast src mid dst srcty midty dstty =>
if $$ inv0 |-src (Expr.value mid) >= (Expr.cast castop_bitcast srcty src midty) $$ &&
$$ inv0 |-src (Expr.value dst) >= (Expr.cast castop_fptosi midty mid dstty) $$ &&
cond_floatpointtyp srcty
then {{ inv0 +++src (Expr.value dst) >= (Expr.cast castop_fptosi srcty src dstty) }}
else apply_fail tt
| Infrule.fptoui_bitcast src mid dst srcty midty dstty =>
if $$ inv0 |-src (Expr.value mid) >= (Expr.cast castop_bitcast srcty src midty) $$ &&
$$ inv0 |-src (Expr.value dst) >= (Expr.cast castop_fptoui midty mid dstty) $$ &&
cond_floatpointtyp srcty
then {{ inv0 +++src (Expr.value dst) >= (Expr.cast castop_fptoui srcty src dstty) }}
else apply_fail tt
| Infrule.fptosi_fpext src mid dst srcty midty dstty =>
if $$ inv0 |-src (Expr.value mid) >= (Expr.ext extop_fp srcty src midty) $$ &&
$$ inv0 |-src (Expr.value dst) >= (Expr.cast castop_fptosi midty mid dstty) $$
then {{ inv0 +++src (Expr.value dst) >= (Expr.cast castop_fptosi srcty src dstty) }}
else apply_fail tt
| Infrule.fptoui_fpext src mid dst srcty midty dstty =>
if $$ inv0 |-src (Expr.value mid) >= (Expr.ext extop_fp srcty src midty) $$ &&
$$ inv0 |-src (Expr.value dst) >= (Expr.cast castop_fptoui midty mid dstty) $$
then {{ inv0 +++src (Expr.value dst) >= (Expr.cast castop_fptoui srcty src dstty) }}
else apply_fail tt
| Infrule.fptrunc_bitcast src mid dst srcty midty dstty =>
if $$ inv0 |-src (Expr.value mid) >= (Expr.cast castop_bitcast srcty src midty) $$ &&
$$ inv0 |-src (Expr.value dst) >= (Expr.trunc truncop_fp midty mid dstty) $$ &&
cond_floatpointtyp srcty
then {{ inv0 +++src (Expr.value dst) >= (Expr.trunc truncop_fp srcty src dstty) }}
else apply_fail tt
| Infrule.fptrunc_fpext src mid dst srcty midty dstty =>
if $$ inv0 |-src (Expr.value mid) >= (Expr.ext extop_fp srcty src midty) $$ &&
$$ inv0 |-src (Expr.value dst) >= (Expr.trunc truncop_fp midty mid dstty) $$ &&
typ_dec srcty dstty
then {{ inv0 +++src (Expr.value dst) >= (Expr.cast castop_bitcast srcty src dstty) }}
else apply_fail tt
| Infrule.gepzero v' gepinst =>
if cond_gep_zero v' gepinst
then
let inv0 := {{inv0 +++src gepinst >= (Expr.value v')}} in
{{inv0 +++src (Expr.value v') >= gepinst}}
else apply_fail tt
| Infrule.gep_inbounds_remove gepinst =>
match gepinst with
| Expr.gep _ t v lsv u =>
{{inv0 +++src (Expr.gep true t v lsv u) >= (Expr.gep false t v lsv u) }}
| _ => apply_fail tt
end
| Infrule.gep_inbounds_remove_tgt gepinst =>
match gepinst with
| Expr.gep _ t v lsv u =>
{{inv0 +++tgt (Expr.gep true t v lsv u) >= (Expr.gep false t v lsv u) }}
| _ => apply_fail tt
end
| Infrule.gep_inbounds_add loadv ptr loadty al e =>
match e with
| Expr.gep _ t v lsv u =>
if $$ inv0 |-src (Expr.value loadv) >= (Expr.load ptr loadty al) $$ &&
$$ inv0 |-src (Expr.value ptr) >= (Expr.gep true t v lsv u) $$ &&
$$ inv0 |-src (Expr.gep true t v lsv u) >= (Expr.value ptr) $$
then
{{ inv0 +++src (Expr.gep false t v lsv u) >= (Expr.gep true t v lsv u) }}
else apply_fail tt
| _ => apply_fail tt
end
| Infrule.inttoptr_bitcast src mid dst srcty midty dstty =>
if $$ inv0 |-src (Expr.value mid) >= (Expr.cast castop_bitcast srcty src midty) $$ &&
$$ inv0 |-src (Expr.value dst) >= (Expr.cast castop_inttoptr midty mid dstty) $$ &&
cond_inttyp srcty
then {{ inv0 +++src (Expr.value dst) >= (Expr.cast castop_inttoptr srcty src dstty) }}
else apply_fail tt
| Infrule.inttoptr_zext src mid dst srcty midty dstty =>
if $$ inv0 |-src (Expr.value mid) >= (Expr.ext extop_z srcty src midty) $$ &&
$$ inv0 |-src (Expr.value dst) >= (Expr.cast castop_inttoptr midty mid dstty) $$
then {{ inv0 +++src (Expr.value dst) >= (Expr.cast castop_inttoptr srcty src dstty) }}
else apply_fail tt
| Infrule.inttoptr_load ptr intty v1 ptrty v2 a =>
if $$ inv0 |-src (Expr.load ptr intty a) >= (Expr.value v1) $$ &&
$$ inv0 |-src (Expr.cast castop_inttoptr intty v1 ptrty) >= (Expr.value v2) $$ &&
cond_same_bitsize intty ptrty m_src
then {{ inv0 +++src (Expr.load ptr ptrty a) >= (Expr.value v2) }}
else apply_fail tt
(* need to check that v's type is equal to ty and v do not invoke undefined behavior, but cannot *)
| Infrule.lessthan_undef ty v =>
if ValueT.canTrap v
then apply_fail tt
else {{ inv0 +++src (Expr.value (ValueT.const (const_undef ty))) >= (Expr.value v) }}
| Infrule.lessthan_undef_tgt ty v =>
if ValueT.canTrap v
then apply_fail tt
else {{ inv0 +++tgt (Expr.value (ValueT.const (const_undef ty))) >= (Expr.value v) }}
| Infrule.sdiv_sub_srem z b a x y s =>
if $$ inv0 |-src (Expr.value (ValueT.id b)) >= (Expr.bop bop_srem s x y) $$ &&
$$ inv0 |-src (Expr.value (ValueT.id a)) >= (Expr.bop bop_sub s x (ValueT.id b)) $$ &&
$$ inv0 |-src (Expr.value (ValueT.id z)) >= (Expr.bop bop_sdiv s (ValueT.id a) y) $$
then {{inv0 +++src (Expr.value (ValueT.id z)) >= (Expr.bop bop_sdiv s x y) }}
else apply_fail tt
| Infrule.udiv_sub_urem z b a x y s =>
if $$ inv0 |-src (Expr.value (ValueT.id b)) >= (Expr.bop bop_urem s x y) $$ &&
$$ inv0 |-src (Expr.value (ValueT.id a)) >= (Expr.bop bop_sub s x (ValueT.id b)) $$ &&
$$ inv0 |-src (Expr.value (ValueT.id z)) >= (Expr.bop bop_udiv s (ValueT.id a) y) $$
then {{inv0 +++src (Expr.value (ValueT.id z)) >= (Expr.bop bop_udiv s x y) }}
else apply_fail tt
| Infrule.sub_add z my x y s =>
if $$ inv0 |-src (Expr.value my) >= (Expr.bop bop_sub s (const_int s (INTEGER.of_Z (Size.to_Z s) 0%Z true)) y) $$ &&
$$ inv0 |-src (Expr.value z) >= (Expr.bop bop_sub s x my) $$
then {{inv0 +++src (Expr.value z) >= (Expr.bop bop_add s x y)}}
else apply_fail tt
| Infrule.sub_sub z x y w s =>
if $$ inv0 |-src (Expr.value w) >= (Expr.bop bop_sub s x y) $$ &&
$$ inv0 |-src (Expr.value (ValueT.id z)) >= (Expr.bop bop_sub s w x) $$
then {{inv0 +++src (Expr.value (ValueT.id z)) >= (Expr.bop bop_sub s (const_int s (INTEGER.of_Z (Size.to_Z s) 0%Z true)) y)}}
else apply_fail tt
| Infrule.neg_val c1 c2 s =>
if cond_plus s c1 c2 (INTEGER.of_Z (Size.to_Z s) 0%Z true)
then
let inv0 :=
{{inv0 +++src (Expr.value (const_int s c1)) >= (Expr.bop bop_sub s (const_int s (INTEGER.of_Z (Size.to_Z s) 0%Z true)) (const_int s c2))}} in
{{inv0 +++tgt (Expr.bop bop_sub s (const_int s (INTEGER.of_Z (Size.to_Z s) 0%Z true)) (const_int s c2)) >= (Expr.value (const_int s c1))}}
else apply_fail tt
| Infrule.mul_mone z x s =>
if $$ inv0 |-src (Expr.value (ValueT.id z)) >= (Expr.bop bop_mul s x (ValueT.const (const_int s (INTEGER.of_Z (Size.to_Z s) (-1)%Z true)))) $$
then {{ inv0 +++src (Expr.value (ValueT.id z))
>= (Expr.bop bop_sub s (ValueT.const (const_int s (INTEGER.of_Z (Size.to_Z s) 0%Z true))) x) }}
else apply_fail tt
| Infrule.mul_neg z mx my x y s =>
if $$ inv0 |-src (Expr.value mx) >= (Expr.bop bop_sub s (const_int s (INTEGER.of_Z (Size.to_Z s) 0%Z true)) x) $$ &&
$$ inv0 |-src (Expr.value my) >= (Expr.bop bop_sub s (const_int s (INTEGER.of_Z (Size.to_Z s) 0%Z true)) y) $$ &&
$$ inv0 |-src (Expr.value z) >= (Expr.bop bop_mul s mx my) $$
then {{inv0 +++src (Expr.value z) >= (Expr.bop bop_mul s x y)}}
else apply_fail tt
| Infrule.mul_bool z x y =>
if $$ inv0 |-src (Expr.value z) >= (Expr.bop bop_mul Size.One x y) $$
then {{inv0 +++src (Expr.value z) >= (Expr.bop bop_and Size.One x y) }}
else apply_fail tt
| Infrule.mul_shl z y x a s =>
if $$ inv0 |-src (Expr.value (ValueT.id y)) >= (Expr.bop bop_shl s (ValueT.const (const_int s (INTEGER.of_Z (Size.to_Z s) 1%Z true))) a) $$ &&
$$ inv0 |-src (Expr.value (ValueT.id z)) >= (Expr.bop bop_mul s (ValueT.id y) x) $$
then {{ inv0 +++src (Expr.value (ValueT.id z)) >= (Expr.bop bop_shl s x a) }}
else apply_fail tt
| Infrule.or_and z y x a s =>
if $$ inv0 |-src (Expr.value y) >= (Expr.bop bop_and s x a) $$ &&
$$ inv0 |-src (Expr.value z) >= (Expr.bop bop_or s y x) $$
then {{ inv0 +++src (Expr.value z) >= (Expr.value x) }}
else apply_fail tt
| Infrule.or_and_xor z x y a b s =>
if $$ inv0 |-src (Expr.value x) >= (Expr.bop bop_and s a b) $$ &&
$$ inv0 |-src (Expr.value y) >= (Expr.bop bop_xor s a b) $$ &&
$$ inv0 |-src (Expr.value z) >= (Expr.bop bop_or s x y) $$
then {{ inv0 +++src (Expr.value z) >= (Expr.bop bop_or s a b) }}
else apply_fail tt
| Infrule.or_commutative_tgt z x y s =>
if $$ inv0 |-tgt (Expr.bop bop_or s x y) >= (Expr.value (ValueT.id z)) $$
then {{inv0 +++tgt (Expr.bop bop_or s y x) >= (Expr.value (ValueT.id z)) }}
else apply_fail tt
| Infrule.or_not z y x s =>
if $$ inv0 |-src (Expr.value y) >= (Expr.bop bop_xor s x
(ValueT.const (const_int s (INTEGER.of_Z (Size.to_Z s) (-1)%Z true)))) $$ &&
$$ inv0 |-src (Expr.value z) >= (Expr.bop bop_or s x y) $$
then {{ inv0 +++src (Expr.value z) >= (Expr.value
(ValueT.const (const_int s (INTEGER.of_Z (Size.to_Z s) (-1)%Z true)))) }}
else apply_fail tt
| Infrule.or_mone z a s =>
if $$ inv0 |-src (Expr.value z) >= (Expr.bop bop_or s a
(ValueT.const (const_int s (INTEGER.of_Z (Size.to_Z s) (-1)%Z true)))) $$
then {{ inv0 +++src (Expr.value z) >= (Expr.value
(ValueT.const (const_int s (INTEGER.of_Z (Size.to_Z s) (-1)%Z true)))) }}
else apply_fail tt
| Infrule.or_or z x y a b s =>
if $$ inv0 |-src (Expr.value x) >= (Expr.bop bop_xor s a (ValueT.const (const_int s (INTEGER.of_Z (Size.to_Z s) (-1)%Z true)))) $$ &&
$$ inv0 |-src (Expr.value y) >= (Expr.bop bop_and s x b) $$ &&
$$ inv0 |-src (Expr.value z) >= (Expr.bop bop_or s y a) $$
then {{ inv0 +++src (Expr.value z) >= (Expr.bop bop_or s a b) }}
else apply_fail tt
| Infrule.or_or2 z x y y' a b s =>
if $$ inv0 |-tgt (Expr.bop bop_and s a b) >= (Expr.value x) $$ &&
$$ inv0 |-tgt (Expr.bop bop_xor s a (ValueT.const (const_int s (INTEGER.of_Z (Size.to_Z s) (-1)%Z true)))) >= (Expr.value y) $$ &&
$$ inv0 |-tgt (Expr.bop bop_xor s a (ValueT.const (const_int s (INTEGER.of_Z (Size.to_Z s) (-1)%Z true)))) >= (Expr.value y') $$ &&
$$ inv0 |-tgt (Expr.bop bop_or s y' b) >= (Expr.value z)$$
then {{ inv0 +++tgt (Expr.bop bop_or s x y) >= (Expr.value z) }}
else apply_fail tt
| Infrule.or_same z a s =>
if $$ inv0 |-src (Expr.value z) >= (Expr.bop bop_or s a a) $$
then {{ inv0 +++src (Expr.value z) >= (Expr.value a) }}
else apply_fail tt
| Infrule.or_false x y sz =>
let false_expr := Expr.value (ValueT.const (const_int sz (INTEGER.of_Z (Size.to_Z sz) 0%Z true))) in
if $$ inv0 |-src false_expr >= (Expr.bop bop_or sz x y) $$
then {{
{{
{{
{{inv0 +++src false_expr >= (Expr.value x)}}
+++src (Expr.value x) >= false_expr
}}
+++src false_expr >= (Expr.value y)
}}
+++src (Expr.value y) >= false_expr
}}
else apply_fail tt
| Infrule.or_false_tgt x y sz =>
let false_expr := Expr.value (ValueT.const (const_int sz (INTEGER.of_Z (Size.to_Z sz) 0%Z true))) in
if $$ inv0 |-tgt false_expr >= (Expr.bop bop_or sz x y) $$
then {{
{{
{{
{{inv0 +++tgt false_expr >= (Expr.value x)}}
+++tgt (Expr.value x) >= false_expr
}}
+++tgt false_expr >= (Expr.value y)
}}
+++tgt (Expr.value y) >= false_expr
}}
else apply_fail tt
| Infrule.or_undef z a s =>
if $$ inv0 |-src (Expr.value z) >= (Expr.bop bop_or s a (ValueT.const (const_undef (typ_int s)))) $$
then {{ inv0 +++src (Expr.value z) >= (Expr.value
(ValueT.const (const_int s (INTEGER.of_Z (Size.to_Z s) (-1)%Z true)))) }}
else apply_fail tt
| Infrule.or_xor w z x y a b s =>
if $$ inv0 |-src (Expr.value x) >= (Expr.bop bop_xor s b (ValueT.const (const_int s (INTEGER.of_Z (Size.to_Z s) (-1)%Z true)))) $$ &&
$$ inv0 |-src (Expr.value y) >= (Expr.bop bop_and s a x) $$ &&