diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-06-29 18:51:03 +0200 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-10-23 17:44:52 +0200 |
commit | a80921db90cd8de52b2fa37bf61e6156dd3a6bcd (patch) | |
tree | 337f1290bbe99d22f126355768df75916e561a39 | |
parent | cfca7b4c6cb48283cb554fc91dc859ff669f2547 (diff) | |
download | sparse-a80921db90cd8de52b2fa37bf61e6156dd3a6bcd.tar.gz |
simplify unsigned compares against 0
Some unsigned compares against 0 are always true or always false
(x < 0 or x >= 0). Simplify them.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r-- | simplify.c | 10 | ||||
-rw-r--r-- | validation/optim/set-uimm0.c | 10 |
2 files changed, 20 insertions, 0 deletions
@@ -1173,6 +1173,16 @@ static int simplify_constant_rightside(struct instruction *insn) case OP_SET_NE: case OP_SET_EQ: return simplify_seteq_setne(insn, value); + case OP_SET_B: + if (!value) { // (x < 0) --> 0 + return replace_with_pseudo(insn, value_pseudo(0)); + } + break; + case OP_SET_AE: + if (!value) { // (x >= 0) --> 1 + return replace_with_pseudo(insn, value_pseudo(1)); + } + break; } return 0; } diff --git a/validation/optim/set-uimm0.c b/validation/optim/set-uimm0.c new file mode 100644 index 00000000..1f62358f --- /dev/null +++ b/validation/optim/set-uimm0.c @@ -0,0 +1,10 @@ +static _Bool setlt0(unsigned int a) { return (a < 0u) == 0; } +static _Bool setge0(unsigned int a) { return (a >= 0u) == 1; } + +/* + * check-name: set-uimm0 + * check-command: test-linearize $file + * + * check-output-ignore + * check-output-pattern(2): ret\\.1 *\\$1 + */ |