aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-10-26 07:07:06 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-11-08 02:15:14 +0100
commita1c1b9236d5d4af1681a45ced26f8350bd7721c2 (patch)
tree7c0e4d8dbf57a5d8c57d63ec9d9e4132d1e7759c
parent89b98b682930e5d4efe97f0ba3b412c23c6721e3 (diff)
downloadsparse-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.c14
-rw-r--r--validation/optim/cmp-sext-simm.c1
2 files changed, 14 insertions, 1 deletions
diff --git a/simplify.c b/simplify.c
index 1cb5275b..a5991869 100644
--- a/simplify.c
+++ b/simplify.c
@@ -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