[PATCH 9/9] simplify TRUNC((x & M) | y, N)

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

 



A N-bit truncate is not much different than ANDing with
a N-bit mask and so the same simplifications can be done.

[It's especially the case with bitfields where the TRUNC+ZEXT
of unsigned bitfields is simplified into an OP_AND while for
signed bitfields the TRUNC+SEXT can't be transformed into a
simple mask operation].

Apply the same simplifications as done for ((x & M) | y) & $mask(N)
---
 simplify.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/simplify.c b/simplify.c
index baea32378..1569b4104 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1238,6 +1238,7 @@ static int simplify_cast(struct instruction *insn)
 	struct instruction *def;
 	pseudo_t src;
 	pseudo_t val;
+	int rc = 0;
 	int osize;
 	int size;
 
@@ -1318,6 +1319,15 @@ static int simplify_cast(struct instruction *insn)
 			return replace_pseudo(insn, &insn->src1, def->src1);
 		}
 		break;
+	case OP_OR:
+		switch (insn->opcode) {
+		case OP_TRUNC:
+			mask = bits_mask(insn->size);
+			rc |= simplify_and_or_mask(def->src1, mask);
+			rc |= simplify_and_or_mask(def->src2, mask);
+			return rc;
+		}
+		break;
 	case OP_TRUNC:
 		osize = def->orig_type->bit_size;
 		if (insn->opcode == OP_ZEXT && size == osize) {
-- 
2.18.0

--
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



[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