c0b63b7d6d9e0a5a89424a3d90a07855839fc01f
[oota-llvm.git] / test / Transforms / CodeGenPrepare / catchpad-phi-cast.ll
1 ; RUN: opt -codegenprepare -S < %s | FileCheck %s
2
3 ; The following target lines are needed for the test to exercise what it should.
4 ; Without these lines, CodeGenPrepare does not try to sink the bitcasts.
5 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
6 target triple = "x86_64-pc-windows-msvc"
7
8 declare i32 @__CxxFrameHandler3(...)
9
10 declare void @f()
11
12 declare void @g(i8*)
13 declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #2
14
15 ; CodeGenPrepare will want to sink these bitcasts, but it selects the catchpad
16 ; blocks as the place to which the bitcast should be sunk.  Since catchpads
17 ; do not allow non-phi instructions before the terminator, this isn't possible. 
18
19 ; CHECK-LABEL: @test(
20 define void @test(i32* %addr) personality i32 (...)* @__CxxFrameHandler3 {
21 ; CHECK: entry:
22 ; CHECK-NEXT: %x = getelementptr i32, i32* %addr, i32 1
23 ; CHECK-NEXT: %p1 = bitcast i32* %x to i8*
24 entry:
25   %x = getelementptr i32, i32* %addr, i32 1
26   %p1 = bitcast i32* %x to i8*
27   invoke void @f()
28           to label %invoke.cont unwind label %catch1
29
30 ; CHECK: invoke.cont:
31 ; CHECK-NEXT: %y = getelementptr i32, i32* %addr, i32 2
32 ; CHECK-NEXT: %p2 = bitcast i32* %y to i8*
33 invoke.cont:
34   %y = getelementptr i32, i32* %addr, i32 2
35   %p2 = bitcast i32* %y to i8*
36   invoke void @f()
37           to label %done unwind label %catch2
38
39 done:
40   ret void
41
42 catch1:
43   %cp1 = catchpad [] to label %catch.dispatch unwind label %catchend1
44
45 catch2:
46   %cp2 = catchpad [] to label %catch.dispatch unwind label %catchend2
47
48 ; CHECK: catch.dispatch:
49 ; CHECK-NEXT: %p = phi i8* [ %p1, %catch1 ], [ %p2, %catch2 ]
50 catch.dispatch:
51   %p = phi i8* [ %p1, %catch1 ], [ %p2, %catch2 ]
52   call void @g(i8* %p)
53   unreachable
54
55 catchend1:
56   catchendpad unwind to caller
57
58 catchend2:
59   catchendpad unwind to caller
60 }
61
62 ; CodeGenPrepare will want to hoist these llvm.dbg.value calls to the phi, but
63 ; there is no insertion point in a catchpad block.
64
65 ; CHECK-LABEL: @test_dbg_value(
66 define void @test_dbg_value() personality i32 (...)* @__CxxFrameHandler3 {
67 entry:
68   %a = alloca i8
69   %b = alloca i8
70   invoke void @f() to label %next unwind label %catch.dispatch
71 next:
72   invoke void @f() to label %ret unwind label %catch.dispatch
73 ret:
74   ret void
75
76 catch.dispatch:
77   %p = phi i8* [%a, %entry], [%b, %next]
78   %cp1 = catchpad [] to label %catch unwind label %catchend
79
80 catch:
81   tail call void @llvm.dbg.value(metadata i8* %p, i64 0, metadata !11, metadata !13), !dbg !14
82   invoke void @g(i8* %p) to label %catchret unwind label %catchend
83 catchret:
84   catchret %cp1 to label %ret
85
86 ; CHECK: catch.dispatch:
87 ; CHECK-NEXT: phi i8
88 ; CHECK-NEXT: catchpad
89 ; CHECK-NOT: llvm.dbg.value
90
91 ; CHECK: catch:
92 ; CHECK-NEXT: call void @llvm.dbg.value
93
94 catchend:
95   catchendpad unwind to caller
96 }
97
98 !llvm.dbg.cu = !{!0}
99 !llvm.module.flags = !{!7, !8, !9}
100 !llvm.ident = !{!10}
101
102 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.8.0 (trunk 254906) (llvm/trunk 254917)", isOptimized: false, runtimeVersion: 0, emissionKind: 1, enums: null, subprograms: !3)
103 !1 = !DIFile(filename: "t.c", directory: "D:\5Csrc\5Cllvm\5Cbuild")
104 !3 = !{!4}
105 !4 = distinct !DISubprogram(name: "test_dbg_value", scope: !1, file: !1, line: 1, type: !5, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: false, variables: null)
106 !5 = !DISubroutineType(types: !6)
107 !6 = !{null}
108 !7 = !{i32 2, !"Dwarf Version", i32 4}
109 !8 = !{i32 2, !"Debug Info Version", i32 3}
110 !9 = !{i32 1, !"PIC Level", i32 2}
111 !10 = !{!"clang version 3.8.0 (trunk 254906) (llvm/trunk 254917)"}
112 !11 = !DILocalVariable(name: "p", scope: !4, file: !1, line: 2, type: !12)
113 !12 = !DIBasicType(name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char)
114 !13 = !DIExpression()
115 !14 = !DILocation(line: 2, column: 8, scope: !4)
116 !15 = !DILocation(line: 3, column: 1, scope: !4)