Commit 1e7ccff0 authored by Michael Beck's avatar Michael Beck
Browse files

- can handle some hidden reinterpret casts when doing const load replacement

[r22099]
parent e40b97bd
......@@ -468,4 +468,11 @@ ir_mode *get_reference_mode_unsigned_eq(ir_mode *mode);
*/
void set_reference_mode_unsigned_eq(ir_mode *ref_mode, ir_mode *int_mode);
/**
* Returns non-zero if the cast from mode src to mode dst is a
* reinterpret cast (ie. only the bit pattern is reinterpreted,
* no conversion is done)
*/
int is_reinterpret_cast(const ir_mode *src, const ir_mode *dst);
#endif
......@@ -907,6 +907,25 @@ int mode_wrap_around(const ir_mode *mode) {
return mode_is_int(mode);
}
/*
* Returns non-zero if the cast from mode src to mode dst is a
* reinterpret cast (ie. only the bit pattern is reinterpreted,
* no conversion is done)
*/
int is_reinterpret_cast(const ir_mode *src, const ir_mode *dst) {
ir_mode_arithmetic ma;
if (src == dst)
return 1;
if (get_mode_size_bits(src) != get_mode_size_bits(dst))
return 0;
ma = get_mode_arithmetic(src);
if (ma != get_mode_arithmetic(dst))
return 0;
return ma == irma_twos_complement || ma == irma_ones_complement;
}
void finish_mode(void) {
obstack_free(&modes, 0);
DEL_ARR_F(mode_list);
......
......@@ -1052,7 +1052,7 @@ static unsigned optimize_load(ir_node *load)
/* check if we can determine the entity that will be loaded */
ent = find_constant_entity(ptr);
if (ent) {
if (ent != NULL) {
if ((allocation_static == get_entity_allocation(ent)) &&
(visibility_external_allocated != get_entity_visibility(ent))) {
/* a static allocation that is not external: there should be NO exception
......@@ -1114,13 +1114,36 @@ static unsigned optimize_load(ir_node *load)
free_compound_graph_path(path);
}
}
if (c != NULL) {
/* check, if the mode matches OR can be easily converted info */
ir_mode *c_mode = get_irn_mode(c);
ir_mode *l_mode = get_Load_mode(load);
if (c_mode != l_mode) {
if (is_reinterpret_cast(c_mode, l_mode)) {
/* we can safely cast */
dbg_info *dbg = get_irn_dbg_info(load);
ir_node *block = get_nodes_block(load);
/* copy the value from the const code irg and cast it */
c = copy_const_value(dbg, c);
c = new_rd_Conv(dbg, current_ir_graph, block, c, l_mode);
} else {
/* must be some operation */
c = NULL;
}
} else {
/* copy the value from the const code irg */
c = copy_const_value(get_irn_dbg_info(load), c);
}
}
if (c != NULL) {
if (info->projs[pn_Load_M]) {
exchange(info->projs[pn_Load_M], mem);
res |= DF_CHANGED;
}
if (info->projs[pn_Load_res]) {
exchange(info->projs[pn_Load_res], copy_const_value(get_irn_dbg_info(load), c));
exchange(info->projs[pn_Load_res], c);
res |= DF_CHANGED;
}
kill_node(load);
......
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