diff mbox series

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

Message ID 20180808143528.82880-10-luc.vanoostenryck@gmail.com (mailing list archive)
State Rejected, archived
Headers show
Series more simplifications of bitfiled accesses | expand

Commit Message

Luc Van Oostenryck Aug. 8, 2018, 2:35 p.m. UTC
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 mbox series

Patch

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