<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/61166>61166</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [MIPS] Incorrect atomic handling for mips1
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          vit9696
      </td>
    </tr>
</table>

<pre>
    Compiling the following example with `clang --target=mips-gnu-linux -march=mips1 -c t.c -o t.o` results in a crash. Changing `__ATOMIC_RELEASE` to `__ATOMIC_RELAXED` makes the code compile.

Since all MIPS I processors are single-core, `__ATOMIC_RELAXED` and `__ATOMIC_RELEASE` should be equivalent apart from a compiler barrier. GCC compiles this code without issues.

```c
_Atomic int a;
void square(void) {
 __c11_atomic_store(&a, 1, __ATOMIC_RELEASE);
}
```

```
warning: MIPS-I support is experimental
fatal error: error in backend: Cannot select: 0x55e91cdb9360: ch = MipsISD::Sync 0x55e91cdb9050:1, Constant:i32<0>, example.c:4:5
 0x55e91cdb8f00: i32 = Constant<0>
In function: square
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-trunk/bin/clang -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-9.2.0 -fcolor-diagnostics -fno-crash-diagnostics --target=mips-gnu-linux -march=mips1 <source>
1.      <eof> parser at end of file
2.      Code generation
3.      Running pass 'Function Pass Manager' on module '<source>'.
4.      Running pass 'MIPS DAG->DAG Pattern Instruction Selection' on function '@square'
 #0 0x000055e91345208f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3b2008f)
 #1 0x000055e9134500bc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3b1e0bc)
 #2 0x000055e9133a3177 llvm::CrashRecoveryContext::HandleExit(int) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3a71177)
 #3 0x000055e913447d22 llvm::sys::Process::Exit(int, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3b15d22)
 #4 0x000055e910ccd8af (/opt/compiler-explorer/clang-trunk/bin/clang+0x139b8af)
 #5 0x000055e9133abffa llvm::report_fatal_error(llvm::Twine const&, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3a79ffa)
 #6 0x000055e91459b6a0 llvm::SelectionDAGISel::CannotYetSelect(llvm::SDNode*) (/opt/compiler-explorer/clang-trunk/bin/clang+0x4c696a0)
 #7 0x000055e9145a09e2 llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*, unsigned int) (/opt/compiler-explorer/clang-trunk/bin/clang+0x4c6e9e2)
 #8 0x000055e914599757 llvm::SelectionDAGISel::DoInstructionSelection() (/opt/compiler-explorer/clang-trunk/bin/clang+0x4c67757)
 #9 0x000055e9145a5199 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/opt/compiler-explorer/clang-trunk/bin/clang+0x4c73199)
#10 0x000055e9145a7f1e llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x4c75f1e)
#11 0x000055e9145aa60f llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (.part.0) SelectionDAGISel.cpp:0:0
#12 0x000055e9119f08af llvm::MipsDAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x20be8af)
#13 0x000055e91282c100 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#14 0x000055e912d43e90 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3411e90)
#15 0x000055e912d44009 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3412009)
#16 0x000055e912d44bf0 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3412bf0)
#17 0x000055e9137f65f2 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>>) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3ec45f2)
#18 0x000055e9146e9e19 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x4db7e19)
#19 0x000055e91592b009 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+0x5ff9009)
#20 0x000055e9146e93d5 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk/bin/clang+0x4db73d5)
#21 0x000055e913fd9281 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk/bin/clang+0x46a7281)
#22 0x000055e913f5b423 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x4629423)
#23 0x000055e9140b93cb clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk/bin/clang+0x47873cb)
#24 0x000055e910ccecdc cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-trunk/bin/clang+0x139ccdc)
#25 0x000055e910cca2df ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#26 0x000055e913db8b1d 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
#27 0x000055e9133a3067 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3a71067)
#28 0x000055e913db8d5c 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
#29 0x000055e913d80cec clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+0x444ecec)
#30 0x000055e913d816dd clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+0x444f6dd)
#31 0x000055e913d8bb2c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x4459b2c)
#32 0x000055e910cccdb2 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x139adb2)
#33 0x000055e910bce8f5 main (/opt/compiler-explorer/clang-trunk/bin/clang+0x129c8f5)
#34 0x00007f420ad77083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#35 0x000055e910cc641e _start (/opt/compiler-explorer/clang-trunk/bin/clang+0x139441e)
clang: error: clang frontend command failed with exit code 70 (use -v to see invocation)
Compiler returned: 70
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWttz46ie_muUF0ouhO4PeXDbSU-mJtupdnZr98mFANlsS6ABlDj__SmQHAvF6fRMPOflVM2kLa4fHx-_CxLWmu8EY9dB-iVI11e4N3uprp-4KbMyu6okfbleybb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