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

    <tr>
        <th>Summary</th>
        <td>
            'mov <rd>, <imm>' produces an error where imm is 0-255 and -march=armv8m.base is used
        </td>
    </tr>

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

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

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

<pre>
    Assembly such as `mov r0, #0` fails to build with clang but is accepted by GCC under `-march=armv8m.base`. I'm not entirely sure if my understanding is correct, but it seems like this is might be a bug in LLVM.

Small example (https://godbolt.org/z/3Y1jqWjvs):
```
void foo(void) {
    // Fails to build with clang, accepted by GCC
    __asm__ volatile("\n\
 .syntax unified\n\
                      mov r0, #0");

    // Clang and GCC are both happy with this
    __asm__ volatile("\n\
                      .syntax unified\n\
 mov r0, #256");
}
```

When building for Arm with `-march=armv8m.base`, Clang errors on the top `__asm__` statement as below (output is abbreviated):
```
<source>:6:1: error: invalid instruction, any one of the following would fix this:
    6 |                       mov r0, #0");
      | ^
<inline asm>:3:23: note: instantiated into assembly here
    3 |                       mov r0, #0
      | 
...
```

Looking at section C2.4.119 in the Armv8-M arch manual, my understanding is that:
- T1 isn't feasible because we 1) aren't in an IT block and 2) used `mov` in the inline asm (rather than `movs`) so we'd look for a flag-preserving variant instead.
- T2 isn't feasible because we're looking at Armv8-M baseline (not mainline).
- T3 should be feasible (and, this is what GCC seems to do, IIUC).

I'm again not entirely sure if I'm misunderstanding something above, but it seems like we should be "selecting" T3 here rather than erroring, similar to GCC.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVk9v27gT_TT0ZRBBoizLOvjgKnURoD39-ttiTwEpjS0m_OMlKTneT78YyqnTwA12jUCxweHwzZs3jxIhqINF3LDqE6vuF2KMg_ObJ2dFHJw9olUvC-n682Yb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