aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-11-01 23:29:30 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-11-08 02:16:21 +0100
commit74d99ae4bd80d6b2064ca539ba4dffe24aaec362 (patch)
tree8875b9c9482be8d797d5a0d493dc2c2586e47f9f
parent4a5f616407e26efb67013f8267adef2d6e093bf1 (diff)
downloadsparse-dev-74d99ae4bd80d6b2064ca539ba4dffe24aaec362.tar.gz
cmp: simplify zext(x) cmps C
A signed compare of a zero-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-zext-simm.c1
2 files changed, 14 insertions, 1 deletions
diff --git a/simplify.c b/simplify.c
index 8a8b39b8..83ae763e 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1185,6 +1185,20 @@ static int simplify_compare_constant(struct instruction *insn, long long value)
insn->itype = def->orig_type;
return replace_pseudo(insn, &insn->src1, def->src);
}
+ switch (insn->opcode) {
+ case OP_SET_LT: case OP_SET_LE:
+ if (sign_extend(value, def->size) > (long long)bits)
+ return replace_with_value(insn, 1);
+ else
+ return replace_with_value(insn, 0);
+ break;
+ case OP_SET_GE: case OP_SET_GT:
+ if (sign_extend(value, def->size) > (long long)bits)
+ return replace_with_value(insn, 0);
+ else
+ return replace_with_value(insn, 1);
+ break;
+ }
break;
}
return changed;
diff --git a/validation/optim/cmp-zext-simm.c b/validation/optim/cmp-zext-simm.c
index f89f8f8b..dda237d7 100644
--- a/validation/optim/cmp-zext-simm.c
+++ b/validation/optim/cmp-zext-simm.c
@@ -17,7 +17,6 @@ int zext_lgt(unsigned int x) { return (ZEXT(x) > -1) == 1; }
/*
* check-name: cmp-zext-simm
* check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
*
* check-output-ignore
* check-output-returns: 1