Commit 76396f2c authored by Christoph Mallon's avatar Christoph Mallon
Browse files

tv: Add and use tarval_in_range().

parent 4c9a1e2c
......@@ -3695,11 +3695,7 @@ static ir_node *transform_node_Switch(ir_node *n)
if (entry->pn == 0)
continue;
ir_tarval *min = entry->min;
ir_tarval *max = entry->max;
if ((min == max && min == val)
|| (tarval_cmp(val, min) != ir_relation_less
&& tarval_cmp(val, max) != ir_relation_greater)) {
if (tarval_in_range(entry->min, val, entry->max)) {
jmp_pn = entry->pn;
break;
}
......
......@@ -2180,29 +2180,14 @@ static void compute_Proj_Switch(node_t *node, ir_node *switchn)
} else {
ir_node *proj = node->node;
long pnc = get_Proj_proj(proj);
long value = get_tarval_long(selector->type.tv);
const ir_switch_table *table = get_Switch_table(switchn);
size_t n_entries = ir_switch_table_get_n_entries(table);
for (size_t e = 0; e < n_entries; ++e) {
const ir_switch_table_entry *entry
= ir_switch_table_get_entry_const(table, e);
ir_tarval *min = entry->min;
ir_tarval *max = entry->max;
if (min == max) {
if (selector->type.tv == min) {
node->type.tv = entry->pn == pnc
? tarval_top : tarval_bottom;
return;
}
} else {
long minval = get_tarval_long(min);
long maxval = get_tarval_long(max);
if (minval <= value && value <= maxval) {
node->type.tv = entry->pn == pnc
? tarval_top : tarval_bottom;
return;
}
ir_switch_table_entry const *const entry = ir_switch_table_get_entry_const(table, e);
if (tarval_in_range(entry->min, selector->type.tv, entry->max)) {
node->type.tv = entry->pn == pnc ? tarval_top : tarval_bottom;
return;
}
}
......
......@@ -1613,3 +1613,15 @@ int (is_tarval)(const void *thing)
{
return is_tarval_(thing);
}
bool tarval_in_range(ir_tarval const *const min, ir_tarval const *const val, ir_tarval const *const max)
{
assert(tarval_cmp(min, max) & ir_relation_less_equal);
assert(!tarval_is_nan(val));
/* Shortcuts. */
if (val == min)
return true;
if (min == max)
return false;
return tarval_cmp(min, val) & ir_relation_less_equal && tarval_cmp(val, max) & ir_relation_less_equal;
}
......@@ -138,4 +138,6 @@ static inline unsigned get_tarval_bit(ir_tarval const *const tv, unsigned const
return tv->value[idx / SC_BITS] >> (idx % SC_BITS) & 1;
}
bool tarval_in_range(ir_tarval const *min, ir_tarval const *val, ir_tarval const *max);
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment