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@xxxxxxxxx> --- simplify.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/simplify.c b/simplify.c index a7d88069b..29ec6e6f3 100644 --- a/simplify.c +++ b/simplify.c @@ -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; -- 2.17.1 -- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html