- left = get_Add_left(node);
- right = get_Add_right(node);
- /* if we can do source address mode then we will never fold the add
- * into address mode */
- if(is_immediate_simple(right) ||
- (!use_source_address_mode(get_nodes_block(node), left, right)
- && !use_source_address_mode(get_nodes_block(node), right, left))) {
- break;
+ /* only 1 user: AM folding is always beneficial */
+ if(get_irn_n_edges(node) <= 1)
+ break;
+
+ /* for adds and shls with multiple users we use this heuristic:
+ * we do not fold them into address mode if their operands don't live
+ * out of the block, because in this case we will reduce register
+ * pressure. Otherwise we fold them in aggressively in the hope, that
+ * the node itself doesn't exist anymore and we were able to save the
+ * register for the result */
+ left = get_binop_left(node);
+ right = get_binop_right(node);
+
+ /* Fold AM if any of the two operands does not die here. This duplicates
+ * an addition and has the same register pressure for the case that only
+ * one operand dies, but is faster (on Pentium 4).
+ * && instead of || only folds AM if both operands do not die here */
+ if (!value_last_used_here(node, left) ||
+ !value_last_used_here(node, right)) {
+ return;