Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

m68k fails to select atomic store where address is sum of two registers #107939

Closed
programmerjake opened this issue Sep 9, 2024 · 3 comments · Fixed by #108982
Closed

m68k fails to select atomic store where address is sum of two registers #107939

programmerjake opened this issue Sep 9, 2024 · 3 comments · Fixed by #108982

Comments

@programmerjake
Copy link
Contributor

encountered when trying to build Rust's standard library for m68k:
https://rust-lang.zulipchat.com/#narrow/stream/187780-t-compiler.2Fwg-llvm/topic/M86k.20Compilation.20Failures/near/468939538

reduced:
https://llvm.godbolt.org/z/qP4nsoq58

define void @f(i8 %v, ptr %p, i32 %o) {
start:
    %p2 = getelementptr i8, ptr %p, i32 %o
    store atomic i8 %v, ptr %p2 monotonic, align 1
    ret void
}
warning: overriding the module target triple with m68k-unknown-linux-gnu [-Woverride-module]
fatal error: error in backend: Cannot select: 0xb912ff0: ch = AtomicStore<(store monotonic (s8) into %ir.p2)> 0xb8cf930, 0xb912ab0, 0xb912f80
  0xb912ab0: i8,ch = load<(load (s8) from %fixed-stack.2)> 0xb8cf930, FrameIndex:i32<-1>, undef:i32
    0xb9129d0: i32 = FrameIndex<-1>
    0xb912a40: i32 = undef
  0xb912f80: i32 = add 0xb912b90, 0xb912c70
    0xb912b90: i32,ch = load<(load (s32) from %fixed-stack.1)> 0xb8cf930, FrameIndex:i32<-2>, undef:i32
      0xb912b20: i32 = FrameIndex<-2>
      0xb912a40: i32 = undef
    0xb912c70: i32,ch = load<(load (s32) from %fixed-stack.0, align 8)> 0xb8cf930, FrameIndex:i32<-3>, undef:i32
      0xb912c00: i32 = FrameIndex<-3>
      0xb912a40: i32 = undef
In function: f
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: /opt/compiler-explorer/clang-18.1.0/bin/clang++ -g -o /app/output.s -fno-verbose-asm -S -x ir -fcolor-diagnostics -fno-crash-diagnostics --target=m68k-unknown-linux-gnu <source>
1.	Code generation
2.	Running pass 'Function Pass Manager' on module '<source>'.
3.	Running pass 'M68k DAG->DAG Pattern Instruction Selection' on function '@f'
 #0 0x000000000351ae38 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x351ae38)
 #1 0x0000000003518f84 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3518f84)
 #2 0x0000000003467543 llvm::CrashRecoveryContext::HandleExit(int) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3467543)
 #3 0x000000000351097e llvm::sys::Process::Exit(int, bool) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x351097e)
 #4 0x0000000000c17976 (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0xc17976)
 #5 0x0000000003470593 llvm::report_fatal_error(llvm::Twine const&, bool) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3470593)
 #6 0x00000000045d3174 llvm::SelectionDAGISel::CannotYetSelect(llvm::SDNode*) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x45d3174)
 #7 0x00000000045d9135 llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*, unsigned int) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x45d9135)
 #8 0x00000000024cc97b (anonymous namespace)::M68kDAGToDAGISel::Select(llvm::SDNode*) M68kISelDAGToDAG.cpp:0:0
 #9 0x00000000045d06f7 llvm::SelectionDAGISel::DoInstructionSelection() (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x45d06f7)
#10 0x00000000045dda15 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x45dda15)
#11 0x00000000045e06df llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x45e06df)
#12 0x00000000045e2dc9 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (.part.0) SelectionDAGISel.cpp:0:0
#13 0x00000000029bc2f0 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#14 0x0000000002ee69e2 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x2ee69e2)
#15 0x0000000002ee6b61 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x2ee6b61)
#16 0x0000000002ee87e0 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x2ee87e0)
#17 0x000000000378ad99 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*) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x378ad99)
#18 0x0000000003d5a8bf clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3d5a8bf)
#19 0x0000000003fe2aa1 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3fe2aa1)
#20 0x0000000003f6010b clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3f6010b)
#21 0x00000000040c2473 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x40c2473)
#22 0x0000000000c19746 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0xc19746)
#23 0x0000000000c1211d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#24 0x0000000003da1979 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::'lambda'()>(long) Job.cpp:0:0
#25 0x0000000003467443 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3467443)
#26 0x0000000003da1b99 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#27 0x0000000003d69d17 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3d69d17)
#28 0x0000000003d6a6cd clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3d6a6cd)
#29 0x0000000003d7445c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3d7445c)
#30 0x0000000000c16a21 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0xc16a21)
#31 0x0000000000b0fa84 main (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0xb0fa84)
#32 0x000070bdd3029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#33 0x000070bdd3029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#34 0x0000000000c1191e _start (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0xc1191e)
clang++: error: clang frontend command failed with exit code 70 (use -v to see invocation)
Compiler returned: 70
@llvmbot
Copy link
Collaborator

