Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Fix isplit legalization for ebb params when jumping forward #1115

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions cranelift-codegen/src/legalizer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,22 @@ 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();

// 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);

abrown marked this conversation as resolved.
Show resolved Hide resolved
// 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();
Expand Down
22 changes: 22 additions & 0 deletions filetests/isa/x86/i128-isplit-forward-jump.clif
Original file line number Diff line number Diff line change
@@ -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
}