aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2021-03-13 14:03:20 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2021-04-18 23:45:41 +0200
commit99bf609861c3bc9ba313a81642988da92838c9e2 (patch)
treedb342d7d500b04e2029f175a87ac952401db6728
parenteb4cdd21b7d0cedbbeff7f70e24473706ccce5a6 (diff)
downloadsparse-99bf609861c3bc9ba313a81642988da92838c9e2.tar.gz
TRUNC(x) {==,!=} C --> AND(x,M) {==,!=} C
It's not 100% clear than this is indeed a simplification but: 1) from a pure instruction count point of view, it doesn't make things worst 2) in most place where it applies, the masking is made redundant and is thus eliminated Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--simplify.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/simplify.c b/simplify.c
index 9e3514d8..21c556e1 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1392,6 +1392,20 @@ static int simplify_compare_constant(struct instruction *insn, long long value)
break;
}
break;
+ case OP_TRUNC:
+ osize = def->orig_type->bit_size;
+ switch (insn->opcode) {
+ case OP_SET_EQ: case OP_SET_NE:
+ if (one_use(def->target)) {
+ insn->itype = def->orig_type;
+ def->type = def->orig_type;
+ def->size = osize;
+ def->src2 = value_pseudo(bits);
+ return replace_opcode(def, OP_AND);
+ }
+ break;
+ }
+ break;
case OP_ZEXT:
osize = def->orig_type->bit_size;
bits = bits_mask(osize);