diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2021-01-03 23:19:38 +0100 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2021-03-10 22:40:18 +0100 |
commit | 6f00b4edb2fb746b924db536519e31199eb57908 (patch) | |
tree | eb231b603ac05d0e9264d92a03b30a79b1960257 | |
parent | b9429057955ed194b072ca181d61c47c562ebcaa (diff) | |
download | sparse-6f00b4edb2fb746b924db536519e31199eb57908.tar.gz |
simplify (x & M) cmps C
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r-- | simplify.c | 25 | ||||
-rw-r--r-- | validation/optim/cmps-and0.c | 1 |
2 files changed, 25 insertions, 1 deletions
@@ -1258,6 +1258,31 @@ static int simplify_compare_constant(struct instruction *insn, long long value) src2 = insn->src2; value = src2->value; switch (DEF_OPCODE(def, src1)) { + case OP_AND: + if (!constant(def->src2)) + break; + bits = def->src2->value; + switch (insn->opcode) { + case OP_SET_LE: + value = sign_extend(value, def->size); + if (bits & sign_bit(def->size)) + break; + if (value < 0) + return replace_with_value(insn, 0); + if (value >= (long long)bits) + return replace_with_value(insn, 1); + break; + case OP_SET_GT: + value = sign_extend(value, def->size); + if (bits & sign_bit(def->size)) + break; + if (value < 0) + return replace_with_value(insn, 1); + if (value >= (long long)bits) + return replace_with_value(insn, 0); + break; + } + break; case OP_SEXT: // sext(x) cmp C --> x cmp trunc(C) osize = def->orig_type->bit_size; if (is_signed_constant(value, osize, size)) { diff --git a/validation/optim/cmps-and0.c b/validation/optim/cmps-and0.c index 097ec2f9..962fbd2d 100644 --- a/validation/optim/cmps-and0.c +++ b/validation/optim/cmps-and0.c @@ -15,7 +15,6 @@ int cmps_and_ge_gtm(int a) { return ((a & MASK) >= (MASK + 1)) + 1; } /* * check-name: cmps-and0 * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-returns: 1 |