[PATCH v2 04/15] add simplify_mask_or()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 simplify.c | 30 ++++++++++++++----------------
 1 file changed, 14 insertions(+), 16 deletions(-)

diff --git a/simplify.c b/simplify.c
index ce48b3a91..5d5bd3f00 100644
--- a/simplify.c
+++ b/simplify.c
@@ -564,6 +564,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;
@@ -600,7 +612,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);
@@ -667,13 +678,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 (A << S) >> S
 			// by      A & (Mask(size) >> S)
@@ -834,7 +839,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)) {
@@ -842,13 +846,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 */
-- 
2.18.0




[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux