diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-08-08 01:04:26 +0200 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-08-22 23:28:07 +0200 |
| commit | 24e2b3800cc5451a509b53e8120f0e009da6f582 (patch) | |
| tree | e39c718afdf4962f893d45786508dde21277a541 /validation/optim/and-or-trunc1.c | |
| parent | a4ae84a892b6e5a8b563f0bb125fcc5a3448b383 (diff) | |
| download | sparse-dev-24e2b3800cc5451a509b53e8120f0e009da6f582.tar.gz | |
simplify TRUNC((x & M') | y, N)
A N-bit truncate is not much different than ANDing with
a N-bit mask and so some simplifications done for AND can
also be done for TRUNC. For example for code like this:
char foo(int x, int y) { return (x & 0xffff) | y; }
the mask is unneeded and the function should be equivalent to:
char foo(int x, int y) { return x | y; }
The simplification in this patch does exactly this, giving:
foo:
or.32 %r4 <- %arg1, %arg2
trunc.8 %r5 <- (32) %r4
ret.8 %r5
while previously the mask was not optimized away:
foo:
and.32 %r2 <- %arg1, $0xffff
or.32 %r4 <- %r2, %arg2
trunc.8 %r5 <- (32) %r4
ret.8 %r5
This simplification is especially important for signed bitfields
because the TRUNC+ZEXT of unsigned bitfields is simplified into
an OP_AND but this is, of course, not the case for the TRUNC+SEXT
of signed bitfields.
Do the simplification by calling simplify_mask_or(), initialy used
for OP_AND, but with the effective mask corresponding to TRUNC(x, N):
$mask(N).
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'validation/optim/and-or-trunc1.c')
| -rw-r--r-- | validation/optim/and-or-trunc1.c | 1 |
1 files changed, 0 insertions, 1 deletions
diff --git a/validation/optim/and-or-trunc1.c b/validation/optim/and-or-trunc1.c index 84c20317..6bbe8a8c 100644 --- a/validation/optim/and-or-trunc1.c +++ b/validation/optim/and-or-trunc1.c @@ -6,7 +6,6 @@ char foo(int x, int y) /* * check-name: and-or-trunc1 * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-excludes: and\\. |
