Skip to content

[BranchRelaxation] Bad MIR after BranchRelaxation #162063

@sc-clulzze

Description

@sc-clulzze

After running branch-relaxation %bb.0 has only %bb.3 in its successor list, but there is also a branch to %bb.2
https://godbolt.org/z/avqYbfcz1

# After Branch relaxation pass
# Machine code for function foo: IsSSA, NoPHIs, TracksLiveness, NoVRegs

bb.0:
  successors: %bb.3(0x80000000); %bb.3(100.00%)
  liveins: $x1
  BEQ $x1, $x0, %bb.3
  PseudoBR %bb.2

bb.3:
; predecessors: %bb.0
  successors: %bb.2(0x80000000); %bb.2(100.00%)

  PseudoBR %bb.2

bb.1:
  successors: %bb.2(0x80000000); %bb.2(100.00%)
  liveins: $x1
  INLINEASM &".space 4096" [sideeffect] [attdialect]
  BGE $x1, $x0, %bb.2

bb.2:
; predecessors: %bb.1, %bb.3

  PseudoRET

# End machine code for function foo.

*** Bad machine code: MBB exits via conditional branch, but its target isn't a CFG successor! ***
- function:    foo
- basic block: %bb.0  (0x38dfe7d8)
LLVM ERROR: Found 1 machine code errors.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0.	Program arguments: /opt/compiler-explorer/clang-trunk/bin/llc -o /app/output.s -x86-asm-syntax=intel -mtriple=riscv64 -run-pass=branch-relaxation -verify-machineinstrs <source>
1.	Running pass 'Function Pass Manager' on module '<source>'.
2.	Running pass 'Verify generated machine code' on function '@foo'
 #0 0x0000000003bbb958 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk/bin/llc+0x3bbb958)
 #1 0x0000000003bb8b24 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #2 0x000076863e842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x000076863e8969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #4 0x000076863e842476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #5 0x000076863e8287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #6 0x00000000007b8462 llvm::UniqueStringSaver::save(llvm::Twine const&) (.cold) StringSaver.cpp:0:0
 #7 0x0000000002d351b6 (/opt/compiler-explorer/clang-trunk/bin/llc+0x2d351b6)
 #8 0x0000000002d3525a (anonymous namespace)::MachineVerifier::~MachineVerifier() MachineVerifier.cpp:0:0
 #9 0x0000000002d4fcdc (anonymous namespace)::MachineVerifierLegacyPass::runOnMachineFunction(llvm::MachineFunction&) (.part.0) MachineVerifier.cpp:0:0
#10 0x0000000002d4fd19 (anonymous namespace)::MachineVerifierLegacyPass::runOnMachineFunction(llvm::MachineFunction&) MachineVerifier.cpp:0:0
#11 0x0000000002c39f4d llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x2c39f4d)
#12 0x00000000031a7682 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x31a7682)
#13 0x00000000031a7911 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x31a7911)
#14 0x00000000031a91e7 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x31a91e7)
#15 0x00000000009008b9 compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0
#16 0x00000000007ccffe main (/opt/compiler-explorer/clang-trunk/bin/llc+0x7ccffe)
#17 0x000076863e829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#18 0x000076863e829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#19 0x00000000008f8105 _start (/opt/compiler-explorer/clang-trunk/bin/llc+0x8f8105)
Program terminated with signal: SIGSEGV
Compiler returned: 139

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions