1; RUN: llc < %s -tail-dup-placement-threshold=4 | FileCheck %s
2
3; Based on test case from PR43695:
4; __declspec(allocator) void *alloc(unsigned int size);
5; void f2();
6; void f1(unsigned int *size_ptr) {
7;     void *hg = alloc(size_ptr ? *size_ptr : 1UL);
8;     f2();
9; }
10
11; In this case, block placement duplicates the heap allocation site.
12
13; ModuleID = 't.cpp'
14source_filename = "t.cpp"
15target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
16target triple = "x86_64-pc-windows-msvc19.22.27905"
17
18define dso_local void @taildupit(i32* readonly %size_ptr) !dbg !8 {
19entry:
20  call void @llvm.dbg.value(metadata i32* %size_ptr, metadata !14, metadata !DIExpression()), !dbg !17
21  %tobool = icmp eq i32* %size_ptr, null, !dbg !18
22  br i1 %tobool, label %cond.end, label %cond.true, !dbg !18
23
24cond.true:                                        ; preds = %entry
25  %0 = load i32, i32* %size_ptr, align 4, !dbg !18, !tbaa !19
26  br label %cond.end, !dbg !18
27
28cond.end:                                         ; preds = %entry, %cond.true
29  %cond = phi i32 [ %0, %cond.true ], [ 1, %entry ], !dbg !18
30  %call = tail call i8* @alloc(i32 %cond), !dbg !18, !heapallocsite !2
31  call void @llvm.dbg.value(metadata i8* %call, metadata !15, metadata !DIExpression()), !dbg !17
32  tail call void @f2(), !dbg !23
33  ret void, !dbg !24
34}
35
36; CHECK-LABEL: taildupit: # @taildupit
37; CHECK: testq
38; CHECK: je
39; CHECK: callq alloc
40; CHECK-NEXT: [[L1:.Ltmp[0-9]+]]
41; CHECK: jmp f2 # TAILCALL
42; CHECK: callq alloc
43; CHECK-NEXT: [[L3:.Ltmp[0-9]+]]
44; CHECK: jmp f2 # TAILCALL
45
46; CHECK-LABEL: .short 4423                    # Record kind: S_GPROC32_ID
47; CHECK:       .short 4446                    # Record kind: S_HEAPALLOCSITE
48; CHECK-NEXT:  .secrel32 [[L0:.Ltmp[0-9]+]]
49; CHECK-NEXT:  .secidx [[L0]]
50; CHECK-NEXT:  .short [[L1]]-[[L0]]
51; CHECK-NEXT:  .long 3
52; CHECK:       .short 4446                    # Record kind: S_HEAPALLOCSITE
53; CHECK-NEXT:  .secrel32 [[L2:.Ltmp[0-9]+]]
54; CHECK-NEXT:  .secidx [[L2]]
55; CHECK-NEXT:  .short [[L3]]-[[L2]]
56; CHECK-NEXT:  .long 3
57
58declare dso_local i8* @alloc(i32)
59
60declare dso_local void @f2()
61
62declare void @llvm.dbg.value(metadata, metadata, metadata)
63
64!llvm.dbg.cu = !{!0}
65!llvm.module.flags = !{!3, !4, !5, !6}
66
67!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 10.0.0 (git@github.com:llvm/llvm-project.git 0650355c09ab8e6605ae37b818270a7a7c8ce2c7)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
68!1 = !DIFile(filename: "t.cpp", directory: "C:\\src\\llvm-project\\build", checksumkind: CSK_MD5, checksum: "b227901e92d848fa564190b0762d757c")
69!2 = !{}
70!3 = !{i32 2, !"CodeView", i32 1}
71!4 = !{i32 2, !"Debug Info Version", i32 3}
72!5 = !{i32 1, !"wchar_size", i32 2}
73!6 = !{i32 7, !"PIC Level", i32 2}
74!8 = distinct !DISubprogram(name: "f1", linkageName: "?f1@@YAXPEAI@Z", scope: !1, file: !1, line: 5, type: !9, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !13)
75!9 = !DISubroutineType(types: !10)
76!10 = !{null, !11}
77!11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64)
78!12 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
79!13 = !{!14, !15}
80!14 = !DILocalVariable(name: "size_ptr", arg: 1, scope: !8, file: !1, line: 5, type: !11)
81!15 = !DILocalVariable(name: "hg", scope: !8, file: !1, line: 6, type: !16)
82!16 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
83!17 = !DILocation(line: 0, scope: !8)
84!18 = !DILocation(line: 6, scope: !8)
85!19 = !{!20, !20, i64 0}
86!20 = !{!"int", !21, i64 0}
87!21 = !{!"omnipotent char", !22, i64 0}
88!22 = !{!"Simple C++ TBAA"}
89!23 = !DILocation(line: 7, scope: !8)
90!24 = !DILocation(line: 8, scope: !8)
91