[LICM] Fix a small oversight introduced in r256763
[oota-llvm.git] / test / Transforms / LICM / funclet.ll
1 ; RUN: opt < %s -licm -S | FileCheck %s
2
3 target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
4 target triple = "i386-pc-windows-msvc18.0.0"
5
6 define void @test1(i32* %s, i1 %b) personality i32 (...)* @__CxxFrameHandler3 {
7 entry:
8   br label %while.cond
9
10 while.cond:                                       ; preds = %while.body, %entry
11   %0 = call i32 @pure_computation()
12   br i1 %b, label %try.cont, label %while.body
13
14 while.body:                                       ; preds = %while.cond
15   invoke void @may_throw()
16           to label %while.cond unwind label %catch.dispatch
17
18 catch.dispatch:                                   ; preds = %while.body
19   %.lcssa1 = phi i32 [ %0, %while.body ]
20   %cs = catchswitch within none [label %catch] unwind to caller
21
22 catch:                                            ; preds = %catch.dispatch
23   %cp = catchpad within %cs [i8* null, i32 64, i8* null]
24   store i32 %.lcssa1, i32* %s
25   catchret from %cp to label %try.cont
26
27 try.cont:                                         ; preds = %catch, %while.cond
28   ret void
29 }
30
31 ; CHECK-LABEL: define void @test1(
32 ; CHECK: %[[CALL:.*]] = call i32 @pure_computation()
33 ; CHECK: phi i32 [ %[[CALL]]
34
35 define void @test2(i32* %s, i1 %b) personality i32 (...)* @__CxxFrameHandler3 {
36 entry:
37   br label %while.cond
38
39 while.cond:                                       ; preds = %while.body, %entry
40   %0 = call i32 @pure_computation()
41   br i1 %b, label %try.cont, label %while.body
42
43 while.body:                                       ; preds = %while.cond
44   invoke void @may_throw()
45           to label %while.cond unwind label %catch.dispatch
46
47 catch.dispatch:                                   ; preds = %while.body
48   %.lcssa1 = phi i32 [ %0, %while.body ]
49   %cp = cleanuppad within none []
50   store i32 %.lcssa1, i32* %s
51   cleanupret from %cp unwind to caller
52
53 try.cont:                                         ; preds = %catch, %while.cond
54   ret void
55 }
56
57 ; CHECK-LABEL: define void @test2(
58 ; CHECK:      %[[CP:.*]] = cleanuppad within none []
59 ; CHECK-NEXT: %[[CALL:.*]] = call i32 @pure_computation() [ "funclet"(token %[[CP]]) ]
60 ; CHECK-NEXT: store i32 %[[CALL]], i32* %s
61 ; CHECK-NEXT: cleanupret from %[[CP]] unwind to caller
62
63 define void @test3(i1 %a, i1 %b, i1 %c) personality i32 (...)* @__CxxFrameHandler3 {
64 entry:
65   %.frame = alloca i8, align 4
66   %.frame2 = alloca i8, align 4
67   %bc = bitcast i8* %.frame to i32*
68   %bc2 = bitcast i8* %.frame2 to i32*
69   br i1 %a, label %try.success.or.caught, label %forbody
70
71 catch.object.Throwable:                           ; preds = %catch.dispatch
72   %cp = catchpad within %cs [i8* null, i32 64, i8* null]
73   unreachable
74
75 try.success.or.caught:                            ; preds = %forcond.backedge, %0
76   ret void
77
78 postinvoke:                                       ; preds = %forbody
79   br i1 %b, label %else, label %forcond.backedge
80
81 forcond.backedge:                                 ; preds = %else, %postinvoke
82   br i1 %c, label %try.success.or.caught, label %forbody
83
84 catch.dispatch:                                   ; preds = %else, %forbody
85   %cs = catchswitch within none [label %catch.object.Throwable] unwind to caller
86
87 forbody:                                          ; preds = %forcond.backedge, %0
88   store i32 1, i32* %bc, align 4
89   store i32 2, i32* %bc2, align 4
90   invoke void @may_throw()
91           to label %postinvoke unwind label %catch.dispatch
92
93 else:                                             ; preds = %postinvoke
94   invoke void @may_throw()
95           to label %forcond.backedge unwind label %catch.dispatch
96 }
97
98 ; CHECK-LABEL: define void @test3(
99 ; CHECK:      catchswitch within none
100 ; CHECK:      store i32 1, i32* %bc, align 4
101 ; CHECK:      store i32 2, i32* %bc2, align 4
102
103 declare void @may_throw()
104
105 declare i32 @pure_computation() nounwind argmemonly readonly
106
107 declare i32 @__CxxFrameHandler3(...)