Fix "Some cleanup of cfopt."
authorAndreas Zwinkau <zwinkau@kit.edu>
Tue, 31 May 2011 08:50:49 +0000 (10:50 +0200)
committerAndreas Zwinkau <zwinkau@kit.edu>
Tue, 31 May 2011 08:50:49 +0000 (10:50 +0200)
The remove_empty_blocks function must be used for a pre-walker, otherwise
it might be called on blocks, which were optimized away. Consider infinite
loops and the Keep edges:

  \ ___
   B   |
    \  /
    Empty
    /
   / Keep Edge!

In this example, we must not call remove_empty_blocks on Empty,
after we called it on B, but a post walker would do that.

ir/opt/cfopt.c

index d833f8f..71cfc7d 100644 (file)
@@ -681,7 +681,7 @@ static void optimize_ifs(ir_node *block, void *x)
 }
 
 /**
 }
 
 /**
- * Post-Block walker: remove empty blocks that are
+ * Pre-Block walker: remove empty blocks that are
  * predecessors of the current block.
  */
 static void remove_empty_blocks(ir_node *block, void *x)
  * predecessors of the current block.
  */
 static void remove_empty_blocks(ir_node *block, void *x)
@@ -731,7 +731,7 @@ static void cfgopt_ignoring_phis(ir_graph *irg) {
                irg_block_walk_graph(irg, NULL, optimize_ifs, &env);
 
                /* Remove empty blocks */
                irg_block_walk_graph(irg, NULL, optimize_ifs, &env);
 
                /* Remove empty blocks */
-               irg_block_walk_graph(irg, NULL, remove_empty_blocks, &env);
+               irg_block_walk_graph(irg, remove_empty_blocks, NULL, &env);
                if (env.changed) {
                        set_irg_doms_inconsistent(irg);
                        /* Removing blocks might enable more Cond optimizations */
                if (env.changed) {
                        set_irg_doms_inconsistent(irg);
                        /* Removing blocks might enable more Cond optimizations */