This is especially usefull when simplifying code accessing bitfields. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx> --- simplify.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/simplify.c b/simplify.c index f1a898700..cdc244c17 100644 --- a/simplify.c +++ b/simplify.c @@ -416,6 +416,7 @@ static int simplify_lsr(struct instruction *insn, pseudo_t pseudo, long long val { struct instruction *def; unsigned long long mask; + pseudo_t old; if (!value) return replace_with_pseudo(insn, pseudo); @@ -434,6 +435,20 @@ static int simplify_lsr(struct instruction *insn, pseudo_t pseudo, long long val insn->opcode = OP_AND; insn->src2 = value_pseudo(mask >> value); return REPEAT_CSE; + case OP_SHL: + // replace (A << S) >> S + // by A & (-1 >> S) + def = insn->src1->def; + if (!constant(def->src2)) + break; + if (def->src2->value != value) + break; + insn->opcode = OP_AND; + insn->src2 = value_pseudo(-1ULL >> value); + old = insn->src1; + use_pseudo(insn, def->src1, &insn->src1); + remove_usage(old, &insn->src1); + return REPEAT_CSE; } return 0; } -- 2.13.2 -- 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