aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-09-28 01:17:20 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-10-24 22:56:24 +0200
commitcea6a6faf6f794d77ffcde5a3f9ae2e43d2341fa (patch)
treefdcb55318bb316a7bd60f0634e796369cbaa108f
parent29aab3ee2f7ab586b5e476f40d427ff9e77fca22 (diff)
downloadsparse-cea6a6faf6f794d77ffcde5a3f9ae2e43d2341fa.tar.gz
unop: prepare simplify_unop() to handle more cases
Currently, simplify_unop() can only handle the simplification of -(-x) and ~(~x). Prepare it to handle more cases. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--simplify.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/simplify.c b/simplify.c
index 6caf6cbc..a8a33efe 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1451,21 +1451,26 @@ static int simplify_constant_unop(struct instruction *insn)
static int simplify_unop(struct instruction *insn)
{
+ struct instruction *def;
+ pseudo_t src = insn->src;
+
if (dead_insn(insn, &insn->src1, NULL, NULL))
return REPEAT_CSE;
- if (constant(insn->src1))
+ if (constant(src))
return simplify_constant_unop(insn);
switch (insn->opcode) {
- struct instruction *def;
-
case OP_NOT:
- if (DEF_OPCODE(def, insn->src) == OP_NOT)
+ switch (DEF_OPCODE(def, src)) {
+ case OP_NOT: // ~(~x) --> x
return replace_with_pseudo(insn, def->src);
+ }
break;
case OP_NEG:
- if (DEF_OPCODE(def, insn->src) == OP_NEG)
+ switch (DEF_OPCODE(def, src)) {
+ case OP_NEG: // -(-x) --> x
return replace_with_pseudo(insn, def->src);
+ }
break;
default:
return 0;