diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-06-18 11:34:07 +0200 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-06-23 16:14:53 +0200 |
| commit | c64d1972a5b775b9d7169dc8db96ee0556af7b26 (patch) | |
| tree | 9b12eb25273738342a49db0df7668c77f3f07d2b | |
| parent | 8dbdcd3d7b6c9f64c16bd77c7a0a8d22d16e7faf (diff) | |
| download | sparse-dev-c64d1972a5b775b9d7169dc8db96ee0556af7b26.tar.gz | |
cast: prepare for more cast simplifications
Currently, the only simplification of casts is CAST(AND(X))
but more simplification are possible.
Prepare for additional simplification by unsing a switch-case
for OP_AND instead of the current 'if'.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
| -rw-r--r-- | simplify.c | 17 |
1 files changed, 10 insertions, 7 deletions
@@ -946,30 +946,33 @@ static int simplify_memop(struct instruction *insn) static int simplify_cast(struct instruction *insn) { + struct instruction *def; pseudo_t src; int size; if (dead_insn(insn, &insn->src, NULL, NULL)) return REPEAT_CSE; - size = insn->size; src = insn->src; /* A cast of a constant? */ if (constant(src)) return simplify_constant_unop(insn); - /* A cast of a "and" might be a no-op.. */ - if (src->type == PSEUDO_REG) { - struct instruction *def = src->def; - if (def->opcode == OP_AND && def->size >= size) { + // can merge with the previous instruction? + size = insn->size; + def = src->def; + switch (def_opcode(src)) { + case OP_AND: + /* A cast of a AND might be a no-op.. */ + if (def->size >= size) { pseudo_t val = def->src2; if (val->type == PSEUDO_VAL) { - unsigned long long value = val->value; - if (!(value >> (size-1))) + if (!(val->value >> (size-1))) goto simplify; } } + break; } return 0; |
