From de33c2df01abfe488a0e80ec0c5d74c68975e856 Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Sat, 28 Mar 2015 20:16:06 +0100 Subject: [PATCH] Simplify operands of bitwise OR expressions as booleans. Deals with a TODO in a more general way. --- lslopt/lslfoldconst.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lslopt/lslfoldconst.py b/lslopt/lslfoldconst.py index 6453d59..fb1a9b1 100644 --- a/lslopt/lslfoldconst.py +++ b/lslopt/lslfoldconst.py @@ -128,7 +128,10 @@ class foldconst(object): self.FoldTree(parent, index) if nt == '|': - #TODO: simplify !!a|b or a|!!b -> a|b + # In a boolean context, the operands count as booleans. + self.FoldCond(child, 0) + self.FoldCond(child, 1) + a, b = 0, 1 if child[a]['nt'] == 'CONST': a, b = 1, 0