Index: llvm/lib/CodeGen/TailDuplicator.cpp =================================================================== --- llvm/lib/CodeGen/TailDuplicator.cpp +++ llvm/lib/CodeGen/TailDuplicator.cpp @@ -731,6 +731,13 @@ LLVM_DEBUG(dbgs() << "\nTail-duplicating into PredBB: " << *PredBB << "From simple Succ: " << *TailBB); + MachineFunction *MF = TailBB->getParent(); + // Update the call site info. + std::for_each(TailBB->begin(), TailBB->end(), [MF](const MachineInstr &MI) { + if (MI.isCandidateForCallSiteEntry()) + MF->eraseCallSiteInfo(&MI); + }); + MachineBasicBlock *NewTarget = *TailBB->succ_begin(); MachineBasicBlock *NextBB = PredBB->getNextNode(); @@ -852,6 +859,13 @@ LLVM_DEBUG(dbgs() << "\nTail-duplicating into PredBB: " << *PredBB << "From Succ: " << *TailBB); + MachineFunction *MF = TailBB->getParent(); + // Update the call site info. + std::for_each(TailBB->begin(), TailBB->end(), [MF](const MachineInstr &MI) { + if (MI.isCandidateForCallSiteEntry()) + MF->eraseCallSiteInfo(&MI); + }); + TDBBs.push_back(PredBB); // Remove PredBB's unconditional branch. Index: llvm/test/CodeGen/X86/call-site-update-taildup.ll =================================================================== --- /dev/null +++ llvm/test/CodeGen/X86/call-site-update-taildup.ll @@ -0,0 +1,55 @@ +; RUN: llc < %s -tail-dup-placement-threshold=4 -debug-entry-values=1 -stop-before=machineverifier | FileCheck %s + +;; Ensure that we removed the call site info during the tail duplication. +;; The test was handmade. +; CHECK: callSites: [] + +; ModuleID = 'test.cpp' +source_filename = "test.cpp" +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +define dso_local void @taildupit(i32* readonly %ptr_size) !dbg !8 { +entry: + call void @llvm.dbg.value(metadata i32* %ptr_size, metadata !14, metadata !DIExpression()), !dbg !17 + %tobool = icmp eq i32* %ptr_size, null, !dbg !17 + br i1 %tobool, label %cond.end, label %cond.true, !dbg !17 + +cond.true: ; preds = %entry + %0 = load i32, i32* %ptr_size, align 4, !dbg !17 + br label %cond.end, !dbg !17 + +cond.end: ; preds = %entry, %cond.true + %cond = phi i32 [ %0, %cond.true ], [ 1, %entry ], !dbg !17 + %call = tail call i8* @f(i32 %cond), !dbg !17, !heapallocsite !2 + call void @llvm.dbg.value(metadata i8* %call, metadata !15, metadata !DIExpression()), !dbg !17 + tail call void @f2(), !dbg !17 + ret void, !dbg !17 +} + +declare dso_local i8* @f(i32) + +declare dso_local void @f2() + +declare void @llvm.dbg.value(metadata, metadata, metadata) + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4, !5, !6} + +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 11.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None) +!1 = !DIFile(filename: "test.cpp", directory: "/dir") +!2 = !{} +!3 = !{i32 7, !"Dwarf Version", i32 4} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{i32 1, !"wchar_size", i32 4} +!6 = !{i32 7, !"PIC Level", i32 2} +!8 = distinct !DISubprogram(name: "f1", linkageName: "f1", scope: !1, file: !1, line: 5, type: !9, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !13) +!9 = !DISubroutineType(types: !10) +!10 = !{null, !11} +!11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64) +!12 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned) +!13 = !{!14, !15} +!14 = !DILocalVariable(name: "ptr_size", arg: 1, scope: !8, file: !1, line: 5, type: !11) +!15 = !DILocalVariable(name: "local", scope: !8, file: !1, line: 6, type: !16) +!16 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64) +!17 = !DILocation(line: 0, scope: !8)