llvmbot commented Sep 9, 2024

@llvm/issue-subscribers-backend-m68k

Author: Jacob Lifshay (programmerjake)

encountered when trying to build Rust's standard library for m68k: https://rust-lang.zulipchat.com/#narrow/stream/187780-t-compiler.2Fwg-llvm/topic/M86k.20Compilation.20Failures/near/468939538

reduced:
https://llvm.godbolt.org/z/qP4nsoq58

define void @<!-- -->f(i8 %v, ptr %p, i32 %o) {
start:
    %p2 = getelementptr i8, ptr %p, i32 %o
    store atomic i8 %v, ptr %p2 monotonic, align 1
    ret void
}
warning: overriding the module target triple with m68k-unknown-linux-gnu [-Woverride-module]
fatal error: error in backend: Cannot select: 0xb912ff0: ch = AtomicStore&lt;(store monotonic (s8) into %ir.p2)&gt; 0xb8cf930, 0xb912ab0, 0xb912f80
  0xb912ab0: i8,ch = load&lt;(load (s8) from %fixed-stack.2)&gt; 0xb8cf930, FrameIndex:i32&lt;-1&gt;, undef:i32
    0xb9129d0: i32 = FrameIndex&lt;-1&gt;
    0xb912a40: i32 = undef
  0xb912f80: i32 = add 0xb912b90, 0xb912c70
    0xb912b90: i32,ch = load&lt;(load (s32) from %fixed-stack.1)&gt; 0xb8cf930, FrameIndex:i32&lt;-2&gt;, undef:i32
      0xb912b20: i32 = FrameIndex&lt;-2&gt;
      0xb912a40: i32 = undef
    0xb912c70: i32,ch = load&lt;(load (s32) from %fixed-stack.0, align 8)&gt; 0xb8cf930, FrameIndex:i32&lt;-3&gt;, undef:i32
      0xb912c00: i32 = FrameIndex&lt;-3&gt;
      0xb912a40: i32 = undef
In function: f
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: /opt/compiler-explorer/clang-18.1.0/bin/clang++ -g -o /app/output.s -fno-verbose-asm -S -x ir -fcolor-diagnostics -fno-crash-diagnostics --target=m68k-unknown-linux-gnu &lt;source&gt;
1.	Code generation
2.	Running pass 'Function Pass Manager' on module '&lt;source&gt;'.
3.	Running pass 'M68k DAG-&gt;DAG Pattern Instruction Selection' on function '@<!-- -->f'
 #<!-- -->0 0x000000000351ae38 llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x351ae38)
 #<!-- -->1 0x0000000003518f84 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3518f84)
 #<!-- -->2 0x0000000003467543 llvm::CrashRecoveryContext::HandleExit(int) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3467543)
 #<!-- -->3 0x000000000351097e llvm::sys::Process::Exit(int, bool) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x351097e)
 #<!-- -->4 0x0000000000c17976 (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0xc17976)
 #<!-- -->5 0x0000000003470593 llvm::report_fatal_error(llvm::Twine const&amp;, bool) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3470593)
 #<!-- -->6 0x00000000045d3174 llvm::SelectionDAGISel::CannotYetSelect(llvm::SDNode*) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x45d3174)
 #<!-- -->7 0x00000000045d9135 llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*, unsigned int) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x45d9135)
 #<!-- -->8 0x00000000024cc97b (anonymous namespace)::M68kDAGToDAGISel::Select(llvm::SDNode*) M68kISelDAGToDAG.cpp:0:0
 #<!-- -->9 0x00000000045d06f7 llvm::SelectionDAGISel::DoInstructionSelection() (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x45d06f7)
