diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2004-11-29 13:52:14 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-07 21:05:16 -0700 |
commit | 19903f1a69a4ebd0e6de92dc926b309e5ed87b3a (patch) | |
tree | 2f54baf7e6451adc9be2d35fca0cc0e1753df191 /simplify.c | |
parent | Be more forgiving about missing types in linearization. (diff) | |
download | sparse-19903f1a69a4ebd0e6de92dc926b309e5ed87b3a.tar.gz sparse-19903f1a69a4ebd0e6de92dc926b309e5ed87b3a.tar.bz2 sparse-19903f1a69a4ebd0e6de92dc926b309e5ed87b3a.zip |
Simplify trivial casts (and handle pointers specially).
This does trivial simplification of casting to the same
typesize. HOWEVER. We split casts up into whether they
cast to a dereferencable pointer type or not, and we don't
simplify pointer casts. This should mean that if we
ever want to do type-based alias analysis, we can still
avoid casted accesses.
(If we do type-based alias analysis, we'll also need to make
a union access do a cast. Which we probably should do anyway).
Diffstat (limited to 'simplify.c')
-rw-r--r-- | simplify.c | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -454,6 +454,22 @@ offset: return REPEAT_CSE | REPEAT_SYMBOL_CLEANUP; } +static int simplify_cast(struct instruction *insn) +{ + int orig_size; + + if (dead_insn(insn, &insn->src, NULL)) + return REPEAT_CSE; + if (insn->opcode == OP_PTRCAST) + return 0; + orig_size = insn->orig_type ? insn->orig_type->bit_size : 0; + if (orig_size < 0) + orig_size = 0; + if (insn->size != orig_size) + return 0; + return replace_with_pseudo(insn, insn->src); +} + int simplify_instruction(struct instruction *insn) { pseudo_t cond; @@ -476,6 +492,9 @@ int simplify_instruction(struct instruction *insn) if (dead_insn(insn, NULL, NULL)) return REPEAT_CSE | REPEAT_SYMBOL_CLEANUP; break; + case OP_PTRCAST: + case OP_CAST: + return simplify_cast(insn); case OP_PHI: if (dead_insn(insn, NULL, NULL)) { clear_phi(insn); |