fix backend Cond/Cmp flag optimization failing for unoptimized code
[libfirm] / ir / opt / ifconv.c
index 04502fc..22ab6f0 100644 (file)
@@ -21,7 +21,6 @@
  * @file    ir/opt/ifconv.c
  * @brief   If conversion
  * @author  Christoph Mallon
- * @version $Id$
  */
 #include "config.h"
 
@@ -40,6 +39,7 @@
 #include "array_t.h"
 #include "irpass_t.h"
 #include "be.h"
+#include "opt_manage.h"
 
 #include "irdump.h"
 #include "debug.h"
@@ -52,7 +52,7 @@ typedef struct walker_env {
        bool                   changed; /**< Set if the graph was changed. */
 } walker_env;
 
-DEBUG_ONLY(static firm_dbg_module_t *dbg);
+DEBUG_ONLY(static firm_dbg_module_t *dbg;)
 
 /**
  * Returns non-zero if a Block can be emptied.
@@ -283,6 +283,8 @@ restart:
                ir_cdep* cdep;
 
                pred0 = get_Block_cfgpred_block(block, i);
+               if (pred0 == block) continue;
+
                for (cdep = find_cdep(pred0); cdep != NULL; cdep = get_cdep_next(cdep)) {
                        const ir_node* dependency = get_cdep_node(cdep);
                        ir_node* projx0 = walk_to_projx(pred0, dependency);
@@ -310,6 +312,7 @@ restart:
                                dbg_info* cond_dbg;
 
                                pred1 = get_Block_cfgpred_block(block, j);
+                               if (pred1 == block) continue;
 
                                if (!is_cdep_on(pred1, dependency)) continue;
 
@@ -461,7 +464,7 @@ static void collect_phis(ir_node *node, void *env)
        }
 }
 
-void opt_if_conv(ir_graph *irg)
+static ir_graph_state_t do_ifconv(ir_graph *irg)
 {
        walker_env            env;
        const backend_params *be_params = be_get_backend_param();
@@ -474,9 +477,6 @@ void opt_if_conv(ir_graph *irg)
 
        DB((dbg, LEVEL_1, "Running if-conversion on %+F\n", irg));
 
-       normalize_one_return(irg);
-       remove_critical_cf_edges(irg);
-
        compute_cdep(irg);
 
        ir_reserve_resources(irg, IR_RESOURCE_BLOCK_MARK | IR_RESOURCE_PHI_LIST);
@@ -489,15 +489,22 @@ void opt_if_conv(ir_graph *irg)
 
        if (env.changed) {
                local_optimize_graph(irg);
-
-               /* graph has changed, invalidate analysis info */
-               set_irg_outs_inconsistent(irg);
-               set_irg_extblk_inconsistent(irg);
-               set_irg_loopinfo_inconsistent(irg);
-               set_irg_doms_inconsistent(irg);
        }
 
        free_cdep(irg);
+
+       return IR_GRAPH_STATE_NO_CRITICAL_EDGES | IR_GRAPH_STATE_ONE_RETURN;
+}
+
+static optdesc_t opt_ifconv = {
+       "if-conversion",
+       IR_GRAPH_STATE_NO_CRITICAL_EDGES | IR_GRAPH_STATE_NO_UNREACHABLE_CODE | IR_GRAPH_STATE_NO_BADS | IR_GRAPH_STATE_ONE_RETURN,
+       do_ifconv,
+};
+
+void opt_if_conv(ir_graph *irg)
+{
+       perform_irg_optimization(irg, &opt_ifconv);
 }
 
 ir_graph_pass_t *opt_if_conv_pass(const char *name)