#<!-- -->10 0x00000000045dda15 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x45dda15)
#<!-- -->11 0x00000000045e06df llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&amp;) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x45e06df)
#<!-- -->12 0x00000000045e2dc9 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&amp;) (.part.0) SelectionDAGISel.cpp:0:0
#<!-- -->13 0x00000000029bc2f0 llvm::MachineFunctionPass::runOnFunction(llvm::Function&amp;) (.part.0) MachineFunctionPass.cpp:0:0
#<!-- -->14 0x0000000002ee69e2 llvm::FPPassManager::runOnFunction(llvm::Function&amp;) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x2ee69e2)
#<!-- -->15 0x0000000002ee6b61 llvm::FPPassManager::runOnModule(llvm::Module&amp;) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x2ee6b61)
#<!-- -->16 0x0000000002ee87e0 llvm::legacy::PassManagerImpl::run(llvm::Module&amp;) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x2ee87e0)
#<!-- -->17 0x000000000378ad99 clang::EmitBackendOutput(clang::DiagnosticsEngine&amp;, clang::HeaderSearchOptions const&amp;, clang::CodeGenOptions const&amp;, clang::TargetOptions const&amp;, clang::LangOptions const&amp;, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr&lt;llvm::vfs::FileSystem&gt;, std::unique_ptr&lt;llvm::raw_pwrite_stream, std::default_delete&lt;llvm::raw_pwrite_stream&gt;&gt;, clang::BackendConsumer*) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x378ad99)
#<!-- -->18 0x0000000003d5a8bf clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3d5a8bf)
#<!-- -->19 0x0000000003fe2aa1 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3fe2aa1)
#<!-- -->20 0x0000000003f6010b clang::CompilerInstance::ExecuteAction(clang::FrontendAction&amp;) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3f6010b)
#<!-- -->21 0x00000000040c2473 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x40c2473)
#<!-- -->22 0x0000000000c19746 cc1_main(llvm::ArrayRef&lt;char const*&gt;, char const*, void*) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0xc19746)
#<!-- -->23 0x0000000000c1211d ExecuteCC1Tool(llvm::SmallVectorImpl&lt;char const*&gt;&amp;, llvm::ToolContext const&amp;) driver.cpp:0:0
#<!-- -->24 0x0000000003da1979 void llvm::function_ref&lt;void ()&gt;::callback_fn&lt;clang::driver::CC1Command::Execute(llvm::ArrayRef&lt;std::optional&lt;llvm::StringRef&gt;&gt;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt;*, bool*) const::'lambda'()&gt;(long) Job.cpp:0:0
#<!-- -->25 0x0000000003467443 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref&lt;void ()&gt;) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3467443)
#<!-- -->26 0x0000000003da1b99 clang::driver::CC1Command::Execute(llvm::ArrayRef&lt;std::optional&lt;llvm::StringRef&gt;&gt;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt;*, bool*) const (.part.0) Job.cpp:0:0
#<!-- -->27 0x0000000003d69d17 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&amp;, clang::driver::Command const*&amp;, bool) const (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3d69d17)
#<!-- -->28 0x0000000003d6a6cd clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&amp;, llvm::SmallVectorImpl&lt;std::pair&lt;int, clang::driver::Command const*&gt;&gt;&amp;, bool) const (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3d6a6cd)
#<!-- -->29 0x0000000003d7445c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&amp;, llvm::SmallVectorImpl&lt;std::pair&lt;int, clang::driver::Command const*&gt;&gt;&amp;) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0x3d7445c)
#<!-- -->30 0x0000000000c16a21 clang_main(int, char**, llvm::ToolContext const&amp;) (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0xc16a21)
#<!-- -->31 0x0000000000b0fa84 main (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0xb0fa84)
#<!-- -->32 0x000070bdd3029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#<!-- -->33 0x000070bdd3029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#<!-- -->34 0x0000000000c1191e _start (/opt/compiler-explorer/clang-18.1.0/bin/clang+++0xc1191e)
clang++: error: clang frontend command failed with exit code 70 (use -v to see invocation)
Compiler returned: 70

@deltro68
Copy link

#108982 doesn't appear to address this use case:

define void @f2(i8 %v, ptr %p) {
start:
    %p2 = getelementptr i8, ptr %p, i32 4
    store atomic i8 %v, ptr %p2 monotonic, align 1
    ret void
}

@knickish
Copy link
Contributor

@deltro68 I was trying to keep it simple for my first PR to llvm until I know the process. I can add ARID addressing mode support (which should fix the other case you've shown here) in a followup if desirable

EricWF pushed a commit to efcs/llvm-project that referenced this issue Oct 22, 2024
Only ARI was supported, this PR adds ARII support for atomic
loads/stores (also with zero displacement). Closes llvm#107939
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants