Index: llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp =================================================================== --- llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp +++ llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp @@ -3085,9 +3085,11 @@ NewEntryBB.sortUniqueLiveIns(); // Get rid of the now empty basic block. + int EntryBBNumber = EntryBB->getNumber(); EntryBB->removeSuccessor(&NewEntryBB); MF->remove(EntryBB); MF->DeleteMachineBasicBlock(EntryBB); + NewEntryBB.setNumber(EntryBBNumber); assert(&MF->front() == &NewEntryBB && "New entry wasn't next in the list of basic block!"); Index: llvm/test/CodeGen/X86/rename-new-entry.ll =================================================================== --- /dev/null +++ llvm/test/CodeGen/X86/rename-new-entry.ll @@ -0,0 +1,49 @@ +;; Test if the entry basic block names start with bb.0.entry when using +;; GlobalISel +; RUN: llc -global-isel %s -stop-after=finalize-isel -o %t.mir +; RUN: cat %t.mir | FileCheck %s +; CHECK: name: fn1 +; CHECK: bb.0.entry: +; CHECK: name: fn3 +; CHECK: bb.0.entry: +; CHECK: name: fn2 +; CHECK: bb.0.entry: + +; ModuleID = 'test/CodeGen/X86/rename-new-entry.c' +source_filename = "test/CodeGen/X86/rename-new-entry.c" +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +; Function Attrs: noinline nounwind uwtable +define dso_local i32 @fn1(i32 %a) local_unnamed_addr { +entry: + %c = add i32 %a, 2 + ret i32 %c +} + +; Function Attrs: noinline nounwind uwtable +define dso_local i32 @fn3(i32 %a, i32 %b, i32 %c) local_unnamed_addr { +entry: + %d = add i32 %a, %b + %e = mul i32 %d, %c + %f = call i32 @fn1(i32 %e) + ret i32 %f +} + +; Function Attrs: noinline nounwind uwtable +define dso_local i64 @fn2(i32 %a, i32 %b, i32 %c) local_unnamed_addr { +entry: + %call = call i32 @fn1(i32 5) + %add = mul i32 %a, 3 + %sub = sub i32 %add, %b + %add2 = add i32 %sub, %c + %conv4 = sext i32 %add2 to i64 + %call2 = call i32 @fn3(i32 5, i32 %add2, i32 %add2) + ret i64 %conv4 +} + +!llvm.module.flags = !{!0} +!llvm.ident = !{!1} + +!0 = !{i32 1, !"wchar_size", i32 4} +!1 = !{!"clang version 9.0.0"}