For any node
- There existing an instruction
$i$ define$a$ satisfying:- There is an instruction
$i'$ use$b$ after$i$ - There is no instruction define
$b$ between$i$ and$i'$
- There is an instruction
- There existing an instruction
$i$ define$b$ satisfying:- There is an instruction
$i'$ use$a$ after$i$ - There is no instruction define
$a$ between$i$ and$i'$
- There is an instruction
Note: The "after" or "before" of an instruction refers to the order of execution control flow
Since live inside the function, thus for every instruction uses
If
-
$i_a$ define$a$ and$i'_a$ uses$a$ , no instruction define$a$ between$i_a$ and$i'_a$ -
$i_b$ define$b$ and$i'_b$ uses$b$ , no instruction define$b$ between$i_b$ and$i'_b$
And
There for either
For any node
If a node
- Before every instruction uses this node, will add a mov to define it.
- After every instruction defines this node, will add a mov to use it.
Thus, for every instruction
Assume
Assume there exists an instruction
- There is an instruction
$i'$ use$b$ after$i$ - There is no instruction define
$b$ between$i$ and$i'$
If
If
If a move instruction
Assume the following code piece with:
r101need to spill.- number color-able register
K=4. rax,rbxare pre-colored registers.rbxlive out of the block.
mov r101, 7
mov rax, 8 // r101 interfere with rax
mov rbx, r101
mov r100, 6
mov rax, r100 // target mov instruction
mov r102, 1
mov r103, 2
mov r104, 3
mov r100, 1
mov r101, 9 // r100 interfere with r101
add rbx, r101
add rbx, r100
add rbx, r102
add rbx, r103
add rbx, r104According to Lemma 0, due to mov rax, 8 it can be found that r101 conflict with rax.
Similarly due to mov r101, 9 can be found that r101 conflict with r100 before re-writing.
It can be seen that rax only conflict with r101 and rbx
It can be seen that r100 only conflict with r101
According to George method, instruction mov rax, r100 can be coalesced since the only neighbor of r100 is r101, which already interfere with rax.
mov r101, 7
mov [mem], r101 // re-writing: save r101
mov rax, 8 // r101 interfere with rax
mov r101, [mem] // re-writing: fetch r101
mov rbx, r101
mov r100, 6
mov rax, r100 // target mov instruction
mov r102, 1
mov r103, 2
mov r104, 3
mov r100, 1
mov r101, 9 // r100 interfere with r101
mov [mem], r101 // re-writing: save r101
mov r101, [mem] // re-writing: fetch r101
add rbx, r101
add rbx, r100
add rbx, r102
add rbx, r103
add rbx, r104Due to the fetch instruction after mov rax, 8, rax no longer interfere with r101
Due to mov r101, 9 can be found that r101 still interfere with r102, r103, r104 and r100
Thus the neighbor of r100 is on significant degree and not a neighbor of rax
Hence according to George method, instruction mov rax, r100 cannot be coalesced.