aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-02-04 18:51:16 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-07 21:06:21 -0700
commit6954ca7089ae0fa578b4fea8bdb8cb5a5a5b7315 (patch)
tree91a8b8dc9a275020cb398443fde2194a89834d31 /simplify.c
parentAdd compile-time "range-check" infrastructure to sparse (diff)
downloadsparse-6954ca7089ae0fa578b4fea8bdb8cb5a5a5b7315.tar.gz
sparse-6954ca7089ae0fa578b4fea8bdb8cb5a5a5b7315.tar.bz2
sparse-6954ca7089ae0fa578b4fea8bdb8cb5a5a5b7315.zip
Make range check code a bit more readable (and more easily extensible).
Diffstat (limited to 'simplify.c')
-rw-r--r--simplify.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/simplify.c b/simplify.c
index 96ad80e..b892da5 100644
--- a/simplify.c
+++ b/simplify.c
@@ -639,6 +639,19 @@ static int simplify_select(struct instruction *insn)
return 0;
}
+static int is_in_range(pseudo_t src, long long low, long long high)
+{
+ long long value;
+
+ switch (src->type) {
+ case PSEUDO_VAL:
+ value = src->value;
+ return value >= low && value <= high;
+ default:
+ return 0;
+ }
+}
+
static int simplify_range(struct instruction *insn)
{
pseudo_t src1, src2, src3;
@@ -648,11 +661,9 @@ static int simplify_range(struct instruction *insn)
src3 = insn->src3;
if (src2->type != PSEUDO_VAL || src2->type != PSEUDO_VAL)
return 0;
- if (src1->type == PSEUDO_VAL) {
- if (src1->value >= src2->value && src1->value <= src3->value) {
- kill_instruction(insn);
- return REPEAT_CSE;
- }
+ if (is_in_range(src1, src2->value, src3->value)) {
+ kill_instruction(insn);
+ return REPEAT_CSE;
}
return 0;
}