1; RUN: opt < %s -S -passes='speculative-execution' | FileCheck %s
2
3%class.B = type { i32 (...)** }
4
5; Testing that two bitcasts are not hoisted to the first BB
6define i8* @foo(%class.B* readonly %b) {
7; CHECK-LABEL: foo
8; CHECK-LABEL: entry
9; CHECK-NEXT: %i = icmp eq %class.B* %b, null
10; CHECK-NEXT: br i1 %i, label %end, label %notnull
11entry:
12  %i = icmp eq %class.B* %b, null
13  br i1 %i, label %end, label %notnull
14
15; CHECK-LABEL: notnull:
16; CHECK-NEXT: %i1 = bitcast %class.B* %b to i32**
17; CHECK: %i3 = bitcast %class.B* %b to i8*
18notnull:                             ; preds = %entry
19  %i1 = bitcast %class.B* %b to i32**
20  %vtable = load i32*, i32** %i1, align 8
21  %i2 = getelementptr inbounds i32, i32* %vtable, i64 -2
22  %offset.to.top = load i32, i32* %i2, align 4
23  %i3 = bitcast %class.B* %b to i8*
24  %i4 = sext i32 %offset.to.top to i64
25  %i5 = getelementptr inbounds i8, i8* %i3, i64 %i4
26  br label %end
27
28end:                                 ; preds = %notnull, %entry
29  %i6 = phi i8* [ %i5, %notnull ], [ null, %entry ]
30  ret i8* %i6
31}
32
33define void @f(i32 %i) {
34entry:
35; CHECK-LABEL: @f(
36; CHECK:  %a2 = add i32 %i, 0
37; CHECK-NEXT:  call void @llvm.dbg.value(metadata i32 %a2
38  br i1 undef, label %land.rhs, label %land.end
39
40land.rhs:                                         ; preds = %entry
41; CHECK: land.rhs:
42; CHECK-NEXT: call void @llvm.dbg.label
43; CHECK-NEXT: %x = alloca i32, align 4
44; CHECK-NEXT: call void @llvm.dbg.addr(metadata i32* %x
45; CHECK-NEXT: %y = alloca i32, align 4
46; CHECK-NEXT: call void @llvm.dbg.declare(metadata i32* %y
47; CHECK-NEXT: %a0 = load i32, i32* undef, align 1
48; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 %a0
49  call void @llvm.dbg.label(metadata !11), !dbg !10
50  %x = alloca i32, align 4
51  call void @llvm.dbg.addr(metadata i32* %x, metadata !12, metadata !DIExpression()), !dbg !10
52  %y = alloca i32, align 4
53  call void @llvm.dbg.declare(metadata i32* %y, metadata !14, metadata !DIExpression()), !dbg !10
54
55  %a0 = load i32, i32* undef, align 1
56  call void @llvm.dbg.value(metadata i32 %a0, metadata !9, metadata !DIExpression()), !dbg !10
57
58  %a2 = add i32 %i, 0
59  call void @llvm.dbg.value(metadata i32 %a2, metadata !13, metadata !DIExpression()), !dbg !10
60
61  br label %land.end
62
63land.end:                                         ; preds = %land.rhs, %entry
64  ret void
65}
66
67; Function Attrs: nounwind readnone speculatable willreturn
68declare void @llvm.dbg.value(metadata, metadata, metadata) #1
69declare void @llvm.dbg.label(metadata)
70declare void @llvm.dbg.declare(metadata, metadata, metadata)
71declare void @llvm.dbg.addr(metadata, metadata, metadata)
72
73attributes #1 = { nounwind readnone speculatable willreturn }
74
75!llvm.dbg.cu = !{!0}
76!llvm.module.flags = !{!5}
77
78!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 11.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3, splitDebugInlining: false, nameTableKind: None)
79!1 = !DIFile(filename: "foo.c", directory: "/bar")
80!2 = !{}
81!3 = !{!4}
82!4 = !DIBasicType(name: "int", size: 16, encoding: DW_ATE_signed)
83!5 = !{i32 2, !"Debug Info Version", i32 3}
84!6 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 1, type: !7, scopeLine: 2, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
85!7 = !DISubroutineType(types: !8)
86!8 = !{null}
87!9 = !DILocalVariable(name: "a0", scope: !6, file: !1, line: 3, type: !4)
88!10 = !DILocation(line: 0, scope: !6)
89!11 = !DILabel(scope: !6, name: "label", file: !1, line: 1)
90!12 = !DILocalVariable(name: "x", scope: !6, file: !1, line: 3, type: !4)
91!13 = !DILocalVariable(name: "a2", scope: !6, file: !1, line: 3, type: !4)
92!14 = !DILocalVariable(name: "y", scope: !6, file: !1, line: 3, type: !4)
93