aboutsummaryrefslogtreecommitdiffstats
path: root/test/Transforms/IndVarsSimplify/exit_value_tests.llx
blob: 7d5d36686406420db4dfc4249d6649d2c137ab61 (plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
; Test that we can evaluate the exit values of various expression types.  Since
; these loops all have predictable exit values we can replace the use outside
; of the loop with a closed-form computation, making the loop dead.
;
; RUN: llvm-upgrade < %s | llvm-as | opt -indvars -adce -simplifycfg | llvm-dis | not grep br

int %polynomial_constant() {
        br label %Loop
Loop:
        %A1 = phi int [0, %0], [%A2, %Loop]
        %B1 = phi int [0, %0], [%B2, %Loop]
        %A2 = add int %A1, 1
        %B2 = add int %B1, %A1

        %C = seteq int %A1, 1000
        br bool %C, label %Out, label %Loop
Out:
        ret int %B2
}

int %NSquare(int %N) {
	br label %Loop
Loop:
	%X = phi int [0, %0], [%X2, %Loop]
	%X2 = add int %X, 1
	%c = seteq int %X, %N
	br bool %c, label %Out, label %Loop
Out:
	%Y = mul int %X, %X
	ret int %Y
}

int %NSquareOver2(int %N) {
	br label %Loop
Loop:
	%X = phi int [0, %0], [%X2, %Loop]
	%Y = phi int [15, %0], [%Y2, %Loop]   ;; include offset of 15 for yuks

	%Y2 = add int %Y, %X

	%X2 = add int %X, 1
	%c = seteq int %X, %N
	br bool %c, label %Out, label %Loop
Out:
	ret int %Y2
}

int %strength_reduced() {
        br label %Loop
Loop:
        %A1 = phi int [0, %0], [%A2, %Loop]
        %B1 = phi int [0, %0], [%B2, %Loop]
        %A2 = add int %A1, 1
        %B2 = add int %B1, %A1

        %C = seteq int %A1, 1000
        br bool %C, label %Out, label %Loop
Out:
        ret int %B2
}

int %chrec_equals() {
entry:
        br label %no_exit
no_exit:
        %i0 = phi int [ 0, %entry ], [ %i1, %no_exit ]
        %ISq = mul int %i0, %i0
        %i1 = add int %i0, 1
        %tmp.1 = setne int %ISq, 10000    ; while (I*I != 1000)
        br bool %tmp.1, label %no_exit, label %loopexit
loopexit:
        ret int %i1
}

;; We should recognize B1 as being a recurrence, allowing us to compute the
;; trip count and eliminate the loop.
short %cast_chrec_test() {
        br label %Loop
Loop:
        %A1 = phi int [0, %0], [%A2, %Loop]
        %B1 = cast int %A1 to short
        %A2 = add int %A1, 1

        %C = seteq short %B1, 1000
        br bool %C, label %Out, label %Loop
Out:
        ret short %B1
}

uint %linear_div_fold() {   ;; for (i = 4; i != 68; i += 8)  (exit with i/2)
entry:
        br label %loop
loop:
        %i = phi uint [ 4, %entry ], [ %i.next, %loop ]
        %i.next = add uint %i, 8
        %RV = div uint %i, 2
        %c = setne uint %i, 68
        br bool %c, label %loop, label %loopexit
loopexit:
        ret uint %RV
}