fix boolean context for OP_AND_BOOL & OP_OR_BOOL
commit6217cd5c130071a65c4d30d8e846f9c9ef0a9bd4
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>
Wed, 14 Dec 2016 08:55:20 +0000 (14 09:55 +0100)
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>
Thu, 11 May 2017 23:36:07 +0000 (12 01:36 +0200)
treeb5773e1ca69a2bd3b159da6c559d7a473782b66f
parente35efe330c6ae7d154197c29b127560d569016d0
fix boolean context for OP_AND_BOOL & OP_OR_BOOL

Current simplifications of 'x && 1 --> x' and its dual
'x || 0 --> x' are wrong because the '||' and '&&' operators
demand that their operands are first compared against zero
which then always give a boolean valued result.
For example: '3 && 1' is not equal to '3' but to '1' (or 'true').
The correct simplification is thus 'x && 1 --> x != 0' and
'x || 0 --> x != 0'.

Fix this by always first doing the comparison against zero
before generating the OP_AND_BOOL and OP_OR_BOOL instructions.

Note: of course, we could decide that the semantic of OP_AND_BOOL
      and OP_OR_BOOL is that these ops take care themselves of
      making a boolean context (which was, I think, why these
      ops were created) but then these simplifications cannot be
      done (or when they are done, we need to add the comparison
      against zero).

Fixes: b85ec4bb7f5b1c522d7c71782dbd9cf1c4c49b2f
Fixes: a0886db12307d2633b04ec44342099a2955794a5
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
linearize.c
validation/optim/bool-context.c [new file with mode: 0644]
validation/optim/bool-simplify.c