diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-10-26 07:07:06 +0100 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-11-08 02:15:14 +0100 |
commit | a1c1b9236d5d4af1681a45ced26f8350bd7721c2 (patch) | |
tree | 7c0e4d8dbf57a5d8c57d63ec9d9e4132d1e7759c | |
parent | 89b98b682930e5d4efe97f0ba3b412c23c6721e3 (diff) | |
download | sparse-a1c1b9236d5d4af1681a45ced26f8350bd7721c2.tar.gz |
cmp: simplify sext(x) cmps {SMAX,SMIN}
A signed compare of a sign-extended value against a constant
outside of the original range is statically known.
Simplify to the corresponding 0/1.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r-- | simplify.c | 14 | ||||
-rw-r--r-- | validation/optim/cmp-sext-simm.c | 1 |
2 files changed, 14 insertions, 1 deletions
@@ -1148,6 +1148,20 @@ static int simplify_compare_constant(struct instruction *insn, long long value) insn->src2 = value_pseudo(zero_extend(value, osize)); return replace_pseudo(insn, &insn->src1, def->src); } + switch (insn->opcode) { + case OP_SET_LT: case OP_SET_LE: + if (value >= sign_bit(osize)) + return replace_with_value(insn, 1); + else + return replace_with_value(insn, 0); + break; + case OP_SET_GE: case OP_SET_GT: + if (value >= sign_bit(osize)) + return replace_with_value(insn, 0); + else + return replace_with_value(insn, 1); + break; + } break; case OP_ZEXT: osize = def->orig_type->bit_size; diff --git a/validation/optim/cmp-sext-simm.c b/validation/optim/cmp-sext-simm.c index c2099a6b..a8b2a8f9 100644 --- a/validation/optim/cmp-sext-simm.c +++ b/validation/optim/cmp-sext-simm.c @@ -23,7 +23,6 @@ static int ge_lt1(int x) { return (sext(x) >= (NEG - 1)) == 0; } /* * check-name: cmp-sext-simm * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-returns: 1 |