2002-05-06 17:43:38 +00:00
|
|
|
; This test makes sure that these instructions are properly eliminated.
|
|
|
|
;
|
2009-11-01 19:22:20 +00:00
|
|
|
; RUN: opt < %s -instcombine -S | FileCheck %s
|
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
|
|
|
|
|
2009-11-01 19:22:20 +00:00
|
|
|
BB1:
|
2008-03-01 09:15:35 +00:00
|
|
|
; Combine away one argument PHI nodes
|
2009-11-01 19:22:20 +00:00
|
|
|
%B = phi i32 [ %A, %BB0 ]
|
2008-03-01 09:15:35 +00:00
|
|
|
ret i32 %B
|
2002-05-06 17:43:38 +00:00
|
|
|
|
2009-11-01 19:22:20 +00:00
|
|
|
BB2:
|
2008-03-01 09:15:35 +00:00
|
|
|
ret i32 %A
|
2009-11-01 19:22:20 +00:00
|
|
|
; CHECK: @test1
|
|
|
|
; CHECK: BB1:
|
|
|
|
; CHECK-NEXT: 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
|
|
|
|
|
2009-11-01 19:22:20 +00:00
|
|
|
BB1:
|
2008-03-01 09:15:35 +00:00
|
|
|
br label %BB2
|
|
|
|
|
2009-11-01 19:22:20 +00:00
|
|
|
BB2:
|
2008-03-01 09:15:35 +00:00
|
|
|
; Combine away PHI nodes with same values
|
2009-11-01 19:22:20 +00:00
|
|
|
%B = phi i32 [ %A, %BB0 ], [ %A, %BB1 ]
|
2008-03-01 09:15:35 +00:00
|
|
|
ret i32 %B
|
2009-11-01 19:22:20 +00:00
|
|
|
; CHECK: @test2
|
|
|
|
; CHECK: BB2:
|
|
|
|
; CHECK-NEXT: ret i32 %A
|
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
|
|
|
|
|
2009-11-01 19:22:20 +00:00
|
|
|
Loop:
|
2008-03-01 09:15:35 +00:00
|
|
|
; PHI has same value always.
|
2009-11-01 19:22:20 +00:00
|
|
|
%B = phi i32 [ %A, %BB0 ], [ %B, %Loop ]
|
2008-03-01 09:15:35 +00:00
|
|
|
br i1 %b, label %Loop, label %Exit
|
2002-08-22 21:26:15 +00:00
|
|
|
|
2009-11-01 19:22:20 +00:00
|
|
|
Exit:
|
2008-03-01 09:15:35 +00:00
|
|
|
ret i32 %B
|
2009-11-01 19:22:20 +00:00
|
|
|
; CHECK: @test3
|
|
|
|
; CHECK: Exit:
|
|
|
|
; CHECK-NEXT: ret i32 %A
|
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.
|
2009-11-01 19:22:20 +00:00
|
|
|
%B = phi i32 [ %B, %L2 ], [ %B, %Loop ]
|
2008-03-01 09:15:35 +00:00
|
|
|
br i1 %b, label %L2, label %Loop
|
|
|
|
|
|
|
|
L2: ; preds = %Loop
|
|
|
|
br label %Loop
|
2009-11-01 19:22:20 +00:00
|
|
|
; CHECK: @test4
|
|
|
|
; CHECK: Loop:
|
|
|
|
; CHECK-NEXT: br i1 %b
|
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.
|
2009-11-01 19:22:20 +00:00
|
|
|
%B = phi i32 [ %A, %BB0 ], [ undef, %Loop ]
|
2008-03-01 09:15:35 +00:00
|
|
|
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
|
2009-11-01 19:22:20 +00:00
|
|
|
; CHECK: @test5
|
|
|
|
; CHECK: Loop:
|
|
|
|
; CHECK-NEXT: br i1 %b
|
|
|
|
; CHECK: Exit:
|
|
|
|
; CHECK-NEXT: ret i32 %A
|
2004-11-14 17:54:27 +00:00
|
|
|
}
|
|
|
|
|
2009-11-01 19:22:20 +00:00
|
|
|
define i32 @test6(i16 %A, i1 %b) {
|
2004-11-14 19:12:17 +00:00
|
|
|
BB0:
|
2009-11-01 19:22:20 +00:00
|
|
|
%X = zext i16 %A to i32
|
2008-03-01 09:15:35 +00:00
|
|
|
br i1 %b, label %BB1, label %BB2
|
|
|
|
|
2009-11-01 19:22:20 +00:00
|
|
|
BB1:
|
|
|
|
%Y = zext i16 %A to i32
|
2004-11-14 19:12:17 +00:00
|
|
|
br label %BB2
|
2008-03-01 09:15:35 +00:00
|
|
|
|
2009-11-01 19:22:20 +00:00
|
|
|
BB2:
|
2008-03-01 09:15:35 +00:00
|
|
|
;; Suck casts into phi
|
2009-11-01 19:22:20 +00:00
|
|
|
%B = phi i32 [ %X, %BB0 ], [ %Y, %BB1 ]
|
2008-03-01 09:15:35 +00:00
|
|
|
ret i32 %B
|
2009-11-01 19:22:20 +00:00
|
|
|
; CHECK: @test6
|
|
|
|
; CHECK: BB2:
|
|
|
|
; CHECK: zext i16 %A to i32
|
|
|
|
; CHECK-NEXT: ret i32
|
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.
|
2009-11-01 19:22:20 +00:00
|
|
|
%B = phi i32 [ %A, %BB0 ], [ %C, %Loop ]
|
|
|
|
%C = add i32 %B, 123
|
2008-03-01 09:15:35 +00:00
|
|
|
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
|
2009-11-01 19:22:20 +00:00
|
|
|
; CHECK: @test7
|
|
|
|
; CHECK: Loop:
|
|
|
|
; CHECK-NEXT: br i1 %b
|
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
|
2009-11-01 19:22:20 +00:00
|
|
|
; CHECK: @test8
|
|
|
|
; CHECK-NOT: phi
|
|
|
|
; CHECK: BB2:
|
|
|
|
; CHECK-NEXT: %B = getelementptr
|
|
|
|
; CHECK-NEXT: ret i32* %B
|
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
|
|
|
}
|
|
|
|
|
2009-11-01 19:50:13 +00:00
|
|
|
define i32 @test9(i32* %A, i32* %B) {
|
|
|
|
entry:
|
|
|
|
%c = icmp eq i32* %A, null
|
|
|
|
br i1 %c, label %bb1, label %bb
|
|
|
|
|
|
|
|
bb:
|
|
|
|
%C = load i32* %B, align 1
|
|
|
|
br label %bb2
|
|
|
|
|
|
|
|
bb1:
|
|
|
|
%D = load i32* %A, align 1
|
|
|
|
br label %bb2
|
|
|
|
|
|
|
|
bb2:
|
|
|
|
%E = phi i32 [ %C, %bb ], [ %D, %bb1 ]
|
|
|
|
ret i32 %E
|
2009-11-01 20:07:07 +00:00
|
|
|
; CHECK: @test9
|
2009-11-01 19:50:13 +00:00
|
|
|
; CHECK: bb2:
|
|
|
|
; CHECK-NEXT: phi i32* [ %B, %bb ], [ %A, %bb1 ]
|
|
|
|
; CHECK-NEXT: %E = load i32* %{{[^,]*}}, align 1
|
|
|
|
; CHECK-NEXT: ret i32 %E
|
2008-03-01 09:15:35 +00:00
|
|
|
|
2009-11-01 19:50:13 +00:00
|
|
|
}
|
2009-11-01 20:07:07 +00:00
|
|
|
|
|
|
|
define i32 @test10(i32* %A, i32* %B) {
|
|
|
|
entry:
|
|
|
|
%c = icmp eq i32* %A, null
|
|
|
|
br i1 %c, label %bb1, label %bb
|
|
|
|
|
|
|
|
bb:
|
|
|
|
%C = load i32* %B, align 16
|
|
|
|
br label %bb2
|
|
|
|
|
|
|
|
bb1:
|
|
|
|
%D = load i32* %A, align 32
|
|
|
|
br label %bb2
|
|
|
|
|
|
|
|
bb2:
|
|
|
|
%E = phi i32 [ %C, %bb ], [ %D, %bb1 ]
|
|
|
|
ret i32 %E
|
|
|
|
; CHECK: @test10
|
|
|
|
; CHECK: bb2:
|
|
|
|
; CHECK-NEXT: phi i32* [ %B, %bb ], [ %A, %bb1 ]
|
|
|
|
; CHECK-NEXT: %E = load i32* %{{[^,]*}}, align 16
|
|
|
|
; CHECK-NEXT: ret i32 %E
|
2009-11-01 20:10:11 +00:00
|
|
|
}
|
|
|
|
|
2009-11-01 20:07:07 +00:00
|
|
|
|
2009-11-01 20:10:11 +00:00
|
|
|
; PR1777
|
|
|
|
declare i1 @test11a()
|
|
|
|
|
|
|
|
define i1 @test11() {
|
|
|
|
entry:
|
|
|
|
%a = alloca i32
|
|
|
|
%i = ptrtoint i32* %a to i32
|
|
|
|
%b = call i1 @test11a()
|
|
|
|
br i1 %b, label %one, label %two
|
|
|
|
|
|
|
|
one:
|
|
|
|
%x = phi i32 [%i, %entry], [%y, %two]
|
|
|
|
%c = call i1 @test11a()
|
|
|
|
br i1 %c, label %two, label %end
|
|
|
|
|
|
|
|
two:
|
|
|
|
%y = phi i32 [%i, %entry], [%x, %one]
|
|
|
|
%d = call i1 @test11a()
|
|
|
|
br i1 %d, label %one, label %end
|
|
|
|
|
|
|
|
end:
|
|
|
|
%f = phi i32 [ %x, %one], [%y, %two]
|
|
|
|
; Change the %f to %i, and the optimizer suddenly becomes a lot smarter
|
|
|
|
; even though %f must equal %i at this point
|
|
|
|
%g = inttoptr i32 %f to i32*
|
|
|
|
store i32 10, i32* %g
|
|
|
|
%z = call i1 @test11a()
|
|
|
|
ret i1 %z
|
|
|
|
; CHECK: @test11
|
|
|
|
; CHECK-NOT: phi i32
|
|
|
|
; CHECK: ret i1 %z
|
2009-11-01 20:07:07 +00:00
|
|
|
}
|
|
|
|
|