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

    <tr>
        <th>Summary</th>
        <td>
            Clang MIPS: float register constraints for inline asm deviate from gcc
        </td>
    </tr>

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

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

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

<pre>
    clang and gcc seem to have different behavior of floating point constraints for inline asm. Consider this simple example

```c
// gcc compiles this but clang does not
void read_float(float* p) {
    float result = *p;
    __asm__("" ::"r"(result));
}
```
The following code compiles fine on gcc when targeting MIPS, but clang gives a compile error `couldn't allocate input reg for constraint 'r'`

Clang requires the register constraint here to be `"f"` not `"r"`. However applying an `"f"` constraint, causes gcc to fail compilation with the error `error: impossible constraint in 'asm'` while clang compiles the code fine. 

```c
// clang compiles this but gcc does not
void read_float(float* p) {
    float result = *p;
 __asm__("" ::"f"(result));
}
```

Here is a simple demo of the issue: https://godbolt.org/z/WGWxd3ejo
Test with "mips gcc 13.1.0" and "mips clang 16.0.0"

(This bug was discovered as part of the wasm2c project https://github.com/WebAssembly/wabt/issues/2266)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VF-P3CYQ_zTsyyiWPfauvQ9-2Nxpmz5UqtRIeTxhM7aJMLiA17l--grw3W0ualVVioRgFzPM_P4w3Dk5aqKWHT-y4-OBr34ytnWT5TeurT50Rjy3veJ6BK4FjH0PjmgGb2DiNwIhh4EsaQ8dTfwmjQUzwKAM91KPsBipPfRGO2-51N7BYCxIraQm4G7O4MFoJwVZ8JN04OS8KAL6xsPK8keWX_b5lKfR7__xyvAaC-rNvEhFLl3RrR5SwcKQA218CrgZKcASF0-xOobNvl5gYXgGVn9MBwEgAQBLblUeWPkIDC8LK-9OPD1xNz89MWwYIkMEVl7CQLRxo0nBDM9hv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