[PATCH 4/4] simplify TRUNC(SHIFT(a | b, S), N)

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

 



The simplication of TRUNC(SHIFT(a | b, S), N) can be done by
combining the effective mask corresponding to TRUNC(_, N) with
the one corresponding to SHIFT(_, S).

This allow to also simplify signed bitfields. For example, code like:
	struct s {
		  signed int  :2;
		  signed int f:3;
	};
	int bfs(struct s s, int a)
	{
		s.f = a;
		return s.f;
	}

is now simplified into the minimal:
	bfs:
		trunc.3     %r4 <- (32) %arg2
		sext.32     %r11 <- (3) %r4
		ret.32      %r11

The simplification is done by calling simplify_mask_shift() with
the mask corresponding to TRUNC(_, N).

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 simplify.c                              | 6 ++++++
 validation/optim/and-or-bfs.c           | 1 -
 validation/optim/bitfield-store-loads.c | 1 -
 3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/simplify.c b/simplify.c
index 78688c7c3..ae23e2a69 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1437,6 +1437,12 @@ static int simplify_cast(struct instruction *insn)
 			return replace_pseudo(insn, &insn->src1, def->src1);
 		}
 		break;
+	case OP_LSR:
+	case OP_SHL:
+		if (insn->opcode != OP_TRUNC)
+			break;
+		mask = bits_mask(insn->size);
+		return simplify_mask_shift(def, mask);
 	case OP_TRUNC:
 		switch (insn->opcode) {
 		case OP_TRUNC:
diff --git a/validation/optim/and-or-bfs.c b/validation/optim/and-or-bfs.c
index e08b816e2..f3f332047 100644
--- a/validation/optim/and-or-bfs.c
+++ b/validation/optim/and-or-bfs.c
@@ -12,7 +12,6 @@ int bfs(struct s s, int a)
 /*
  * check-name: and-or-bfs
  * check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
  *
  * check-output-ignore
  * check-output-pattern(1): trunc\\.
diff --git a/validation/optim/bitfield-store-loads.c b/validation/optim/bitfield-store-loads.c
index 99a0a03a7..dc625131e 100644
--- a/validation/optim/bitfield-store-loads.c
+++ b/validation/optim/bitfield-store-loads.c
@@ -12,7 +12,6 @@ int foo(struct s s, int a)
 /*
  * check-name: bitfield-store-load signed
  * check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
  *
  * check-output-ignore
  * check-output-excludes: shl\\.
-- 
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