1 ; This test makes sure that these instructions are properly eliminated.
3 ; RUN: opt < %s -instcombine -S | not grep phi
5 define i32 @test1(i32 %A, i1 %b) {
7 br i1 %b, label %BB1, label %BB2
10 ; Combine away one argument PHI nodes
11 %B = phi i32 [ %A, %BB0 ] ; <i32> [#uses=1]
18 define i32 @test2(i32 %A, i1 %b) {
20 br i1 %b, label %BB1, label %BB2
25 BB2: ; preds = %BB1, %BB0
26 ; Combine away PHI nodes with same values
27 %B = phi i32 [ %A, %BB0 ], [ %A, %BB1 ] ; <i32> [#uses=1]
31 define i32 @test3(i32 %A, i1 %b) {
35 Loop: ; preds = %Loop, %BB0
36 ; PHI has same value always.
37 %B = phi i32 [ %A, %BB0 ], [ %B, %Loop ] ; <i32> [#uses=2]
38 br i1 %b, label %Loop, label %Exit
44 define i32 @test4(i1 %b) {
49 Loop: ; preds = %L2, %Loop
50 ; PHI has same value always.
51 %B = phi i32 [ %B, %L2 ], [ %B, %Loop ] ; <i32> [#uses=2]
52 br i1 %b, label %L2, label %Loop
58 define i32 @test5(i32 %A, i1 %b) {
62 Loop: ; preds = %Loop, %BB0
63 ; PHI has same value always.
64 %B = phi i32 [ %A, %BB0 ], [ undef, %Loop ] ; <i32> [#uses=1]
65 br i1 %b, label %Loop, label %Exit
71 define i32 @test6(i32 %A, i1 %b) {
73 %X = bitcast i32 %A to i32 ; <i32> [#uses=1]
74 br i1 %b, label %BB1, label %BB2
77 %Y = bitcast i32 %A to i32 ; <i32> [#uses=1]
80 BB2: ; preds = %BB1, %BB0
81 ;; Suck casts into phi
82 %B = phi i32 [ %X, %BB0 ], [ %Y, %BB1 ] ; <i32> [#uses=1]
86 define i32 @test7(i32 %A, i1 %b) {
90 Loop: ; preds = %Loop, %BB0
92 %B = phi i32 [ %A, %BB0 ], [ %C, %Loop ] ; <i32> [#uses=1]
93 %C = add i32 %B, 123 ; <i32> [#uses=1]
94 br i1 %b, label %Loop, label %Exit
100 define i32* @test8({ i32, i32 } *%A, i1 %b) {
102 %X = getelementptr { i32, i32 } *%A, i32 0, i32 1
103 br i1 %b, label %BB1, label %BB2
106 %Y = getelementptr { i32, i32 } *%A, i32 0, i32 1
110 ;; Suck GEPs into phi
111 %B = phi i32* [ %X, %BB0 ], [ %Y, %BB1 ]