aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-08-22 17:31:57 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-08-24 08:18:56 +0200
commit1d78043467a769ccf2d81d55f898fb37f158b14f (patch)
treee26ffeac2e858644f02a87f558f2ccff56e1ed78
parent3f2cbce78f78cbae35a02eb318a86f78556f71aa (diff)
downloadsparse-dev-1d78043467a769ccf2d81d55f898fb37f158b14f.tar.gz
simplify TRUNC(SHIFT(a | b, S), N)
The simplification 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 allows 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@gmail.com>
-rw-r--r--simplify.c6
-rw-r--r--validation/optim/and-or-bfs.c1
-rw-r--r--validation/optim/bitfield-store-loads.c1
3 files changed, 6 insertions, 2 deletions
diff --git a/simplify.c b/simplify.c
index 78688c7c..ae23e2a6 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 e08b816e..f3f33204 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 99a0a03a..dc625131 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\\.