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