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

    <tr>
        <th>Summary</th>
        <td>
            [M68k] RTD must be implemented for 68020 baseline and higher
        </td>
    </tr>

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

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

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

<pre>
    As initially reported in https://github.com/llvm/llvm-project/issues/59161#issuecomment-1418260415, the M68k backend needs to have the RTD instruction implemented in order to use a baseline of 68020 or higher.

The reason for this is that the code in `llvm/lib/Target/M68k/M68kExpandPseudo.cpp`M68kExpandPseudo::ExpandMI()` wants to emit the RTD instead of RTS instruction when the baseline is set to 68020 or higher but RTD is not implemented:

```
glaubitz@node54:/data/home/glaubitz> /data/home/glaubitz/llvm-project/stage1.install/bin/clang -mcpu=68020 -target m68k-linux-gnu future.cc -o future -I /data/home/glaubitz/sid-m68k-sbuild/usr/m68k-linux-gnu/include/c++/12/m68k-linux-gnu/ -I /data/home/glaubitz/sid-m68k-sbuild/usr/m68k-linux-gnu/include/ -I /data/home/glaubitz/sid-m68k-sbuild/usr/include/c++/12/ -I /data/home/glaubitz/sid-m68k-sbuild/usr/include/m68k-linux-gnu/c++/12/ -L /data/home/glaubitz/sid-m68k-sbuild/usr/lib/m68k-linux-gnu/ -L /data/home/glaubitz/sid-m68k-sbuild/usr/lib/gcc/m68k-linux-gnu/12/ -L /data/home/glaubitz/sid-m68k-sbuild/usr/lib/gcc/m68k-linux-gnu/12/ -fuse-ld=/usr/bin/m68k-suse-linux-ld
RTD is not implemented
UNREACHABLE executed at /data/home/glaubitz/llvm-project/llvm/lib/Target/M68k/M68kExpandPseudo.cpp:255!
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: /data/home/glaubitz/llvm-project/stage1.install/bin/clang-17 -cc1 -triple m68k-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -clear-ast-before-backend -main-file-name future.cc -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -target-cpu M68020 -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -fcoverage-compilation-dir=/data/home/glaubitz -resource-dir /data/home/glaubitz/llvm-project/stage1.install/lib/clang/17 -I /data/home/glaubitz/sid-m68k-sbuild/usr/m68k-linux-gnu/include/c++/12/m68k-linux-gnu/ -I /data/home/glaubitz/sid-m68k-sbuild/usr/m68k-linux-gnu/include/ -I /data/home/glaubitz/sid-m68k-sbuild/usr/include/c++/12/ -I /data/home/glaubitz/sid-m68k-sbuild/usr/include/m68k-linux-gnu/c++/12/ -internal-isystem /data/home/glaubitz/llvm-project/stage1.install/lib/clang/17/include -internal-isystem /usr/local/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-dir=/data/home/glaubitz -ferror-limit 19 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/future-3f8909.o -x c++ future.cc
1.      <eof> parser at end of file
2.      Code generation
3.      Running pass 'Function Pass Manager' on module 'future.cc'.
4.      Running pass 'M68k pseudo instruction expansion pass' on function '@"_ZSt5asyncIZ4mainE3$_0JEESt6futureINSt15__invoke_resultINSt5decayIT_E4typeEJDpNS3_IT0_E4typeEEE4typeEESt6launchOS4_DpOS7_"'
 #0 0x0000000002003f67 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/home/glaubitz/llvm-project/stage1.install/bin/clang-17+0x2003f67)
 #1 0x0000000002001a1c SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f95f03a88c0 __restore_rt (/lib64/libpthread.so.0+0x168c0)
 #3 0x00007f95eead8cbb raise (/lib64/libc.so.6+0x4acbb)
 #4 0x00007f95eeada355 abort (/lib64/libc.so.6+0x4c355)
 #5 0x0000000001f6ad7a (/data/home/glaubitz/llvm-project/stage1.install/bin/clang-17+0x1f6ad7a)
 #6 0x0000000000f537bd (anonymous namespace)::M68kExpandPseudo::ExpandMI(llvm::MachineBasicBlock&, llvm::MachineInstrBundleIterator<llvm::MachineInstr, false>) M68kExpandPseudo.cpp:0:0
 #7 0x0000000000f53ab2 (anonymous namespace)::M68kExpandPseudo::runOnMachineFunction(llvm::MachineFunction&) M68kExpandPseudo.cpp:0:0
 #8 0x00000000013633e2 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.71) MachineFunctionPass.cpp:0:0
 #9 0x0000000001900658 llvm::FPPassManager::runOnFunction(llvm::Function&) (/data/home/glaubitz/llvm-project/stage1.install/bin/clang-17+0x1900658)
#10 0x0000000001900979 llvm::FPPassManager::runOnModule(llvm::Module&) (/data/home/glaubitz/llvm-project/stage1.install/bin/clang-17+0x1900979)
#11 0x00000000019017d8 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/data/home/glaubitz/llvm-project/stage1.install/bin/clang-17+0x19017d8)
#12 0x00000000023853a8 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>>) (/data/home/glaubitz/llvm-project/stage1.install/bin/clang-17+0x23853a8)
#13 0x00000000030de451 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/data/home/glaubitz/llvm-project/stage1.install/bin/clang-17+0x30de451)
#14 0x0000000003dec2d9 clang::ParseAST(clang::Sema&, bool, bool) (/data/home/glaubitz/llvm-project/stage1.install/bin/clang-17+0x3dec2d9)
#15 0x00000000030dd0a0 clang::CodeGenAction::ExecuteAction() (/data/home/glaubitz/llvm-project/stage1.install/bin/clang-17+0x30dd0a0)
#16 0x0000000002a847e9 clang::FrontendAction::Execute() (/data/home/glaubitz/llvm-project/stage1.install/bin/clang-17+0x2a847e9)
#17 0x0000000002a1cc3a clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/data/home/glaubitz/llvm-project/stage1.install/bin/clang-17+0x2a1cc3a)
#18 0x0000000002b544cb clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/data/home/glaubitz/llvm-project/stage1.install/bin/clang-17+0x2b544cb)
#19 0x0000000000bb8ec1 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/data/home/glaubitz/llvm-project/stage1.install/bin/clang-17+0xbb8ec1)
#20 0x0000000000bb4398 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#21 0x0000000000bb688c clang_main(int, char**) (/data/home/glaubitz/llvm-project/stage1.install/bin/clang-17+0xbb688c)
#22 0x00007f95eeac329d __libc_start_main (/lib64/libc.so.6+0x3529d)
#23 0x0000000000bae7ba _start /home/abuild/rpmbuild/BUILD/glibc-2.31/csu/../sysdeps/x86_64/start.S:122:0
clang-17: error: unable to execute command: Aborted (core dumped)
clang-17: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 17.0.0 (https://github.com/llvm/llvm-project.git b72330cd54f985f3454d3538b504027c3eff8711)
Target: m68k-unknown-linux-gnu
Thread model: posix
InstalledDir: /data/home/glaubitz/llvm-project/stage1.install/bin
clang-17: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-17: note: diagnostic msg: /tmp/future-76c283.cpp
clang-17: note: diagnostic msg: /tmp/future-76c283.sh
clang-17: note: diagnostic msg: 

********************
glaubitz@node54:/data/home/glaubitz>
```

The 68020 baseline is required in order to be able to use the newly implemented support for atomics and also the upcoming TLS Support (https://github.com/llvm/llvm-project/issues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