summaryrefslogtreecommitdiffstats
path: root/test/Transforms/InstCombine/phi.ll
blob: 24eca72d4b5398e31dbdb29a8396ed0e54a62fe1 (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
103
104
105
106
107
108
109
110
111
112
113
114
115
; This test makes sure that these instructions are properly eliminated.
;
; RUN: opt < %s -instcombine -S | not grep phi

define i32 @test1(i32 %A, i1 %b) {
BB0:
        br i1 %b, label %BB1, label %BB2

BB1:            ; preds = %BB0
        ; Combine away one argument PHI nodes
        %B = phi i32 [ %A, %BB0 ]               ; <i32> [#uses=1]
        ret i32 %B

BB2:            ; preds = %BB0
        ret i32 %A
}

define i32 @test2(i32 %A, i1 %b) {
BB0:
        br i1 %b, label %BB1, label %BB2

BB1:            ; preds = %BB0
        br label %BB2

BB2:            ; preds = %BB1, %BB0
        ; Combine away PHI nodes with same values
        %B = phi i32 [ %A, %BB0 ], [ %A, %BB1 ]         ; <i32> [#uses=1]
        ret i32 %B
}

define i32 @test3(i32 %A, i1 %b) {
BB0:
        br label %Loop

Loop:           ; preds = %Loop, %BB0
        ; PHI has same value always.
        %B = phi i32 [ %A, %BB0 ], [ %B, %Loop ]                ; <i32> [#uses=2]
        br i1 %b, label %Loop, label %Exit

Exit:           ; preds = %Loop
        ret i32 %B
}

define i32 @test4(i1 %b) {
BB0:
        ; Loop is unreachable
        ret i32 7

Loop:           ; preds = %L2, %Loop
        ; PHI has same value always.
        %B = phi i32 [ %B, %L2 ], [ %B, %Loop ]         ; <i32> [#uses=2]
        br i1 %b, label %L2, label %Loop

L2:             ; preds = %Loop
        br label %Loop
}

define i32 @test5(i32 %A, i1 %b) {
BB0:
        br label %Loop

Loop:           ; preds = %Loop, %BB0
        ; PHI has same value always.
        %B = phi i32 [ %A, %BB0 ], [ undef, %Loop ]             ; <i32> [#uses=1]
        br i1 %b, label %Loop, label %Exit

Exit:           ; preds = %Loop
        ret i32 %B
}

define i32 @test6(i32 %A, i1 %b) {
BB0:
        %X = bitcast i32 %A to i32              ; <i32> [#uses=1]
        br i1 %b, label %BB1, label %BB2

BB1:            ; preds = %BB0
        %Y = bitcast i32 %A to i32              ; <i32> [#uses=1]
        br label %BB2

BB2:            ; preds = %BB1, %BB0
        ;; Suck casts into phi
        %B = phi i32 [ %X, %BB0 ], [ %Y, %BB1 ]         ; <i32> [#uses=1]
        ret i32 %B
}

define i32 @test7(i32 %A, i1 %b) {
BB0:
        br label %Loop

Loop:           ; preds = %Loop, %BB0
        ; PHI is dead.
        %B = phi i32 [ %A, %BB0 ], [ %C, %Loop ]                ; <i32> [#uses=1]
        %C = add i32 %B, 123            ; <i32> [#uses=1]
        br i1 %b, label %Loop, label %Exit

Exit:           ; preds = %Loop
        ret i32 0
}

define i32* @test8({ i32, i32 } *%A, i1 %b) {
BB0:
        %X = getelementptr { i32, i32 } *%A, i32 0, i32 1
        br i1 %b, label %BB1, label %BB2

BB1:
        %Y = getelementptr { i32, i32 } *%A, i32 0, i32 1
        br label %BB2

BB2:
        ;; Suck GEPs into phi
        %B = phi i32* [ %X, %BB0 ], [ %Y, %BB1 ]
        ret i32* %B
}


OpenPOWER on IntegriCloud