[llvm] [BranchFolding] Merge debug locs on common hoisted code (PR #140063)
Mikael Holmén via llvm-commits
llvm-commits at lists.llvm.org
Thu May 22 00:39:33 PDT 2025
mikaelholmen wrote:
> Hi @OCHyams
>
> I started seeing crashes with this patch for my downstream target. I managed to reduce and then reproduce it for ARM with `llc -mtriple=armv7-apple-ios bbi-107255_arm.mir -o - -run-pass=branch-folder`
>
> It crashes with
>
> ```
> llc: ../lib/CodeGen/BranchFolding.cpp:2097: bool llvm::BranchFolder::HoistCommonCodeInSuccs(MachineBasicBlock *): Assertion `TI->isIdenticalTo(*FI, MachineInstr::CheckDefs) && "Expected non-debug lockstep"' failed.
> PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
> Stack dump:
> 0. Program arguments: build-all/bin/llc -mtriple=armv7-apple-ios bbi-107255_arm.mir -o - -run-pass=branch-folder
> 1. Running pass 'Function Pass Manager' on module 'bbi-107255_arm.mir'.
> 2. Running pass 'Control Flow Optimizer' on function '@f_1418_2054'
> #0 0x00005629c40322a6 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (build-all/bin/llc+0x76d22a6)
> #1 0x00005629c402fd8e llvm::sys::RunSignalHandlers() (build-all/bin/llc+0x76cfd8e)
> #2 0x00005629c40329d9 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
> #3 0x00007fa8fc4c7d10 __restore_rt (/lib64/libpthread.so.0+0x12d10)
> #4 0x00007fa8f9e6752f raise (/lib64/libc.so.6+0x4e52f)
> #5 0x00007fa8f9e3ae65 abort (/lib64/libc.so.6+0x21e65)
> #6 0x00007fa8f9e3ad39 _nl_load_domain.cold.0 (/lib64/libc.so.6+0x21d39)
> #7 0x00007fa8f9e5fe86 (/lib64/libc.so.6+0x46e86)
> #8 0x00005629c2e5c974 llvm::BranchFolder::HoistCommonCodeInSuccs(llvm::MachineBasicBlock*) BranchFolding.cpp:0:0
> #9 0x00005629c2e53c25 llvm::BranchFolder::OptimizeFunction(llvm::MachineFunction&, llvm::TargetInstrInfo const*, llvm::TargetRegisterInfo const*, llvm::MachineLoopInfo*, bool) BranchFolding.cpp:0:0
> #10 0x00005629c2e5d10b (anonymous namespace)::BranchFolderLegacy::runOnMachineFunction(llvm::MachineFunction&) BranchFolding.cpp:0:0
> #11 0x00005629c3062c67 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (build-all/bin/llc+0x6702c67)
> #12 0x00005629c35bb3d9 llvm::FPPassManager::runOnFunction(llvm::Function&) (build-all/bin/llc+0x6c5b3d9)
> #13 0x00005629c35c39d2 llvm::FPPassManager::runOnModule(llvm::Module&) (build-all/bin/llc+0x6c639d2)
> #14 0x00005629c35bbeb8 llvm::legacy::PassManagerImpl::run(llvm::Module&) (build-all/bin/llc+0x6c5beb8)
> #15 0x00005629c0fcf6dd compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0
> #16 0x00005629c0fccdc0 main (build-all/bin/llc+0x466cdc0)
> #17 0x00007fa8f9e537e5 __libc_start_main (/lib64/libc.so.6+0x3a7e5)
> #18 0x00005629c0fcc22e _start (build-all/bin/llc+0x466c22e)
> Abort (core dumped)
> ```
>
> [bbi-107255_arm.mir.gz](https://github.com/user-attachments/files/20382281/bbi-107255_arm.mir.gz)
I think the problem happens when we come to BranchFolder::HoistCommonCodeInSuccs and TBB and FBB are the same block and we still go ahead and hoist and then after
```
++FI;
```
FI suddenly points to an instruction in MBB.
https://github.com/llvm/llvm-project/pull/140063
More information about the llvm-commits
mailing list