Skip to content

Commit 9e7fc82

Browse files
committed
XPR: add simplification rules
1 parent 092ca6d commit 9e7fc82

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

CodeHawk/CH/xprlib/xsimplify.ml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ let rec sim_expr (m:bool) (e:xpr_t):(bool * xpr_t) =
153153
| XAsr -> reduce_asr m s1 s2
154154
| XLsl -> reduce_lsl m s1 s2
155155
| XBAnd -> reduce_bitwiseand m s1 s2
156+
| XLAnd -> reduce_and m s1 s2
156157
| XDisjoint -> reduce_disjoint m s1 s2
157158
| XSubset -> reduce_subset m s1 s2
158159
| XNumJoin -> reduce_binary_numjoin m s1 s2
@@ -1091,9 +1092,14 @@ and reduce_bor m e1 e2 =
10911092

10921093
and reduce_or m e1 e2 =
10931094
let default = (m, XOp (XLOr, [e1 ; e2])) in
1094-
if is_true e1 || is_true e2 then (true, true_constant_expr)
1095-
else if is_false e1 then (true, e2)
1096-
else if is_false e2 then (true, e1)
1095+
if is_true e1 || is_true e2 then
1096+
(true, true_constant_expr)
1097+
else if is_false e1 then
1098+
(true, e2)
1099+
else if is_false e2 then
1100+
(true, e1)
1101+
else if syntactically_equal e1 e2 then
1102+
(true, e1)
10971103
else match (e1,e2) with
10981104
| (XConst XRandom, XOp (XLOr, [XConst XRandom; b]))
10991105
| (XConst XRandom, XOp (XLOr, [b; XConst XRandom]))
@@ -1145,6 +1151,19 @@ and reduce_bitwiseand m e1 e2 =
11451151
default
11461152
end
11471153

1154+
and reduce_and m e1 e2 =
1155+
let default = (m, XOp (XLAnd, [e1; e2])) in
1156+
if is_true e1 && is_true e2 then
1157+
(true, true_constant_expr)
1158+
else if is_true e1 then
1159+
(true, e2)
1160+
else if is_true e2 then
1161+
(true, e1)
1162+
else if syntactically_equal e1 e2 then
1163+
(true, e1)
1164+
else
1165+
default
1166+
11481167

11491168
and reduce_shiftleft (m: bool) (e1: xpr_t) (e2: xpr_t): bool * xpr_t =
11501169
let default = (m, XOp (XShiftlt, [e1; e2])) in

0 commit comments

Comments
 (0)