diff options
author | 2004-12-05 13:52:59 -0700 | |
---|---|---|
committer | 2005-04-07 21:05:34 -0700 | |
commit | 08778dab216796220717960736d78f4c6b570eae (patch) | |
tree | a0fdddb3b4c2deb8073e34734848dc4802856ef7 /simplify.c | |
parent | Fix inlining of STMT_ASM. (diff) | |
download | sparse-08778dab216796220717960736d78f4c6b570eae.tar.gz sparse-08778dab216796220717960736d78f4c6b570eae.tar.bz2 sparse-08778dab216796220717960736d78f4c6b570eae.zip |
Simplify constant unops
Diffstat (limited to 'simplify.c')
-rw-r--r-- | simplify.c | 19 |
1 files changed, 18 insertions, 1 deletions
@@ -393,7 +393,24 @@ static int simplify_binop(struct instruction *insn) static int simplify_constant_unop(struct instruction *insn) { - return 0; + long long val = insn->src1->value; + long long res, mask; + + switch (insn->opcode) { + case OP_NOT: + res = ~val; + break; + case OP_NEG: + res = -val; + break; + default: + return 0; + } + mask = 1ULL << (insn->size-1); + res &= mask | (mask-1); + + replace_with_pseudo(insn, value_pseudo(res)); + return REPEAT_CSE; } static int simplify_unop(struct instruction *insn) |