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
|
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
|
|
|
}
|
|
|
|
|
Teach inst combine to merge GEPs through PHIs. This is really
important because it is sinking the loads using the GEPs, but
not the GEPs themselves. This triggers 647 times on 403.gcc
and makes the .s file much much nicer. For example before:
je LBB1_87 ## bb78
LBB1_62: ## bb77
leal 84(%esi), %eax
LBB1_63: ## bb79
movl (%eax), %eax
...
LBB1_87: ## bb78
movl $0, 4(%esp)
movl %esi, (%esp)
call L_make_decl_rtl$stub
jmp LBB1_62 ## bb77
after:
jne LBB1_63 ## bb79
LBB1_62: ## bb78
movl $0, 4(%esp)
movl %esi, (%esp)
call L_make_decl_rtl$stub
LBB1_63: ## bb79
movl 84(%esi), %eax
The input code was (and the GEPs are merged and
the PHI is now eliminated by instcombine):
br i1 %tmp233, label %bb78, label %bb77
bb77:
%tmp234 = getelementptr %struct.tree_node* %t_addr.3, i32 0, i32 0, i32 22
br label %bb79
bb78:
call void @make_decl_rtl(%struct.tree_node* %t_addr.3, i8* null) nounwind
%tmp235 = getelementptr %struct.tree_node* %t_addr.3, i32 0, i32 0, i32 22
br label %bb79
bb79:
%iftmp.12.0.in = phi %struct.rtx_def** [ %tmp235, %bb78 ], [ %tmp234, %bb77 ]
%iftmp.12.0 = load %struct.rtx_def** %iftmp.12.0.in
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60322 91177308-0d34-0410-b5e6-96231b3b80d8
2008-12-01 02:34:36 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2008-03-01 09:15:35 +00:00
|
|
|
|