1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# Programs from "Global Code Motion Global Value Numbering" by Cliff Click
# https://courses.cs.washington.edu/courses/cse501/06wi/reading/click-pldi95.pdf
# GCM program in Figure 1
function w $gcm_test(w %a){
@start
%i.0 =w copy 0
@loop
%i.1 =w phi @start %i.0, @loop %i.2
%b =w add %a, 1 # early schedule moves to @start
%i.2 =w add %i.1, %b
%c =w mul %i.2, 2 # late schedule moves to @end
%x =w csltw %i.2, 10
jnz %x, @loop, @end
@end
ret %c
}
# GCM program in "Figure 3 x's definition does not dominate it's use"
#
# SSA contruction will insert phi instruction for "x" in @if_false
# preventing the "add" in @if_false from being moved to @if_true
function $gcm_test2 (w %a){
@start
%f =w copy 1
%x =w copy 0
%s.0 =w copy 0
@loop
%s.1 = w phi @start %s.0, @if_false %s.2
jnz %a, @if, @end
@if
jnz %f, @if_true, @if_false
@if_true
%f =w copy 0
%x =w add %x, 1
@if_false
%s.2 =w add %s.1, %x
jmp @loop
@end
ret
}
|