Created attachment 24164 [details] LLVM IR to reproduce the crash ``` % ./bin/llc ../build/bugpoint-reduced-simplified.ll -filetype=obj -mcpu=apple-a12 -march=arm64 -O0 Assertion failed: (TmpVec.size() > 1), function buildUnmerge, file /Users/shepmaster/Projects/llvm-project/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp, line 609. PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace. Stack dump: 0. Program arguments: ./bin/llc ../build/bugpoint-reduced-simplified.ll -filetype=obj -mcpu=apple-a12 -march=arm64 -O0 1. Running pass 'Function Pass Manager' on module '../build/bugpoint-reduced-simplified.ll'. 2. Running pass 'Legalizer' on function '@_ZN3std2io5stdio8print_to17h83af8c48359573cfE' 0 llc 0x0000000106c22658 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 76 1 llc 0x0000000106c22b68 PrintStackTraceSignalHandler(void*) + 32 2 llc 0x0000000106c20bd8 llvm::sys::RunSignalHandlers() + 124 3 llc 0x0000000106c24ac4 SignalHandler(int) + 208 4 libsystem_platform.dylib 0x000000018941cc44 _sigtramp + 56 5 libsystem_pthread.dylib 0x00000001893d4c24 pthread_kill + 292 6 libsystem_c.dylib 0x000000018931c864 abort + 104 7 libsystem_c.dylib 0x000000018931bb68 err + 0 8 llc 0x000000010729d1dc llvm::MachineIRBuilder::buildUnmerge(llvm::ArrayRef<llvm::Register>, llvm::SrcOp const&) + 168 9 llc 0x000000010724c894 llvm::LegalizerHelper::extractParts(llvm::Register, llvm::LLT, int, llvm::SmallVectorImpl<llvm::Register>&) + 248 10 llc 0x0000000107244c08 llvm::LegalizerHelper::narrowScalar(llvm::MachineInstr&, unsigned int, llvm::LLT) + 8564 11 llc 0x0000000107241ec0 llvm::LegalizerHelper::legalizeInstrStep(llvm::MachineInstr&) + 492 12 llc 0x000000010722bf48 llvm::Legalizer::legalizeMachineFunction(llvm::MachineFunction&, llvm::LegalizerInfo const&, llvm::ArrayRef<llvm::GISelChangeObserver*>, llvm::LostDebugLocObserver&, llvm::MachineIRBuilder&) + 1104 13 llc 0x000000010722da2c llvm::Legalizer::runOnMachineFunction(llvm::MachineFunction&) + 964 14 llc 0x000000010552ce70 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 460 15 llc 0x0000000105d4a29c llvm::FPPassManager::runOnFunction(llvm::Function&) + 548 16 llc 0x0000000105d51a68 llvm::FPPassManager::runOnModule(llvm::Module&) + 116 17 llc 0x0000000105d4ab08 (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) + 688 18 llc 0x0000000105d4a6a0 llvm::legacy::PassManagerImpl::run(llvm::Module&) + 272 19 llc 0x0000000105d51e84 llvm::legacy::PassManager::run(llvm::Module&) + 36 20 llc 0x0000000104597258 compileModule(char**, llvm::LLVMContext&) + 5304 21 llc 0x0000000104595590 main + 1288 22 libdyld.dylib 0x00000001893f0f54 start + 4 ``` Doing some light debugging, I see that `NumParts` is `1`; this is what triggers the assertion. This is computed from `SizeOp0 / NarrowSize` when `SizeOp0` is `120` and `NarrowSize` is `64`. The Rust fork is currently at 2e10b7a39b930ef8d9c4362509d8835b221fbc0a. git-bisect says that the attached LLVM IR compiles successfully starting at db464a3dbf0e8fed363a7b2b9a5b320514ca60f8. However, I don't believe that the bug is actually *fixed*, merely hidden. The commit in question performs more transformations to the code and causes `SizeOp0` to be 128. When I cherry-picked that commit back to the Rust fork, the problems continue to manifest.
Looking elsewhere in the file, I see this code: ``` // FIXME: add support for when SizeOp0 isn't an exact multiple of // NarrowSize. if (SizeOp0 % NarrowSize != 0) return UnableToLegalize; ``` Applying an equivalent patch to the `G_PHI` case **does** appear to fix the issue in the Rust repository: ``` diff --git a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp index 244e7a9583d..5ee9ba91760 100644 --- a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp +++ b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp @@ -1024,6 +1024,11 @@ LegalizerHelper::LegalizeResult LegalizerHelper::narrowScalar(MachineInstr &MI, Observer.changedInstr(MI); return Legalized; case TargetOpcode::G_PHI: { + // FIXME: add support for when SizeOp0 isn't an exact multiple of + // NarrowSize. + if (SizeOp0 % NarrowSize != 0) + return UnableToLegalize; + unsigned NumParts = SizeOp0 / NarrowSize; SmallVector<Register, 2> DstRegs(NumParts); SmallVector<SmallVector<Register, 2>, 2> SrcRegs(MI.getNumOperands() / 2); ```
Encountered what I believe is the same issue during the LLVM 12 upgrade in rustc, with the following reduced test case: ; RUN: llc -O0 < %s target triple = "aarch64-unknown-linux-gnu" define void @test() { entry: br label %loop loop: %p = phi i72 [ 0, %entry ], [ %p, %loop ] br label %loop }
Existing candidate patch: https://reviews.llvm.org/D92446
Fixed by https://github.com/llvm/llvm-project/commit/c35761db0f078f74550ef56bfc0745c162d76967 on main.
Merged: 52510d84802b