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

Commit 3eae87c

Browse files
bjorn3abrown
authored andcommitted
Fix isplit legalization for ebb params when jumping forward
Fixes #1106
1 parent 3ff68bb commit 3eae87c

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

cranelift-codegen/src/legalizer/mod.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,22 @@ pub fn legalize_function(func: &mut ir::Function, cfg: &mut ControlFlowGraph, is
146146
func.encodings.resize(func.dfg.num_insts());
147147

148148
let mut pos = FuncCursor::new(func);
149+
let func_begin = pos.position();
150+
151+
// Split ebb params before trying to legalize instructions, so that the newly introduced
152+
// isplit instructions get legalized.
153+
while let Some(ebb) = pos.next_ebb() {
154+
split::split_ebb_params(pos.func, cfg, ebb);
155+
}
156+
157+
pos.set_position(func_begin);
149158

150159
// This must be a set to prevent trying to legalize `isplit` and `vsplit` twice in certain cases.
151160
let mut pending_splits = BTreeSet::new();
152161

153162
// Process EBBs in layout order. Some legalization actions may split the current EBB or append
154163
// new ones to the end. We need to make sure we visit those new EBBs too.
155164
while let Some(ebb) = pos.next_ebb() {
156-
split::split_ebb_params(pos.func, cfg, ebb);
157-
158165
// Keep track of the cursor position before the instruction being processed, so we can
159166
// double back when replacing instructions.
160167
let mut prev_pos = pos.position();
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
test compile
2+
target x86_64
3+
4+
function u0:0() -> i128 system_v {
5+
ebb0:
6+
v0 = iconst.i64 0
7+
v1 = iconst.i64 0
8+
v2 = iconcat v0, v1
9+
jump ebb5
10+
11+
ebb2:
12+
jump ebb4(v27)
13+
14+
ebb4(v23: i128):
15+
return v23
16+
17+
ebb5:
18+
v27 = bxor.i128 v2, v2
19+
v32 = iconst.i32 0
20+
brz v32, ebb2
21+
trap user0
22+
}

0 commit comments

Comments
 (0)