aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2004-12-05 13:52:59 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-07 21:05:34 -0700
commit08778dab216796220717960736d78f4c6b570eae (patch)
treea0fdddb3b4c2deb8073e34734848dc4802856ef7 /simplify.c
parentFix inlining of STMT_ASM. (diff)
downloadsparse-08778dab216796220717960736d78f4c6b570eae.tar.gz
sparse-08778dab216796220717960736d78f4c6b570eae.tar.bz2
sparse-08778dab216796220717960736d78f4c6b570eae.zip
Simplify constant unops
Diffstat (limited to 'simplify.c')
-rw-r--r--simplify.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/simplify.c b/simplify.c
index 1af115d..2d14b9d 100644
--- a/simplify.c
+++ b/simplify.c
@@ -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)