Fix handling of jumps in bugpoint (#5794)

Fixes #5792
This commit is contained in:
Trevor Elliott
2023-02-15 15:07:03 -08:00
committed by GitHub
parent 76539ef9f2
commit aba239e9b8

View File

@@ -709,32 +709,31 @@ impl Mutator for MergeBlocks {
let pred = cfg.pred_iter(block).next().unwrap(); let pred = cfg.pred_iter(block).next().unwrap();
// If the branch instruction that lead us to this block is preceded by another branch // If the branch instruction that lead us to this block wasn't an unconditional jump, then
// instruction, then we have a conditional jump sequence that we should not break by // we have a conditional jump sequence that we should not break.
// replacing the second instruction by more of them. let branch_dests = func.dfg.insts[pred.inst].branch_destination();
if let Some(pred_pred_inst) = func.layout.prev_inst(pred.inst) { if branch_dests.len() != 1 {
if func.dfg.insts[pred_pred_inst].opcode().is_branch() { return Some((
return Some(( func,
func, format!("did nothing for {}", block),
format!("did nothing for {}", block), ProgressStatus::Skip,
ProgressStatus::Skip, ));
));
}
} }
assert!(func.dfg.block_params(block).len() == func.dfg.inst_variable_args(pred.inst).len()); let branch_args = branch_dests[0].args_slice(&func.dfg.value_lists).to_vec();
// If there were any block parameters in block, then the last instruction in pred will // TODO: should we free the entity list associated with the block params?
// fill these parameters. Make the block params aliases of the terminator arguments. let block_params = func
for (block_param, arg) in func
.dfg .dfg
.detach_block_params(block) .detach_block_params(block)
.as_slice(&func.dfg.value_lists) .as_slice(&func.dfg.value_lists)
.iter() .to_vec();
.cloned()
.zip(func.dfg.inst_variable_args(pred.inst).iter().cloned()) assert_eq!(block_params.len(), branch_args.len());
.collect::<Vec<_>>()
{ // If there were any block parameters in block, then the last instruction in pred will
// fill these parameters. Make the block params aliases of the terminator arguments.
for (block_param, arg) in block_params.into_iter().zip(branch_args) {
if block_param != arg { if block_param != arg {
func.dfg.change_to_alias(block_param, arg); func.dfg.change_to_alias(block_param, arg);
} }