Commit 39777374 authored by Christoph Mallon's avatar Christoph Mallon
Browse files

Remove classify_Const() and replace it by is_Const_{null,one,all_one}().

[r15842]
parent 118c38b6
......@@ -463,27 +463,14 @@ int get_Return_n_ress(ir_node *node);
ir_node *get_Return_res(ir_node *node, int pos);
void set_Return_res(ir_node *node, int pos, ir_node *res);
/**
* Possible classes for constant classification.
*/
typedef enum {
CNST_NULL = 0, /**< The node is a const(0). */
CNST_ONE = +1, /**< The node is a const(1). */
CNST_ALL_ONE = -1, /**< The node is a const(11111...). */
CNST_OTHER = 2, /**< The tarval of the const has another value. */
CNST_SYMCONST = 3, /**< The node is symconst. */
CNST_NO_CONST = 4 /**< The node is no const at all. */
} cnst_classify_t;
tarval *get_Const_tarval(const ir_node *node);
void set_Const_tarval(ir_node *node, tarval *con);
/**
* Classify a node concerning constant properties.
* @param irn A node to check for.
* @return Constant properties of that node.
*/
cnst_classify_t classify_Const(ir_node *irn);
int is_Const_null(const ir_node *node);
int is_Const_one(const ir_node *node);
int is_Const_all_one(const ir_node *node);
/** Returns the source language type of a Const node.
* Must be an atomic type. Mode of type must be mode of node.
......
......@@ -222,17 +222,11 @@ static ir_entity *ia32_get_entity_for_tv(ia32_isa_t *isa, ir_node *cnst)
}
static int is_Const_0(ir_node *node) {
if(!is_Const(node))
return 0;
return classify_Const(node) == CNST_NULL;
return is_Const(node) && is_Const_null(node);
}
static int is_Const_1(ir_node *node) {
if(!is_Const(node))
return 0;
return classify_Const(node) == CNST_ONE;
return is_Const(node) && is_Const_one(node);
}
static int is_Const_Minus_1(ir_node *node) {
......@@ -267,10 +261,9 @@ static ir_node *gen_Const(ir_node *node) {
ir_node *nomem = new_NoMem();
ir_node *load;
ir_entity *floatent;
cnst_classify_t clss = classify_Const(node);
if (USE_SSE2(env_cg)) {
if (clss == CNST_NULL) {
if (is_Const_null(node)) {
load = new_rd_ia32_xZero(dbgi, irg, block);
set_ia32_ls_mode(load, mode);
res = load;
......@@ -285,10 +278,10 @@ static ir_node *gen_Const(ir_node *node) {
res = new_r_Proj(irg, block, load, mode_xmm, pn_ia32_xLoad_res);
}
} else {
if (clss == CNST_NULL) {
if (is_Const_null(node)) {
load = new_rd_ia32_vfldz(dbgi, irg, block);
res = load;
} else if (clss == CNST_ONE) {
} else if (is_Const_one(node)) {
load = new_rd_ia32_vfld1(dbgi, irg, block);
res = load;
} else {
......
......@@ -1087,8 +1087,16 @@ set_Const_tarval(ir_node *node, tarval *con) {
node->attr.con.tv = con;
}
cnst_classify_t (classify_Const)(ir_node *node) {
return _classify_Const(node);
int (is_Const_null)(const ir_node *node) {
return _is_Const_null(node);
}
int (is_Const_one)(const ir_node *node) {
return _is_Const_one(node);
}
int (is_Const_all_one)(const ir_node *node) {
return _is_Const_all_one(node);
}
......
......@@ -766,22 +766,16 @@ static INLINE tarval *_get_Const_tarval(const ir_node *node) {
return node->attr.con.tv;
}
static INLINE cnst_classify_t _classify_Const(ir_node *node) {
ir_op *op;
assert(_is_ir_node(node));
op = _get_irn_op(node);
static INLINE int _is_Const_null(const ir_node *node) {
return tarval_is_null(_get_Const_tarval(node));
}
if (op == op_Const) {
tarval *tv = _get_Const_tarval(node);
if (tarval_is_null(tv)) return CNST_NULL;
if (tarval_is_one(tv)) return CNST_ONE;
if (tarval_is_all_one(tv)) return CNST_ALL_ONE;
return CNST_OTHER;
} else if(op == op_SymConst)
return CNST_SYMCONST;
static INLINE int _is_Const_one(const ir_node *node) {
return tarval_is_one(_get_Const_tarval(node));
}
return CNST_NO_CONST;
static INLINE int _is_Const_all_one(const ir_node *node) {
return tarval_is_all_one(_get_Const_tarval(node));
}
static INLINE int _is_irn_forking(const ir_node *node) {
......@@ -944,7 +938,9 @@ static INLINE void _set_irn_dbg_info(ir_node *n, dbg_info *db) {
#define set_Block_dead(block) _set_Block_dead(block)
#define is_Block_dead(block) _is_Block_dead(block)
#define get_Const_tarval(node) _get_Const_tarval(node)
#define classify_Const(node) _classify_Const(node)
#define is_Const_null(node) _is_Const_null(node)
#define is_Const_one(node) _is_Const_one(node)
#define is_Const_all_one(node) _is_Const_all_one(node)
#define is_irn_forking(node) _is_irn_forking(node)
#define get_irn_type(node) _get_irn_type(node)
#define get_irn_type_attr(node) _get_irn_type_attr(node)
......
......@@ -1457,7 +1457,8 @@ static ir_node *equivalent_node_Mux(ir_node *n)
* However, if +0 and -0 is handled differently, we cannot use the first one.
*/
if (get_irn_op(cmp) == op_Cmp && get_Cmp_left(cmp) == a) {
if (classify_Const(get_Cmp_right(cmp)) == CNST_NULL) {
ir_node *cmp_r = get_Cmp_right(cmp);
if (is_Const(cmp_r) && is_Const_null(cmp_r)) {
/* Mux(a CMP 0, X, a) */
if (get_irn_op(b) == op_Minus && get_Minus_op(b) == a) {
/* Mux(a CMP 0, -a, a) */
......@@ -1470,7 +1471,7 @@ static ir_node *equivalent_node_Mux(ir_node *n)
n = a;
DBG_OPT_ALGSIM0(oldn, n, FS_OPT_MUX_TRANSFORM);
}
} else if (classify_Const(b) == CNST_NULL) {
} else if (is_Const(b) && is_Const_null(b)) {
/* Mux(a CMP 0, 0, a) */
if (proj_nr == pn_Cmp_Lg || proj_nr == pn_Cmp_Ne) {
/* Mux(a != 0, 0, a) ==> a */
......@@ -2018,7 +2019,7 @@ static ir_node *transform_node_Add(ir_node *n) {
if (is_Not(a)) {
ir_node *op = get_Not_op(a);
if (classify_Const(b) == CNST_ONE) {
if (is_Const(b) && is_Const_one(b)) {
/* ~x + 1 = -x */
ir_node *blk = get_irn_n(n, -1);
n = new_rd_Minus(get_irn_dbg_info(n), current_ir_graph, blk, op, mode);
......@@ -2162,7 +2163,7 @@ restart:
}
/* Beware of Sub(P, P) which cannot be optimized into a simple Minus ... */
if (mode_is_num(mode) && mode == get_irn_mode(a) && (classify_Const(a) == CNST_NULL)) {
if (mode_is_num(mode) && mode == get_irn_mode(a) && is_Const(a) && is_Const_null(a)) {
n = new_rd_Minus(
get_irn_dbg_info(n),
current_ir_graph,
......@@ -3090,12 +3091,15 @@ static ir_node *transform_node_Not(ir_node *n) {
DBG_OPT_ALGSIM0(oldn, n, FS_OPT_NOT_CMP);
return n;
}
if (op_a == op_Sub && classify_Const(get_Sub_right(a)) == CNST_ONE) {
/* ~(x-1) = -x */
ir_node *op = get_Sub_left(a);
ir_node *blk = get_irn_n(n, -1);
n = new_rd_Minus(get_irn_dbg_info(n), current_ir_graph, blk, op, get_irn_mode(n));
DBG_OPT_ALGSIM0(oldn, n, FS_OPT_NOT_MINUS_1);
if (op_a == op_Sub) {
ir_node *sub_r = get_Sub_right(a);
if (is_Const(sub_r) && is_Const_one(sub_r)) {
/* ~(x-1) = -x */
ir_node *op = get_Sub_left(a);
ir_node *blk = get_irn_n(n, -1);
n = new_rd_Minus(get_irn_dbg_info(n), current_ir_graph, blk, op, get_irn_mode(n));
DBG_OPT_ALGSIM0(oldn, n, FS_OPT_NOT_MINUS_1);
}
}
return n;
} /* transform_node_Not */
......@@ -4309,77 +4313,79 @@ static ir_node *transform_node_Mux(ir_node *n) {
* However, if +0 and -0 is handled differently, we cannot use the first
* one.
*/
if (get_irn_op(cmp) == op_Cmp
&& classify_Const(get_Cmp_right(cmp)) == CNST_NULL) {
ir_node *block = get_irn_n(n, -1);
if(is_negated_value(f, t)) {
ir_node *cmp_left = get_Cmp_left(cmp);
/* Psi(a >= 0, a, -a) = Psi(a <= 0, -a, a) ==> Abs(a) */
if ( (cmp_left == t && (pn == pn_Cmp_Ge || pn == pn_Cmp_Gt))
|| (cmp_left == f && (pn == pn_Cmp_Le || pn == pn_Cmp_Lt)))
{
n = new_rd_Abs(get_irn_dbg_info(n), current_ir_graph, block,
cmp_left, mode);
DBG_OPT_ALGSIM1(oldn, cmp, sel, n, FS_OPT_MUX_TO_ABS);
return n;
/* Psi(a <= 0, a, -a) = Psi(a >= 0, -a, a) ==> -Abs(a) */
} else if ((cmp_left == t && (pn == pn_Cmp_Le || pn == pn_Cmp_Lt))
|| (cmp_left == f && (pn == pn_Cmp_Ge || pn == pn_Cmp_Gt)))
{
n = new_rd_Abs(get_irn_dbg_info(n), current_ir_graph, block,
cmp_left, mode);
n = new_rd_Minus(get_irn_dbg_info(n), current_ir_graph,
block, n, mode);
DBG_OPT_ALGSIM1(oldn, cmp, sel, n, FS_OPT_MUX_TO_ABS);
return n;
if (is_Cmp(cmp)) {
ir_node *cmp_r = get_Cmp_right(cmp);
if (is_Const(cmp_r) && is_Const_null(cmp_r)) {
ir_node *block = get_irn_n(n, -1);
if(is_negated_value(f, t)) {
ir_node *cmp_left = get_Cmp_left(cmp);
/* Psi(a >= 0, a, -a) = Psi(a <= 0, -a, a) ==> Abs(a) */
if ( (cmp_left == t && (pn == pn_Cmp_Ge || pn == pn_Cmp_Gt))
|| (cmp_left == f && (pn == pn_Cmp_Le || pn == pn_Cmp_Lt)))
{
n = new_rd_Abs(get_irn_dbg_info(n), current_ir_graph, block,
cmp_left, mode);
DBG_OPT_ALGSIM1(oldn, cmp, sel, n, FS_OPT_MUX_TO_ABS);
return n;
/* Psi(a <= 0, a, -a) = Psi(a >= 0, -a, a) ==> -Abs(a) */
} else if ((cmp_left == t && (pn == pn_Cmp_Le || pn == pn_Cmp_Lt))
|| (cmp_left == f && (pn == pn_Cmp_Ge || pn == pn_Cmp_Gt)))
{
n = new_rd_Abs(get_irn_dbg_info(n), current_ir_graph, block,
cmp_left, mode);
n = new_rd_Minus(get_irn_dbg_info(n), current_ir_graph,
block, n, mode);
DBG_OPT_ALGSIM1(oldn, cmp, sel, n, FS_OPT_MUX_TO_ABS);
return n;
}
}
}
if (mode_is_int(mode) && mode_is_signed(mode) &&
get_mode_arithmetic(mode) == irma_twos_complement) {
ir_node *x = get_Cmp_left(cmp);
if (mode_is_int(mode) && mode_is_signed(mode) &&
get_mode_arithmetic(mode) == irma_twos_complement) {
ir_node *x = get_Cmp_left(cmp);
/* the following optimization works only with signed integer two-complement mode */
/* the following optimization works only with signed integer two-complement mode */
if (mode == get_irn_mode(x)) {
/*
* FIXME: this restriction is two rigid, as it would still
* work if mode(x) = Hs and mode == Is, but at least it removes
* all wrong cases.
*/
if ((pn == pn_Cmp_Lt || pn == pn_Cmp_Le) &&
classify_Const(t) == CNST_ALL_ONE &&
classify_Const(f) == CNST_NULL) {
if (mode == get_irn_mode(x)) {
/*
* Mux(x:T </<= 0, 0, -1) -> Shrs(x, sizeof_bits(T) - 1)
* Conditions:
* T must be signed.
* FIXME: this restriction is two rigid, as it would still
* work if mode(x) = Hs and mode == Is, but at least it removes
* all wrong cases.
*/
n = new_rd_Shrs(get_irn_dbg_info(n),
current_ir_graph, block, x,
if ((pn == pn_Cmp_Lt || pn == pn_Cmp_Le) &&
is_Const(t) && is_Const_all_one(t) &&
is_Const(f) && is_Const_null(f)) {
/*
* Mux(x:T </<= 0, 0, -1) -> Shrs(x, sizeof_bits(T) - 1)
* Conditions:
* T must be signed.
*/
n = new_rd_Shrs(get_irn_dbg_info(n),
current_ir_graph, block, x,
new_r_Const_long(current_ir_graph, block, mode_Iu,
get_mode_size_bits(mode) - 1),
mode);
DBG_OPT_ALGSIM1(oldn, cmp, sel, n, FS_OPT_MUX_TO_SHR);
return n;
} else if ((pn == pn_Cmp_Gt || pn == pn_Cmp_Ge) &&
is_Const(t) && is_Const_one(t) &&
is_Const(f) && is_Const_null(f)) {
/*
* Mux(x:T >/>= 0, 0, 1) -> Shr(-x, sizeof_bits(T) - 1)
* Conditions:
* T must be signed.
*/
n = new_rd_Shr(get_irn_dbg_info(n),
current_ir_graph, block,
new_r_Minus(current_ir_graph, block, x, mode),
new_r_Const_long(current_ir_graph, block, mode_Iu,
get_mode_size_bits(mode) - 1),
mode);
DBG_OPT_ALGSIM1(oldn, cmp, sel, n, FS_OPT_MUX_TO_SHR);
return n;
} else if ((pn == pn_Cmp_Gt || pn == pn_Cmp_Ge) &&
classify_Const(t) == CNST_ONE &&
classify_Const(f) == CNST_NULL) {
/*
* Mux(x:T >/>= 0, 0, 1) -> Shr(-x, sizeof_bits(T) - 1)
* Conditions:
* T must be signed.
*/
n = new_rd_Shr(get_irn_dbg_info(n),
current_ir_graph, block,
new_r_Minus(current_ir_graph, block, x, mode),
new_r_Const_long(current_ir_graph, block, mode_Iu,
get_mode_size_bits(mode) - 1),
mode);
DBG_OPT_ALGSIM1(oldn, cmp, sel, n, FS_OPT_MUX_TO_SHR);
return n;
DBG_OPT_ALGSIM1(oldn, cmp, sel, n, FS_OPT_MUX_TO_SHR);
return n;
}
}
}
}
......
......@@ -214,9 +214,10 @@ static ir_node *lower_node(ir_node *node)
ir_node *right = get_Cmp_right(pred);
ir_mode *mode = get_irn_mode(left);
if( (mode_is_int(mode) || mode_is_reference(mode)) &&
(get_mode_size_bits(mode) < get_mode_size_bits(lowered_mode)
|| classify_Const(right) == CNST_NULL)) {
if ((mode_is_int(mode) || mode_is_reference(mode)) && (
get_mode_size_bits(mode) < get_mode_size_bits(lowered_mode) ||
(is_Const(right) && is_Const_null(right))
)) {
int pnc = get_Proj_proj(node);
int need_not = 0;
ir_node *a = NULL;
......
......@@ -190,10 +190,12 @@ int value_not_null(ir_node *n, ir_node **confirm) {
return 1;
} else {
for (; is_Confirm(n); n = skip_Cast(get_Confirm_value(n))) {
if (get_Confirm_cmp(n) == pn_Cmp_Lg &&
classify_Const(get_Confirm_bound(n)) == CNST_NULL) {
if (get_Confirm_cmp(n) != pn_Cmp_Lg) {
ir_node *bound = get_Confirm_bound(n);
if (is_Const(bound) && is_Const_null(bound)) {
*confirm = n;
return 1;
}
}
}
}
......
Markdown is supported
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