1 ; RUN: opt -codegenprepare -S < %s | FileCheck %s
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"
8 declare i32 @__CxxFrameHandler3(...)
13 declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #2
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.
20 define void @test(i32* %addr) personality i32 (...)* @__CxxFrameHandler3 {
22 %x = getelementptr i32, i32* %addr, i32 1
23 %p1 = bitcast i32* %x to i8*
25 to label %invoke.cont unwind label %catch1
28 ; CHECK-NEXT: %y = getelementptr i32, i32* %addr, i32 2
30 %y = getelementptr i32, i32* %addr, i32 2
31 %p2 = bitcast i32* %y to i8*
33 to label %done unwind label %catch2
39 %cs1 = catchswitch within none [label %handler1] unwind to caller
42 %cp1 = catchpad within %cs1 []
43 br label %catch.shared
45 ; CHECK-NEXT: catchpad within %cs1
46 ; CHECK: %[[p1:[0-9]+]] = bitcast i32* %x to i8*
49 %cs2 = catchswitch within none [label %handler2] unwind to caller
52 %cp2 = catchpad within %cs2 []
53 br label %catch.shared
55 ; CHECK: catchpad within %cs2
56 ; CHECK: %[[p2:[0-9]+]] = bitcast i32* %y to i8*
58 ; CHECK: catch.shared:
59 ; CHECK-NEXT: %p = phi i8* [ %[[p1]], %handler1 ], [ %[[p2]], %handler2 ]
61 %p = phi i8* [ %p1, %handler1 ], [ %p2, %handler2 ]
66 ; CodeGenPrepare will want to hoist these llvm.dbg.value calls to the phi, but
67 ; there is no insertion point in a catchpad block.
69 ; CHECK-LABEL: @test_dbg_value(
70 define void @test_dbg_value() personality i32 (...)* @__CxxFrameHandler3 {
74 invoke void @f() to label %next unwind label %catch.dispatch
76 invoke void @f() to label %ret unwind label %catch.dispatch
81 %p = phi i8* [%a, %entry], [%b, %next]
82 %cs1 = catchswitch within none [label %catch] unwind to caller
85 %cp1 = catchpad within %cs1 []
86 tail call void @llvm.dbg.value(metadata i8* %p, i64 0, metadata !11, metadata !13), !dbg !14
88 catchret from %cp1 to label %ret
90 ; CHECK: catch.dispatch:
92 ; CHECK-NEXT: catchswitch
93 ; CHECK-NOT: llvm.dbg.value
96 ; CHECK-NEXT: catchpad
97 ; CHECK-NEXT: call void @llvm.dbg.value
101 !llvm.module.flags = !{!7, !8, !9}
104 !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: FullDebug, enums: null)
105 !1 = !DIFile(filename: "t.c", directory: "D:\5Csrc\5Cllvm\5Cbuild")
106 !4 = distinct !DISubprogram(name: "test_dbg_value", scope: !1, file: !1, line: 1, type: !5, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: false, unit: !0, retainedNodes: null)
107 !5 = !DISubroutineType(types: !6)
109 !7 = !{i32 2, !"Dwarf Version", i32 4}
110 !8 = !{i32 2, !"Debug Info Version", i32 3}
111 !9 = !{i32 1, !"PIC Level", i32 2}
112 !10 = !{!"clang version 3.8.0 (trunk 254906) (llvm/trunk 254917)"}
113 !11 = !DILocalVariable(name: "p", scope: !4, file: !1, line: 2, type: !12)
114 !12 = !DIBasicType(name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char)
115 !13 = !DIExpression(DW_OP_deref)
116 !14 = !DILocation(line: 2, column: 8, scope: !4)
117 !15 = !DILocation(line: 3, column: 1, scope: !4)