2009-10-11 11:54:21 +08:00
|
|
|
; RUN: opt < %s -jump-threading -S | FileCheck %s
|
2008-04-22 14:35:14 +08:00
|
|
|
|
|
|
|
declare i32 @f1()
|
|
|
|
declare i32 @f2()
|
|
|
|
declare void @f3()
|
|
|
|
|
2009-10-11 11:55:30 +08:00
|
|
|
define i32 @test1(i1 %cond) {
|
|
|
|
; CHECK: @test1
|
|
|
|
|
2008-04-22 14:35:14 +08:00
|
|
|
br i1 %cond, label %T1, label %F1
|
|
|
|
|
|
|
|
T1:
|
|
|
|
%v1 = call i32 @f1()
|
|
|
|
br label %Merge
|
|
|
|
|
|
|
|
F1:
|
|
|
|
%v2 = call i32 @f2()
|
|
|
|
br label %Merge
|
|
|
|
|
|
|
|
Merge:
|
|
|
|
%A = phi i1 [true, %T1], [false, %F1]
|
|
|
|
%B = phi i32 [%v1, %T1], [%v2, %F1]
|
|
|
|
br i1 %A, label %T2, label %F2
|
|
|
|
|
|
|
|
T2:
|
2009-10-11 11:54:21 +08:00
|
|
|
; CHECK: T2:
|
|
|
|
; CHECK: ret i32 %v1
|
2008-04-22 14:35:14 +08:00
|
|
|
call void @f3()
|
|
|
|
ret i32 %B
|
|
|
|
|
|
|
|
F2:
|
2009-10-11 11:54:21 +08:00
|
|
|
; CHECK: F2:
|
|
|
|
; CHECK: ret i32 %v2
|
2008-04-22 14:35:14 +08:00
|
|
|
ret i32 %B
|
|
|
|
}
|
2008-12-03 15:48:08 +08:00
|
|
|
|
|
|
|
|
|
|
|
;; cond is known false on Entry -> F1 edge!
|
|
|
|
define i32 @test2(i1 %cond) {
|
2009-10-11 11:55:30 +08:00
|
|
|
; CHECK: @test2
|
2008-12-03 15:48:08 +08:00
|
|
|
Entry:
|
|
|
|
br i1 %cond, label %T1, label %F1
|
|
|
|
|
|
|
|
T1:
|
2009-10-11 11:54:21 +08:00
|
|
|
; CHECK: %v1 = call i32 @f1()
|
|
|
|
; CHECK: ret i32 47
|
2008-12-03 15:48:08 +08:00
|
|
|
%v1 = call i32 @f1()
|
|
|
|
br label %Merge
|
|
|
|
|
|
|
|
F1:
|
|
|
|
br i1 %cond, label %Merge, label %F2
|
|
|
|
|
|
|
|
Merge:
|
|
|
|
%B = phi i32 [47, %T1], [192, %F1]
|
|
|
|
ret i32 %B
|
|
|
|
|
|
|
|
F2:
|
|
|
|
call void @f3()
|
|
|
|
ret i32 12
|
|
|
|
}
|
2009-10-11 11:55:30 +08:00
|
|
|
|
|
|
|
|
|
|
|
; Undef handling.
|
|
|
|
define i32 @test3(i1 %cond) {
|
|
|
|
; CHECK: @test3
|
|
|
|
; CHECK-NEXT: T1:
|
|
|
|
; CHECK-NEXT: ret i32 42
|
|
|
|
br i1 undef, label %T1, label %F1
|
|
|
|
|
|
|
|
T1:
|
|
|
|
ret i32 42
|
|
|
|
|
|
|
|
F1:
|
|
|
|
ret i32 17
|
|
|
|
}
|
2009-10-11 12:18:15 +08:00
|
|
|
|
|
|
|
define i32 @test4(i1 %cond, i1 %cond2) {
|
|
|
|
; CHECK: @test4
|
|
|
|
|
|
|
|
br i1 %cond, label %T1, label %F1
|
|
|
|
|
|
|
|
T1:
|
|
|
|
; CHECK: %v1 = call i32 @f1()
|
|
|
|
; CHECK-NEXT: br label %T
|
|
|
|
|
|
|
|
%v1 = call i32 @f1()
|
|
|
|
br label %Merge
|
|
|
|
|
|
|
|
F1:
|
|
|
|
%v2 = call i32 @f2()
|
|
|
|
; CHECK: %v2 = call i32 @f2()
|
|
|
|
; CHECK-NEXT: br i1 %cond2,
|
|
|
|
br label %Merge
|
|
|
|
|
|
|
|
Merge:
|
|
|
|
%A = phi i1 [undef, %T1], [%cond2, %F1]
|
|
|
|
%B = phi i32 [%v1, %T1], [%v2, %F1]
|
|
|
|
br i1 %A, label %T2, label %F2
|
|
|
|
|
|
|
|
T2:
|
|
|
|
call void @f3()
|
|
|
|
ret i32 %B
|
|
|
|
|
|
|
|
F2:
|
|
|
|
ret i32 %B
|
|
|
|
}
|
|
|
|
|
2009-10-11 15:24:57 +08:00
|
|
|
|
|
|
|
;; This tests that the branch in 'merge' can be cloned up into T1.
|
|
|
|
define i32 @test5(i1 %cond, i1 %cond2) {
|
|
|
|
; CHECK: @test5
|
|
|
|
|
|
|
|
br i1 %cond, label %T1, label %F1
|
|
|
|
|
|
|
|
T1:
|
|
|
|
; CHECK: T1:
|
|
|
|
; CHECK-NEXT: %v1 = call i32 @f1()
|
|
|
|
; CHECK-NEXT: %cond3 = icmp eq i32 %v1, 412
|
|
|
|
; CHECK-NEXT: br i1 %cond3, label %T2, label %F2
|
|
|
|
|
|
|
|
%v1 = call i32 @f1()
|
|
|
|
%cond3 = icmp eq i32 %v1, 412
|
|
|
|
br label %Merge
|
|
|
|
|
|
|
|
F1:
|
|
|
|
%v2 = call i32 @f2()
|
|
|
|
br label %Merge
|
|
|
|
|
|
|
|
Merge:
|
|
|
|
%A = phi i1 [%cond3, %T1], [%cond2, %F1]
|
|
|
|
%B = phi i32 [%v1, %T1], [%v2, %F1]
|
|
|
|
br i1 %A, label %T2, label %F2
|
|
|
|
|
|
|
|
T2:
|
|
|
|
call void @f3()
|
|
|
|
ret i32 %B
|
|
|
|
|
|
|
|
F2:
|
|
|
|
ret i32 %B
|
|
|
|
}
|
|
|
|
|
2009-10-12 02:39:58 +08:00
|
|
|
|
|
|
|
;; Lexically duplicated conditionals should be threaded.
|
|
|
|
|
|
|
|
|
|
|
|
define i32 @test6(i32 %A) {
|
|
|
|
; CHECK: @test6
|
|
|
|
%tmp455 = icmp eq i32 %A, 42
|
|
|
|
br i1 %tmp455, label %BB1, label %BB2
|
|
|
|
|
|
|
|
BB2:
|
|
|
|
; CHECK: call i32 @f1()
|
|
|
|
; CHECK-NEXT: call void @f3()
|
|
|
|
; CHECK-NEXT: ret i32 4
|
|
|
|
call i32 @f1()
|
|
|
|
br label %BB1
|
|
|
|
|
|
|
|
|
|
|
|
BB1:
|
|
|
|
%tmp459 = icmp eq i32 %A, 42
|
|
|
|
br i1 %tmp459, label %BB3, label %BB4
|
|
|
|
|
|
|
|
BB3:
|
|
|
|
call i32 @f2()
|
|
|
|
ret i32 3
|
|
|
|
|
|
|
|
BB4:
|
|
|
|
call void @f3()
|
|
|
|
ret i32 4
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-07 16:05:03 +08:00
|
|
|
;; This tests that the branch in 'merge' can be cloned up into T1.
|
|
|
|
;; rdar://7367025
|
|
|
|
define i32 @test7(i1 %cond, i1 %cond2) {
|
|
|
|
Entry:
|
|
|
|
; CHECK: @test7
|
|
|
|
%v1 = call i32 @f1()
|
|
|
|
br i1 %cond, label %Merge, label %F1
|
|
|
|
|
|
|
|
F1:
|
|
|
|
%v2 = call i32 @f2()
|
|
|
|
br label %Merge
|
|
|
|
|
|
|
|
Merge:
|
|
|
|
%B = phi i32 [%v1, %Entry], [%v2, %F1]
|
|
|
|
%M = icmp ne i32 %B, %v1
|
|
|
|
%N = icmp eq i32 %B, 47
|
|
|
|
%O = and i1 %M, %N
|
|
|
|
br i1 %O, label %T2, label %F2
|
2009-10-12 02:39:58 +08:00
|
|
|
|
2009-11-07 16:05:03 +08:00
|
|
|
; CHECK: Merge:
|
|
|
|
; CHECK-NOT: phi
|
|
|
|
; CHECK-NEXT: %v2 = call i32 @f2()
|
|
|
|
|
|
|
|
T2:
|
|
|
|
call void @f3()
|
|
|
|
ret i32 %B
|
|
|
|
|
|
|
|
F2:
|
|
|
|
ret i32 %B
|
|
|
|
; CHECK: F2:
|
|
|
|
; CHECK-NEXT: phi i32
|
|
|
|
}
|
2009-10-12 02:39:58 +08:00
|
|
|
|