From d8d573208b846873cc45b88bc25de9fd2333390e Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Sun, 28 Apr 2019 14:06:41 -0400 Subject: [PATCH] Remove unwrap() for branch folding --- .../filetests/filetests/preopt/branch.clif | 25 +++++++++++++++++++ cranelift/preopt/src/constant_folding.rs | 5 +++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/cranelift/filetests/filetests/preopt/branch.clif b/cranelift/filetests/filetests/preopt/branch.clif index 2b696fa2ef..8e139952f9 100644 --- a/cranelift/filetests/filetests/preopt/branch.clif +++ b/cranelift/filetests/filetests/preopt/branch.clif @@ -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: } diff --git a/cranelift/preopt/src/constant_folding.rs b/cranelift/preopt/src/constant_folding.rs index 018ac04a7e..cf4dba2815 100644 --- a/cranelift/preopt/src/constant_folding.rs +++ b/cranelift/preopt/src/constant_folding.rs @@ -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(), )