Remove unwrap() for branch folding

This commit is contained in:
Antoni Boucher
2019-04-28 14:06:41 -04:00
committed by Dan Gohman
parent 4ee2747c5b
commit d8d573208b
2 changed files with 29 additions and 1 deletions

View File

@@ -52,3 +52,28 @@ ebb2:
; nextln: v2 = iconst.i32 24
; nextln: return v2
; nextln: }
function %brz_fold_param(b1) -> i32 {
ebb0(v0: b1):
brz v0, ebb2
jump ebb1
ebb1:
v1 = iconst.i32 42
return v1
ebb2:
v2 = iconst.i32 24
return v2
}
; sameln: function %brz_fold_param(b1) -> i32 fast {
; nextln: ebb0(v0: b1):
; nextln: brz v0, ebb2
; nextln: jump ebb1
; nextln:
; nextln: ebb1:
; nextln: v1 = iconst.i32 42
; nextln: return v1
; nextln:
; nextln: ebb2:
; nextln: v2 = iconst.i32 24
; nextln: return v2
; nextln: }

View File

@@ -232,7 +232,10 @@ fn fold_branch(pos: &mut FuncCursor, inst: ir::Inst, opcode: ir::Opcode) {
let values = pos.func.dfg.inst_args(inst);
let inst_data = &pos.func.dfg[inst];
(
resolve_value_to_imm(&pos.func.dfg, values[0]).unwrap(),
match resolve_value_to_imm(&pos.func.dfg, values[0]) {
Some(imm) => imm,
None => return,
},
inst_data.branch_destination().unwrap(),
values[1..].to_vec(),
)