* LICM pass * Uses loop analysis to detect loop tree * For each loop (starting with the inner ones), create a pre-header and move there loop-invariant instructions * An instruction is loop invariant if it does not use as argument a value defined earlier in the loop * File tests to check LICM's correctness * Optimized pre-header creation If the loop already has a natural pre-header, we use it instead of creating a new one. The natural pre-header of a loop is the only predecessor of the header it doesn't dominate.
47 lines
930 B
Plaintext
47 lines
930 B
Plaintext
test licm
|
|
|
|
function multiple_blocks(i32) -> i32 {
|
|
|
|
ebb0(v0: i32):
|
|
jump ebb1(v0)
|
|
|
|
ebb1(v10: i32):
|
|
v11 = iconst.i32 1
|
|
v12 = iconst.i32 2
|
|
v13 = iadd v11, v12
|
|
brz v10, ebb2(v10)
|
|
v15 = isub v10, v11
|
|
brz v15, ebb3(v15)
|
|
v14 = isub v10, v11
|
|
jump ebb1(v14)
|
|
|
|
ebb2(v20: i32):
|
|
return v20
|
|
|
|
ebb3(v30: i32):
|
|
v31 = iadd v11, v13
|
|
jump ebb1(v30)
|
|
|
|
}
|
|
; sameln:function multiple_blocks(i32) -> i32 {
|
|
; nextln: ebb0(v0: i32):
|
|
; nextln: v2 = iconst.i32 1
|
|
; nextln: v3 = iconst.i32 2
|
|
; nextln: v4 = iadd v2, v3
|
|
; nextln: v9 = iadd v2, v4
|
|
; nextln: jump ebb1(v0)
|
|
; nextln:
|
|
; nextln: ebb1(v1: i32):
|
|
; nextln: brz v1, ebb2(v1)
|
|
; nextln: v5 = isub v1, v2
|
|
; nextln: brz v5, ebb3(v5)
|
|
; nextln: v6 = isub v1, v2
|
|
; nextln: jump ebb1(v6)
|
|
; nextln:
|
|
; nextln: ebb2(v7: i32):
|
|
; nextln: return v7
|
|
; nextln:
|
|
; nextln: ebb3(v8: i32):
|
|
; nextln: jump ebb1(v8)
|
|
; nextln: }
|