2002-05-06 17:43:38 +00:00
|
|
|
; This test makes sure that these instructions are properly eliminated.
|
|
|
|
;
|
2008-03-01 09:15:35 +00:00
|
|
|
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | not grep phi
|
2007-04-15 07:38:21 +00:00
|
|
|
; END.
|
2002-05-06 17:43:38 +00:00
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
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
|
2002-05-06 17:43:38 +00:00
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
BB2: ; preds = %BB0
|
|
|
|
ret i32 %A
|
2002-05-06 17:43:38 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
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
|
2002-08-20 15:27:45 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
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
|
2002-08-22 21:26:15 +00:00
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
Exit: ; preds = %Loop
|
|
|
|
ret i32 %B
|
2002-08-22 21:26:15 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
define i32 @test4(i1 %b) {
|
|
|
|
BB0:
|
|
|
|
; Loop is unreachable
|
|
|
|
ret i32 7
|
2002-08-22 21:26:15 +00:00
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
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
|
2002-08-22 21:26:15 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
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
|
2004-11-14 17:54:27 +00:00
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
Exit: ; preds = %Loop
|
|
|
|
ret i32 %B
|
2004-11-14 17:54:27 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
define i32 @test6(i32 %A, i1 %b) {
|
2004-11-14 19:12:17 +00:00
|
|
|
BB0:
|
2008-03-01 09:15:35 +00:00
|
|
|
%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]
|
2004-11-14 19:12:17 +00:00
|
|
|
br label %BB2
|
2008-03-01 09:15:35 +00:00
|
|
|
|
|
|
|
BB2: ; preds = %BB1, %BB0
|
|
|
|
;; Suck casts into phi
|
|
|
|
%B = phi i32 [ %X, %BB0 ], [ %Y, %BB1 ] ; <i32> [#uses=1]
|
|
|
|
ret i32 %B
|
2004-11-14 19:12:17 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
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
|
2007-01-15 07:29:29 +00:00
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
Exit: ; preds = %Loop
|
|
|
|
ret i32 0
|
2007-01-15 07:29:29 +00:00
|
|
|
}
|
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
|