[llvm] [llvm][CodeGen] Add a new software pipeliner 'Window Scheduler' (PR #84443)

Nathan Chancellor via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 17 17:30:27 PDT 2024


nathanchance wrote:

> Here is the patch with the corresponding solution. Please try it out to see if it resolves the issue. Sorry for the inconvenience. at nathanchance #95636

No worries, thanks for the forward fix! I found another crash that is not resolved with it.

```c
void *poll_for_response_data;
long poll_for_response_response_0;
int poll_for_response_crc_err_retries;
void poll_for_response(char size) {
  int i;
  char *data_byte = poll_for_response_data;
retry:
  if (poll_for_response_crc_err_retries)
    goto fail;
  {
    unsigned val = poll_for_response_response_0;
    i = 0;
    for (; i < size; i++)
      data_byte[-i - 1] = val >>= 8;
  }
  goto retry;
fail:;
}
```

```
$ clang --target=hexagon-linux -O2 -c -o /dev/null fsi-master-gpio.i
clang: /home/nathan/tmp/cvise.YaBcQe05cQ/src/llvm/lib/CodeGen/WindowScheduler.cpp:650: int llvm::WindowScheduler::getOriCycle(MachineInstr *): Assertion `TriToOri.count(NewMI) && "Cannot find original MI!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: clang --target=hexagon-linux -O2 -c -o /dev/null fsi-master-gpio.i
1.	<eof> parser at end of file
2.	Code generation
3.	Running pass 'Function Pass Manager' on module 'fsi-master-gpio.i'.
4.	Running pass 'Modulo Software Pipelining' on function '@poll_for_response'
 #0 0x000000000330fc60 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/clang-19+0x330fc60)
 #1 0x000000000330dba8 llvm::sys::RunSignalHandlers() (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/clang-19+0x330dba8)
 #2 0x00000000032992e4 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x0000ffffb26797f0 (linux-vdso.so.1+0x7f0)
 #4 0x0000ffffb20385e0 __pthread_kill_implementation (/lib64/libc.so.6+0x985e0)
 #5 0x0000ffffb1fe5a00 gsignal (/lib64/libc.so.6+0x45a00)
 #6 0x0000ffffb1fd0288 abort (/lib64/libc.so.6+0x30288)
 #7 0x0000ffffb1fde3e0 __assert_fail_base (/lib64/libc.so.6+0x3e3e0)
 #8 0x0000ffffb1fde454 (/lib64/libc.so.6+0x3e454)
 #9 0x0000000002cc5728 llvm::WindowScheduler::getOriCycle(llvm::MachineInstr*) (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/clang-19+0x2cc5728)
#10 0x0000000002cc641c llvm::WindowScheduler::schedulePhi(int, unsigned int&) (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/clang-19+0x2cc641c)
#11 0x0000000002cc2770 llvm::WindowScheduler::run() (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/clang-19+0x2cc2770)
#12 0x000000000292f16c llvm::MachinePipeliner::runWindowScheduler(llvm::MachineLoop&) (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/clang-19+0x292f16c)
#13 0x000000000292d7a4 llvm::MachinePipeliner::scheduleLoop(llvm::MachineLoop&) (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/clang-19+0x292d7a4)
#14 0x000000000292d6f4 llvm::MachinePipeliner::scheduleLoop(llvm::MachineLoop&) (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/clang-19+0x292d6f4)
#15 0x000000000292d5e8 llvm::MachinePipeliner::runOnMachineFunction(llvm::MachineFunction&) (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/clang-19+0x292d5e8)
#16 0x00000000028f0b24 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/clang-19+0x28f0b24)
#17 0x0000000002e7a160 llvm::FPPassManager::runOnFunction(llvm::Function&) (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/clang-19+0x2e7a160)
#18 0x0000000002e81be8 llvm::FPPassManager::runOnModule(llvm::Module&) (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/clang-19+0x2e81be8)
#19 0x0000000002e7aa80 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/clang-19+0x2e7aa80)
#20 0x0000000003a622c4 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/clang-19+0x3a622c4)
#21 0x0000000003a84404 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/clang-19+0x3a84404)
#22 0x0000000004c75190 clang::ParseAST(clang::Sema&, bool, bool) (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/clang-19+0x4c75190)
#23 0x0000000003e3b810 clang::FrontendAction::Execute() (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/clang-19+0x3e3b810)
#24 0x0000000003dc1974 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/clang-19+0x3dc1974)
#25 0x0000000003f07098 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/clang-19+0x3f07098)
#26 0x0000000002081dec cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/clang-19+0x2081dec)
#27 0x000000000207ec98 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#28 0x0000000003c673e0 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::$_0>(long) Job.cpp:0:0
#29 0x000000000329904c llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/clang-19+0x329904c)
#30 0x0000000003c669c0 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/clang-19+0x3c669c0)
#31 0x0000000003c2e478 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/clang-19+0x3c2e478)
#32 0x0000000003c2e6c4 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/clang-19+0x3c2e6c4)
#33 0x0000000003c47710 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/clang-19+0x3c47710)
#34 0x000000000207e06c clang_main(int, char**, llvm::ToolContext const&) (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/clang-19+0x207e06c)
#35 0x000000000208c138 main (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/clang-19+0x208c138)
#36 0x0000ffffb1fd0a1c __libc_start_call_main (/lib64/libc.so.6+0x30a1c)
#37 0x0000ffffb1fd0afc __libc_start_main at GLIBC_2.17 (/lib64/libc.so.6+0x30afc)
#38 0x000000000207c8b0 _start (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/clang-19+0x207c8b0)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
ClangBuiltLinux clang version 19.0.0git (https://github.com/llvm/llvm-project.git 355e4a9e56c644f24fc10f780cb2fc68b660d0a0)
Target: hexagon-unknown-linux
Thread model: posix
InstalledDir: /home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin
Build config: +assertions
clang: note: diagnostic msg: Error generating preprocessed source(s) - no preprocessable inputs.

```

```llvm
target datalayout = "e-m:e-p:32:32:32-a:0-n16:32-i64:64:64-i32:32:32-i16:16:16-i1:8:8-f32:32:32-f64:64:64-v32:32:32-v64:64:64-v512:512:512-v1024:1024:1024-v2048:2048:2048"
target triple = "hexagon-unknown-linux"

define void @poll_for_response(i32 %0, ptr %1) {
  br label %4

3:                                                ; preds = %4
  ret void

4:                                                ; preds = %4, %2
  %5 = phi i32 [ 0, %4 ], [ %0, %2 ]
  %6 = phi i32 [ 1, %4 ], [ 0, %2 ]
  %7 = phi i32 [ %11, %4 ], [ 0, %2 ]
  %8 = lshr i32 %5, 1
  %9 = trunc i32 %8 to i8
  store i8 %9, ptr %1, align 1
  %10 = getelementptr i8, ptr %1, i32 %6
  store i8 0, ptr %10, align 1
  %11 = add i32 %7, 1
  %12 = icmp eq i32 %7, 1
  br i1 %12, label %3, label %4
}
```

```
$ llc -o /dev/null reduced.ll
llc: /home/nathan/tmp/cvise.YaBcQe05cQ/src/llvm/lib/CodeGen/WindowScheduler.cpp:650: int llvm::WindowScheduler::getOriCycle(MachineInstr *): Assertion `TriToOri.count(NewMI) && "Cannot find original MI!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: llc -o /dev/null reduced.ll
1.      Running pass 'Function Pass Manager' on module 'reduced.ll'.
2.      Running pass 'Modulo Software Pipelining' on function '@poll_for_response'
 #0 0x00000000031fa6f8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/llc+0x31fa6f8)
 #1 0x00000000031f85a0 llvm::sys::RunSignalHandlers() (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/llc+0x31f85a0)
 #2 0x00000000031fae14 SignalHandler(int) Signals.cpp:0:0
 #3 0x0000ffff9199b7f0 (linux-vdso.so.1+0x7f0)
 #4 0x0000ffff913585e0 __pthread_kill_implementation (/lib64/libc.so.6+0x985e0)
 #5 0x0000ffff91305a00 gsignal (/lib64/libc.so.6+0x45a00)
 #6 0x0000ffff912f0288 abort (/lib64/libc.so.6+0x30288)
 #7 0x0000ffff912fe3e0 __assert_fail_base (/lib64/libc.so.6+0x3e3e0)
 #8 0x0000ffff912fe454 (/lib64/libc.so.6+0x3e454)
 #9 0x00000000026d81b4 llvm::WindowScheduler::getOriCycle(llvm::MachineInstr*) (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/llc+0x26d81b4)
#10 0x00000000026d8ea8 llvm::WindowScheduler::schedulePhi(int, unsigned int&) (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/llc+0x26d8ea8)
#11 0x00000000026d50a4 llvm::WindowScheduler::run() (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/llc+0x26d50a4)
#12 0x00000000023edbf8 llvm::MachinePipeliner::runWindowScheduler(llvm::MachineLoop&) (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/llc+0x23edbf8)
#13 0x00000000023ec1e8 llvm::MachinePipeliner::scheduleLoop(llvm::MachineLoop&) (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/llc+0x23ec1e8)
#14 0x00000000023ec02c llvm::MachinePipeliner::runOnMachineFunction(llvm::MachineFunction&) (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/llc+0x23ec02c)
#15 0x0000000002380258 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/llc+0x2380258)
#16 0x00000000028ba804 llvm::FPPassManager::runOnFunction(llvm::Function&) (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/llc+0x28ba804)
#17 0x00000000028c2348 llvm::FPPassManager::runOnModule(llvm::Module&) (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/llc+0x28c2348)
#18 0x00000000028bb1b4 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/llc+0x28bb1b4)
#19 0x00000000019a1da8 main (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/llc+0x19a1da8)
#20 0x0000ffff912f0a1c __libc_start_call_main (/lib64/libc.so.6+0x30a1c)
#21 0x0000ffff912f0afc __libc_start_main at GLIBC_2.17 (/lib64/libc.so.6+0x30afc)
#22 0x000000000199c4f0 _start (/home/nathan/tmp/cvise.YaBcQe05cQ/install/llvm-bad/bin/llc+0x199c4f0)
```

https://github.com/llvm/llvm-project/pull/84443


More information about the llvm-commits mailing list