so i'm working at the cfg level. I create a new block. Redirect blocks. Introduce a new switch statement and insert it in the new block. Before exiting from the my plugin, i print out all stmts from all blocks and my switch is seemingly there too. However at the end of my compilation it's been removed and goes with it a whole bunch of other blocks and their stmts. Could someone tell me what am i missing in the process of adding this switch? gimple_seq new_bb_seq = bb_seq(new_bb); stmt = gimple_build_assign(switch_index, build_int_cst(NULL, 0)); gimple_seq_add_stmt(&new_bb_seq, stmt); switch_stmt = gimple_build_switch_vec(switch_index, default_label, new_case_labels); gimple_seq_add_stmt(&new_bb_seq, switch_stmt); and this is how i build up my new case labels: case_label = build3(CASE_LABEL_EXPR, void_type_node, build_int_cst(NULL, i), NULL, gimple_block_label(bb)); VEC_quick_push(tree, new_case_labels, case_label); and the switch variable and its index are built this way: new_bb = create_empty_bb(ENTRY_BLOCK_PTR); new_bb_label = gimple_block_label (new_bb); new_case_labels = VEC_alloc (tree, heap, block_count); default_label = build3(CASE_LABEL_EXPR, void_type_node, NULL_TREE, NULL_TREE, create_artificial_label(UNKNOWN_LOCATION)); switch_index = create_tmp_var(integer_type_node, "sw_"); and at the end, i sandwich this block between entry and exit like this: redirect_edge_succ(single_succ_edge(ENTRY_BLOCK_PTR), new_bb); make_edge(new_bb, EXIT_BLOCK_PTR, EDGE_FALLTHRU); and if print the stmts in the new block as shown in the following, I see the listing at the bottom: for (gsi = gsi_start_bb(new_bb); !gsi_end_p(gsi); gsi_next(&gsi)) { gimple stmt = gsi_stmt(gsi); print_gimple_stmt(stdout, stmt, 8, 0); } ********* stmts in the new block ******** <L4>: sw_.1 = 2; switch (sw_.1) <default: <D.1973>, case 2: <L5>, case 3: <L6>, case 4: <L7>, case 5: L1> The following is taken from the veclower dump: <L3>: sw_.0 = 2; goto <bb 1>; The switch stmt is either gone or not shown. regardless, cleanup_cfg shows the following results: Removing basic block 9 Removing basic block 8 Removing basic block 7 Removing basic block 6 Removing basic block 5 Removing basic block 4 Removing basic block 3 f () { int sw_.1; int j; int i; int D.1970; <L4>: sw_.1 = 2; }