From f84fc6a1897f820455af602fa12568af748fdab0 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 5 Oct 2019 17:12:51 +0200 Subject: [PATCH] Fix isplit legalization for ebb params when jumping forward Fixes #1106 --- cranelift-codegen/src/legalizer/mod.rs | 11 ++++++++-- .../isa/x86/i128-isplit-forward-jump.clif | 22 +++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 filetests/isa/x86/i128-isplit-forward-jump.clif diff --git a/cranelift-codegen/src/legalizer/mod.rs b/cranelift-codegen/src/legalizer/mod.rs index f090b1400..b406506f4 100644 --- a/cranelift-codegen/src/legalizer/mod.rs +++ b/cranelift-codegen/src/legalizer/mod.rs @@ -146,6 +146,15 @@ pub fn legalize_function(func: &mut ir::Function, cfg: &mut ControlFlowGraph, is func.encodings.resize(func.dfg.num_insts()); let mut pos = FuncCursor::new(func); + let func_begin = pos.position(); + + // Split ebb params before trying to legalize instructions, so that the newly introduced + // isplit instructions get legalized. + while let Some(ebb) = pos.next_ebb() { + split::split_ebb_params(pos.func, cfg, ebb); + } + + pos.set_position(func_begin); // This must be a set to prevent trying to legalize `isplit` and `vsplit` twice in certain cases. let mut pending_splits = BTreeSet::new(); @@ -153,8 +162,6 @@ pub fn legalize_function(func: &mut ir::Function, cfg: &mut ControlFlowGraph, is // Process EBBs in layout order. Some legalization actions may split the current EBB or append // new ones to the end. We need to make sure we visit those new EBBs too. while let Some(ebb) = pos.next_ebb() { - split::split_ebb_params(pos.func, cfg, ebb); - // Keep track of the cursor position before the instruction being processed, so we can // double back when replacing instructions. let mut prev_pos = pos.position(); diff --git a/filetests/isa/x86/i128-isplit-forward-jump.clif b/filetests/isa/x86/i128-isplit-forward-jump.clif new file mode 100644 index 000000000..863f39612 --- /dev/null +++ b/filetests/isa/x86/i128-isplit-forward-jump.clif @@ -0,0 +1,22 @@ +test compile +target x86_64 + +function u0:0() -> i128 system_v { +ebb0: + v0 = iconst.i64 0 + v1 = iconst.i64 0 + v2 = iconcat v0, v1 + jump ebb5 + +ebb2: + jump ebb4(v27) + +ebb4(v23: i128): + return v23 + +ebb5: + v27 = bxor.i128 v2, v2 + v32 = iconst.i32 0 + brz v32, ebb2 + trap user0 +}