diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-08-14 11:35:20 +0200 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-08-22 09:25:34 +0200 |
| commit | cce0b3b688346ce2416233ba06007388c379c113 (patch) | |
| tree | a1d5028dc27cffd5ded12691e618cbfaa5f12245 | |
| parent | fcbfef57bef4b3cf9e3ef84e39b89cf2c0dddc55 (diff) | |
| download | sparse-dev-cce0b3b688346ce2416233ba06007388c379c113.tar.gz | |
add simplify_mask_or()
Both sites calling simplify_mask_or_and() do it in exactly the same way.
In order to avoid code duplication and in preparation of incoming
changes, move these calls to a small helper: simplify_mask_or().
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
| -rw-r--r-- | simplify.c | 30 |
1 files changed, 14 insertions, 16 deletions
@@ -595,6 +595,18 @@ static int simplify_mask_or_and(struct instruction *insn, unsigned long long mas return replace_pseudo(insn, &insn->src1, other); } +static int simplify_mask_or(struct instruction *insn, unsigned long long mask, struct instruction *or) +{ + pseudo_t src1 = or->src1; + pseudo_t src2 = or->src2; + + if (def_opcode(src1) == OP_AND) + return simplify_mask_or_and(insn, mask, src1, src2); + if (def_opcode(src2) == OP_AND) + return simplify_mask_or_and(insn, mask, src2, src1); + return 0; +} + static long long check_shift_count(struct instruction *insn, unsigned long long uval) { unsigned int size = insn->size; @@ -631,7 +643,6 @@ static int simplify_shift(struct instruction *insn, pseudo_t pseudo, long long v unsigned long long nval; unsigned int size; pseudo_t src2; - pseudo_t src; if (!value) return replace_with_pseudo(insn, pseudo); @@ -698,13 +709,7 @@ static int simplify_shift(struct instruction *insn, pseudo_t pseudo, long long v goto case_shift_shift; case OP_OR: mask = bits_mask(size - value) << value; - src = def->src1; - if (def_opcode(src) == OP_AND) - return simplify_mask_or_and(insn, mask, src, def->src2); - src = def->src2; - if (def_opcode(src) == OP_AND) - return simplify_mask_or_and(insn, mask, src, def->src1); - break; + return simplify_mask_or(insn, mask, def); case OP_SHL: // replace ((x << S) >> S) // by (x & (-1 >> S)) @@ -872,7 +877,6 @@ static int simplify_constant_mask(struct instruction *insn, unsigned long long m unsigned long long omask; unsigned long long nmask; struct instruction *def; - pseudo_t src1, src2; int osize; switch (DEF_OPCODE(def, old)) { @@ -880,13 +884,7 @@ static int simplify_constant_mask(struct instruction *insn, unsigned long long m osize = 1; goto oldsize; case OP_OR: - src1 = def->src1; - src2 = def->src2; - if (def_opcode(src1) == OP_AND) - return simplify_mask_or_and(insn, mask, src1, src2); - if (def_opcode(src2) == OP_AND) - return simplify_mask_or_and(insn, mask, src2, src1); - break; + return simplify_mask_or(insn, mask, def); case OP_ZEXT: osize = def->orig_type->bit_size; /* fall through */ |
