diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-07-02 00:20:25 +0200 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2018-07-23 13:11:20 +0200 |
| commit | 212b9239abbc4101b9558d2a5c8a554eaae99b00 (patch) | |
| tree | 52c2c59906b401f3688a4e580376328e65eb7fc2 /simplify.c | |
| parent | 548f00d19561881ba176c8acfaf9121ddacb80e8 (diff) | |
| download | sparse-dev-212b9239abbc4101b9558d2a5c8a554eaae99b00.tar.gz | |
cast: simplify [SZ]EXT + TRUNC to a smaller/greater size
An OP_SEXT or a OP_ZEXT followed by a truncate to a size smaller
than the original size is unneeded, the same result can be obtained
by doing the truncate directly on the original value.
Dualy, an OP_SEXT or a OP_ZEXT followed by a truncate to a size greater
than the original size doesn't need the truncate, the same result can be
obtained by doing the extend directly on the original value.
Rearrange the inputs (src & orig_type) to bypass the unneeded operation.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'simplify.c')
| -rw-r--r-- | simplify.c | 5 |
1 files changed, 4 insertions, 1 deletions
@@ -1015,7 +1015,10 @@ static int simplify_cast(struct instruction *insn) osize = def->orig_type->bit_size; if (size == osize) return replace_with_pseudo(insn, def->src); - break; + if (size > osize) + insn->opcode = def->opcode; + insn->orig_type = def->orig_type; + return replace_pseudo(insn, &insn->src, def->src); } break; } |
