- else if (get_irn_op(pred) == op_Store && get_Store_ptr(pred) == ptr &&
- get_irn_mode(get_Store_value(pred)) == load_mode) {
- /*
- * a load immediately after a store -- a read after write.
- * We may remove the Load, if it does not have an exception handler
- * OR they are in the same block. In the latter case the Load cannot
- * throw an exception when the previous Store was quiet.
- */
- if (! info->projs[pn_Load_X_except] || get_nodes_block(load) == get_nodes_block(pred)) {
- exchange( info->projs[pn_Load_res], get_Store_value(pred) );
- if (info->projs[pn_Load_M])
- exchange(info->projs[pn_Load_M], mem);
-
- /* no exception */
- if (info->projs[pn_Load_X_except])
- exchange( info->projs[pn_Load_X_except], new_Bad());
+
+ /* the mem of the Load. Must still be returned after optimization */
+ mem = get_Load_mem(load);
+
+ /* check if we can determine the entity that will be loaded */
+ ent = find_constant_entity(ptr);
+ if (ent) {
+ 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
+ * when loading. */
+
+ /* no exception, clear the info field as it might be checked later again */
+ if (info->projs[pn_Load_X_except]) {
+ exchange(info->projs[pn_Load_X_except], new_Bad());
+ info->projs[pn_Load_X_except] = NULL;
+ }
+
+ if (variability_constant == get_entity_variability(ent)
+ && is_atomic_entity(ent)) { /* Might not be atomic after
+ lowering of Sels. In this
+ case we could also load, but
+ it's more complicated. */
+ /* more simpler case: we load the content of a constant value:
+ * replace it by the constant itself
+ */
+
+ /* no memory */
+ if (info->projs[pn_Load_M])
+ exchange(info->projs[pn_Load_M], mem);
+
+ /* no result :-) */
+ if (info->projs[pn_Load_res]) {
+ if (is_atomic_entity(ent)) {
+ ir_node *c = copy_const_value(get_atomic_ent_value(ent));
+
+ DBG_OPT_RC(load, c);
+ exchange(info->projs[pn_Load_res], c);
+
+ return 1;
+ }
+ }
+ }
+ else if (variability_constant == get_entity_variability(ent)) {
+ printf(">>>>>>>>>>>>> Found access to constant entity %s in function %s\n", get_entity_name(ent),
+ get_entity_name(get_irg_entity(current_ir_graph)));
+ }
+
+ /* we changed the irg, but try further */