diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-07-01 22:21:28 +0200 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-07-23 13:11:20 +0200 |
| commit | 45e70ebf4685004ad3cf31c8acf5b8c834933379 (patch) | |
| tree | 1923af6d99a88757de82b64f20ce8cb9299cf345 | |
| parent | c1715a15efc63174218266f400ffb535ee9c5e16 (diff) | |
| download | sparse-dev-45e70ebf4685004ad3cf31c8acf5b8c834933379.tar.gz | |
cast: preserve the sizes of TRUNC(AND(x,M),N)
sparse contains some code to simplify an AND masking
followed by a truncating cast.
However, this simplification is problematic because it
doesn't keep the sizes consistent. For example, code like:
and.32 %r3 <- %r2, $0x7fff
trunc.16 %r4 <- (32) %r3
will be discarded with %r3 used in place of %r4.
This is correct in the mathematical sense but %r4 had a size
of 16 while %r3 has a size of 32, so using %r3 in place of %r4
will make the sizes inconsistent with unexpected consequences.
We can more or less fix this by using another transformation
that preserve the sizes:
trunc.16 %r3 <- (32) %r2
and.16 %r4 <- %r3, $0x7fff
which in itself doesn't optimize anything but:
1) the mask may be smaller
2) may trigger other simplification with the TRUNC or the AND.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
| -rw-r--r-- | simplify.c | 17 | ||||
| -rw-r--r-- | validation/optim/and-trunc.c | 1 |
2 files changed, 11 insertions, 7 deletions
@@ -999,10 +999,18 @@ static int simplify_cast(struct instruction *insn) /* A cast of a AND might be a no-op.. */ switch (insn->opcode) { case OP_TRUNC: + if (nbr_users(src) > 1) + break; + def->opcode = OP_TRUNC; + def->orig_type = def->type; + def->type = insn->type; + def->size = size; + + insn->opcode = OP_AND; mask = val->value; - if (!(mask >> (size-1))) - goto simplify; - break; + mask &= (1ULL << size) - 1; + insn->src2 = value_pseudo(mask); + return REPEAT_CSE; } break; case OP_TRUNC: @@ -1029,9 +1037,6 @@ static int simplify_cast(struct instruction *insn) } return 0; - -simplify: - return replace_with_pseudo(insn, src); } static int simplify_select(struct instruction *insn) diff --git a/validation/optim/and-trunc.c b/validation/optim/and-trunc.c index bcb80bbe..df1e4d03 100644 --- a/validation/optim/and-trunc.c +++ b/validation/optim/and-trunc.c @@ -11,7 +11,6 @@ short umask(unsigned short x) /* * check-name: and-trunc * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-excludes: sext\\. |
