aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-10-22 01:13:02 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-11-08 02:12:10 +0100
commit4146aecb9917aaad05c560280089e2557f113126 (patch)
tree6114438d1e40864615903b8aa16e0b55a2eb76cf
parentc355e5ac5dce35f3d95c30cd5e2e9a5074c38437 (diff)
downloadsparse-4146aecb9917aaad05c560280089e2557f113126.tar.gz
cmp: simplify unsigned (x {<=,>} UMAX) into {1,0}
These compares are always true or false, so simplify them. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--simplify.c5
-rw-r--r--validation/optim/set-uimm1.c1
2 files changed, 5 insertions, 1 deletions
diff --git a/simplify.c b/simplify.c
index b8dfbad1..160a6ab1 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1081,6 +1081,7 @@ static int simplify_seteq_setne(struct instruction *insn, long long value)
static int simplify_compare_constant(struct instruction *insn, long long value)
{
+ unsigned long long bits = bits_mask(insn->itype->bit_size);
int changed = 0;
switch (insn->opcode) {
@@ -1103,10 +1104,14 @@ static int simplify_compare_constant(struct instruction *insn, long long value)
case OP_SET_BE:
if (!value) // (x <= 0) --> (x == 0)
return replace_opcode(insn, OP_SET_EQ);
+ if (value == bits) // (x <= ~0) --> 1
+ return replace_with_pseudo(insn, value_pseudo(1));
break;
case OP_SET_A:
if (!value) // (x > 0) --> (x != 0)
return replace_opcode(insn, OP_SET_NE);
+ if (value == bits) // (x > ~0) --> 0
+ return replace_with_pseudo(insn, value_pseudo(0));
break;
}
return changed;
diff --git a/validation/optim/set-uimm1.c b/validation/optim/set-uimm1.c
index d6928f59..aa9f54c3 100644
--- a/validation/optim/set-uimm1.c
+++ b/validation/optim/set-uimm1.c
@@ -4,7 +4,6 @@ static _Bool setgt_umax(unsigned int a) { return (a > ~0) == 0; }
/*
* check-name: set-uimm1
* check-command: test-linearize $file
- * check-known-to-fail
*
* check-output-ignore
* check-output-returns: 1