Split edges to have a block to add regmove & copy instructions.
When using basic block instructions cannot be added in-between jump instructions which are ending basic blocks. These changes create extra basic blocks such that extra space is available for the spilling and moving registers where they are expected.
This commit is contained in:
committed by
GitHub
parent
bb87f1a54a
commit
381578311c
158
cranelift/filetests/filetests/regalloc/coalesce-bb.clif
Normal file
158
cranelift/filetests/filetests/regalloc/coalesce-bb.clif
Normal file
@@ -0,0 +1,158 @@
|
||||
test regalloc
|
||||
target riscv32
|
||||
feature "basic-blocks"
|
||||
|
||||
; Test the coalescer.
|
||||
; regex: V=v\d+
|
||||
; regex: WS=\s+
|
||||
; regex: LOC=%\w+
|
||||
; regex: EBB=ebb\d+
|
||||
|
||||
; This function is already CSSA, so no copies should be inserted.
|
||||
function %cssa(i32) -> i32 {
|
||||
ebb0(v0: i32):
|
||||
; not: copy
|
||||
; v0 is used by the branch and passed as an arg - that's no conflict.
|
||||
brnz v0, ebb1(v0)
|
||||
jump ebb2
|
||||
|
||||
ebb2:
|
||||
; v0 is live across the branch above. That's no conflict.
|
||||
v1 = iadd_imm v0, 7
|
||||
jump ebb1(v1)
|
||||
|
||||
ebb1(v10: i32):
|
||||
v11 = iadd_imm v10, 7
|
||||
return v11
|
||||
}
|
||||
|
||||
function %trivial(i32) -> i32 {
|
||||
ebb0(v0: i32):
|
||||
; check: brnz v0, $(splitEdge=$EBB)
|
||||
brnz v0, ebb1(v0)
|
||||
jump ebb2
|
||||
|
||||
ebb2:
|
||||
; not: copy
|
||||
v1 = iadd_imm v0, 7
|
||||
jump ebb1(v1)
|
||||
|
||||
; check: $splitEdge:
|
||||
; nextln: $(cp1=$V) = copy.i32 v0
|
||||
; nextln: jump ebb1($cp1)
|
||||
|
||||
ebb1(v10: i32):
|
||||
; Use v0 in the destination EBB causes a conflict.
|
||||
v11 = iadd v10, v0
|
||||
return v11
|
||||
}
|
||||
|
||||
; A value is used as an SSA argument twice in the same branch.
|
||||
function %dualuse(i32) -> i32 {
|
||||
ebb0(v0: i32):
|
||||
; check: brnz v0, $(splitEdge=$EBB)
|
||||
brnz v0, ebb1(v0, v0)
|
||||
jump ebb2
|
||||
|
||||
ebb2:
|
||||
v1 = iadd_imm v0, 7
|
||||
v2 = iadd_imm v1, 56
|
||||
jump ebb1(v1, v2)
|
||||
|
||||
; check: $splitEdge:
|
||||
; check: $(cp1=$V) = copy.i32 v0
|
||||
; nextln: jump ebb1($cp1, v0)
|
||||
|
||||
ebb1(v10: i32, v11: i32):
|
||||
v12 = iadd v10, v11
|
||||
return v12
|
||||
}
|
||||
|
||||
; Interference away from the branch
|
||||
; The interference can be broken with a copy at either branch.
|
||||
function %interference(i32) -> i32 {
|
||||
ebb0(v0: i32):
|
||||
; not: copy
|
||||
; check: brnz v0, $(splitEdge=$EBB)
|
||||
; not: copy
|
||||
brnz v0, ebb1(v0)
|
||||
jump ebb2
|
||||
|
||||
ebb2:
|
||||
v1 = iadd_imm v0, 7
|
||||
; v1 and v0 interfere here:
|
||||
v2 = iadd_imm v0, 8
|
||||
; check: $(cp0=$V) = copy v1
|
||||
; check: jump ebb1($cp0)
|
||||
jump ebb1(v1)
|
||||
|
||||
; check: $splitEdge:
|
||||
; not: copy
|
||||
; nextln: jump ebb1(v0)
|
||||
|
||||
ebb1(v10: i32):
|
||||
; not: copy
|
||||
v11 = iadd_imm v10, 7
|
||||
return v11
|
||||
}
|
||||
|
||||
; A loop where one induction variable is used as a backedge argument.
|
||||
function %fibonacci(i32) -> i32 {
|
||||
ebb0(v0: i32):
|
||||
v1 = iconst.i32 1
|
||||
v2 = iconst.i32 2
|
||||
jump ebb1(v1, v2)
|
||||
|
||||
ebb1(v10: i32, v11: i32):
|
||||
; v11 needs to be isolated because it interferes with v10.
|
||||
; check: ebb1(v10: i32 [$LOC], $(nv11a=$V): i32 [$LOC])
|
||||
; check: v11 = copy $nv11a
|
||||
v12 = iadd v10, v11
|
||||
v13 = icmp ult v12, v0
|
||||
; check: brnz v13, $(splitEdge=$EBB)
|
||||
brnz v13, ebb1(v11, v12)
|
||||
jump ebb2
|
||||
|
||||
; check: $splitEdge:
|
||||
; check: $(nv11b=$V) = copy.i32 v11
|
||||
; not: copy
|
||||
; check: jump ebb1($nv11b, v12)
|
||||
|
||||
ebb2:
|
||||
return v12
|
||||
}
|
||||
|
||||
; Function arguments passed on the stack aren't allowed to be part of a virtual
|
||||
; register, at least for now. This is because the other values in the virtual
|
||||
; register would need to be spilled to the incoming_arg stack slot which we treat
|
||||
; as belonging to the caller.
|
||||
function %stackarg(i32, i32, i32, i32, i32, i32, i32, i32, i32) -> i32 {
|
||||
; check: ss0 = incoming_arg 4
|
||||
; not: incoming_arg
|
||||
ebb0(v0: i32, v1: i32, v2: i32, v3: i32, v4: i32, v5: i32, v6: i32, v7: i32, v8: i32):
|
||||
; check: fill v8
|
||||
; not: v8
|
||||
jump ebb1(v8)
|
||||
|
||||
ebb1(v10: i32):
|
||||
v11 = iadd_imm v10, 1
|
||||
return v11
|
||||
}
|
||||
|
||||
function %gvn_unremovable_phi(i32) system_v {
|
||||
ebb0(v0: i32):
|
||||
v2 = iconst.i32 0
|
||||
jump ebb2(v2, v0)
|
||||
|
||||
ebb2(v3: i32, v4: i32):
|
||||
brnz v3, ebb2(v3, v4)
|
||||
jump ebb3
|
||||
|
||||
ebb3:
|
||||
v5 = iconst.i32 1
|
||||
brnz v3, ebb2(v2, v5)
|
||||
jump ebb4
|
||||
|
||||
ebb4:
|
||||
return
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
test regalloc
|
||||
target riscv32
|
||||
feature !"basic-blocks"
|
||||
|
||||
; Test the coalescer.
|
||||
; regex: V=v\d+
|
||||
|
||||
111
cranelift/filetests/filetests/regalloc/reload-208-bb.clif
Normal file
111
cranelift/filetests/filetests/regalloc/reload-208-bb.clif
Normal file
@@ -0,0 +1,111 @@
|
||||
test regalloc
|
||||
target x86_64 haswell
|
||||
feature "basic-blocks"
|
||||
|
||||
; regex: V=v\d+
|
||||
; regex: EBB=ebb\d+
|
||||
|
||||
; Filed as https://github.com/CraneStation/cranelift/issues/208
|
||||
;
|
||||
; The verifier complains about a branch argument that is not in the same virtual register as the
|
||||
; corresponding EBB argument.
|
||||
;
|
||||
; The problem was the reload pass rewriting EBB arguments on "brnz v9, ebb3(v9)"
|
||||
|
||||
function %pr208(i64 vmctx [%rdi]) system_v {
|
||||
gv1 = vmctx
|
||||
gv0 = iadd_imm.i64 gv1, -8
|
||||
heap0 = static gv0, min 0, bound 0x5000, offset_guard 0x0040_0000
|
||||
sig0 = (i64 vmctx [%rdi]) -> i32 [%rax] system_v
|
||||
sig1 = (i64 vmctx [%rdi], i32 [%rsi]) system_v
|
||||
fn0 = u0:1 sig0
|
||||
fn1 = u0:3 sig1
|
||||
|
||||
ebb0(v0: i64):
|
||||
v1 = iconst.i32 0
|
||||
v2 = call fn0(v0)
|
||||
v20 = iconst.i32 0x4ffe
|
||||
v16 = icmp uge v2, v20
|
||||
brz v16, ebb5
|
||||
jump ebb9
|
||||
|
||||
ebb9:
|
||||
trap heap_oob
|
||||
|
||||
ebb5:
|
||||
v17 = uextend.i64 v2
|
||||
v18 = iadd_imm.i64 v0, -8
|
||||
v19 = load.i64 v18
|
||||
v3 = iadd v19, v17
|
||||
v4 = load.i32 v3
|
||||
v21 = iconst.i32 0
|
||||
v5 = icmp eq v4, v21
|
||||
v6 = bint.i32 v5
|
||||
brnz v6, ebb2
|
||||
jump ebb3(v4)
|
||||
|
||||
ebb3(v7: i32):
|
||||
call fn1(v0, v7)
|
||||
v26 = iconst.i32 0x4ffe
|
||||
v22 = icmp uge v7, v26
|
||||
brz v22, ebb6
|
||||
jump ebb10
|
||||
|
||||
ebb10:
|
||||
trap heap_oob
|
||||
|
||||
ebb6:
|
||||
v23 = uextend.i64 v7
|
||||
v24 = iadd_imm.i64 v0, -8
|
||||
v25 = load.i64 v24
|
||||
v8 = iadd v25, v23
|
||||
v9 = load.i32 v8+56
|
||||
; check: v9 = spill
|
||||
; check: brnz $V, $(splitEdge=$EBB)
|
||||
brnz v9, ebb3(v9)
|
||||
jump ebb4
|
||||
|
||||
; check: $splitEdge:
|
||||
; nextln: jump ebb3(v9)
|
||||
|
||||
ebb4:
|
||||
jump ebb2
|
||||
|
||||
ebb2:
|
||||
v10 = iconst.i32 0
|
||||
v31 = iconst.i32 0x4ffe
|
||||
v27 = icmp uge v10, v31
|
||||
brz v27, ebb7
|
||||
jump ebb11
|
||||
|
||||
ebb11:
|
||||
trap heap_oob
|
||||
|
||||
ebb7:
|
||||
v28 = uextend.i64 v10
|
||||
v29 = iadd_imm.i64 v0, -8
|
||||
v30 = load.i64 v29
|
||||
v11 = iadd v30, v28
|
||||
v12 = load.i32 v11+12
|
||||
call fn1(v0, v12)
|
||||
v13 = iconst.i32 0
|
||||
v36 = iconst.i32 0x4ffe
|
||||
v32 = icmp uge v13, v36
|
||||
brz v32, ebb8
|
||||
jump ebb12
|
||||
|
||||
ebb12:
|
||||
trap heap_oob
|
||||
|
||||
ebb8:
|
||||
v33 = uextend.i64 v13
|
||||
v34 = iadd_imm.i64 v0, -8
|
||||
v35 = load.i64 v34
|
||||
v14 = iadd v35, v33
|
||||
v15 = load.i32 v14+12
|
||||
call fn1(v0, v15)
|
||||
jump ebb1
|
||||
|
||||
ebb1:
|
||||
return
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
test regalloc
|
||||
target x86_64 haswell
|
||||
feature !"basic-blocks"
|
||||
|
||||
; regex: V=v\d+
|
||||
|
||||
|
||||
49
cranelift/filetests/filetests/regalloc/x86-regres-bb.clif
Normal file
49
cranelift/filetests/filetests/regalloc/x86-regres-bb.clif
Normal file
@@ -0,0 +1,49 @@
|
||||
test regalloc
|
||||
target i686
|
||||
feature "basic-blocks"
|
||||
|
||||
; regex: V=v\d+
|
||||
; regex: EBB=ebb\d+
|
||||
|
||||
; The value v9 appears both as the branch control and one of the EBB arguments
|
||||
; in the brnz instruction in ebb2. It also happens that v7 and v9 are assigned
|
||||
; to the same register, so v9 doesn't need to be moved before the brnz.
|
||||
;
|
||||
; This ended up confusong the constraint solver which had not made a record of
|
||||
; the fixed register assignment for v9 since it was already in the correct
|
||||
; register.
|
||||
function %pr147(i32) -> i32 system_v {
|
||||
ebb0(v0: i32):
|
||||
v1 = iconst.i32 0
|
||||
v2 = iconst.i32 1
|
||||
v3 = iconst.i32 0
|
||||
jump ebb2(v3, v2, v0)
|
||||
|
||||
ebb2(v4: i32, v5: i32, v7: i32):
|
||||
; check: ebb2
|
||||
v6 = iadd v4, v5
|
||||
v8 = iconst.i32 -1
|
||||
; v7 is killed here and v9 gets the same register.
|
||||
v9 = iadd v7, v8
|
||||
; check: v9 = iadd v7, v8
|
||||
; Here v9 the brnz control appears to interfere with v9 the EBB argument,
|
||||
; so divert_fixed_input_conflicts() calls add_var(v9), which is ok. The
|
||||
; add_var sanity checks got confused when no fixed assignment could be
|
||||
; found for v9.
|
||||
;
|
||||
; We should be able to handle this situation without making copies of v9.
|
||||
brnz v9, ebb2(v5, v6, v9)
|
||||
; check: brnz v9, $(splitEdge=$EBB)
|
||||
jump ebb3
|
||||
|
||||
; check: $splitEdge:
|
||||
; check: jump ebb2($V, $V, v9)
|
||||
ebb3:
|
||||
return v5
|
||||
}
|
||||
|
||||
function %select_i64(i64, i64, i32) -> i64 {
|
||||
ebb0(v0: i64, v1: i64, v2: i32):
|
||||
v3 = select v2, v0, v1
|
||||
return v3
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
test regalloc
|
||||
|
||||
target i686
|
||||
feature !"basic-blocks"
|
||||
|
||||
; regex: V=v\d+
|
||||
|
||||
|
||||
Reference in New Issue
Block a user