<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/145411>145411</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang] mips4 instructions generated when compiling for mips2
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Sirius902
</td>
</tr>
</table>
<pre>
## The Problem
When using the `__atomic_fetch_min` and `__atomic_fetch_max` compiler builtins it is possible to generate instructions introduced in mips4 despite compiling for mips2. Following the code below compiling with `-mips2`, using `__atomic_fetch_min` generates a `movz` instruction while `__atomic_fetch_max` generates a `movn` instruction.
Here is C code that demonstrates this problem along with a [Godbolt link](https://godbolt.org/z/a7qd4dns1) demonstrating this miscompilation.
```c
int min(int* x, int y) {
return __atomic_fetch_min(x, y, __ATOMIC_SEQ_CST);
}
int max(int* x, int y) {
return __atomic_fetch_max(x, y, __ATOMIC_SEQ_CST);
}
```
## Expected Behavior
I would expect that instructions like `movz` and `movn` would not be emitted when compiling for `-mips2` since these instructions were introduced in MIPS IV, they are not present in the MIPS II standard.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyMVE1v4zYQ_TXUZRCDoizZOujgJOvWh0W3SNAeDYocW9OlSJWk4mR_fUHJbp3UQQsYFqD5eG-e5o0MgY4WsWHlPSsfMznGzvnmiTyNoeYia51-a5gomCjguUP45l1rsGd8w_jm9w4tjIHsEWKHwCq-38voelL7A0bV7XuyrOIgrb4VlK8pqFw_kEEP7Ugmkg1AESjA4EKg1iBEB0e06GVEIBuiH1Ukl_Js9E6PCjWQhZ6GsASNYaCI566J2cH5KSYWsHXGuNOFrnIaoUXjTlfZJ4pd4no3lbCKM_FwHvHT8S7sAsiU1LuXH-n1FVc4dWRuCjRr8O8O9kOHxaz4z-gxifMws4-djKCxdylxqo9dkm7-SCCNu4wkgZX3PzndOhPBkP3Oykcm1l2MQ2DFhoktE9vjHF84f2Ri-4OJrVz9qZfahpyJ-gpolpAC9BRm7eTfJCs-_xTjG7IRkkhiTTYysYHXJGd6-5YastU94xsAAI9x9BZu6CvWU81b-tvvN8-_fN097J--_Lp_eHpmomZFasFWj7M-E6B8_Q_AT9Cmuv-Pdhl0Rj575MvrgCqihnvs5As5P0d3cHKj0YBTeP5u73bZ0He8Xp6zZS6bMFdbF6FFwJ5igjgl-71f9OvNhUBWpR3B8ME4p2mL3rnn6-7bE-x-S3PHDt9AepzgBo8BbSI7eWZO20GI0mrp9SLTTaHropYZNvmq5Ku8KOo86xqlW72sq3pdrlcSq7rkSh_EAauDOOQVx4wawUXJK1GIPK-KfKHymvM8X2JVS3XIK7bk2EsyC2Ne-rSTGYUwYpMvy2WeZ0a2aMJ0uIRQRtojEyLdMN-kgrt2PAa25IZCDP-0iBTNdO3mivLxfDfe6XOx402JJ3mz0Zvmg3kodmO7UK5nYpvwzo-7wbs_UEUmthP_wMT2PMJLI_4KAAD__39zzuQ">