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

    <tr>
        <th>Summary</th>
        <td>
            ppc64el miscompilation on signed integer argument passing
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          tpearson-ssc
      </td>
    </tr>
</table>

<pre>
    On all Clang versions after Clang 16, llc miscompiles a simple C++ test program testing integer argument passing:

```
#include <stdio.h>
#include <math.h>

int main() {
        volatile double result;

        volatile int exp = -53;
        volatile double base = 3635833917682146;

 result = ldexp(base, exp);
        printf("Result: %f\n", result);

        return 0;
}
```

The program should output `0.403659`, but on Clang 17 and newer outputs `inf`.

On calling ldexp, `r4` is used to pass `exp`.  Unfortunately, only the lower 32 bits of `exp` are passed in `r4`, leading to an incorrect result.  This is due to incorrect backend code generation:

```
  8bc:  60 00 3f c8     lfd f1,96(r31)
- 8c0:  6e 00 9f e8     lwa     r4,108(r31)             <-- CORRECT (sign extends values for signed 64-bit integer parameter passing in r4)
+ 8c0:  6c 00 9f 80     lwz     r4,108(r31)             <-- WRONG (zeroes upper 32 bits of parameter in r4)
  8c4:  9d fd ff 4b     bl      660 <0000001b.plt_call.ldexp@@GLIBC_2.17>
  8c8:  18 00 41 e8     ld r2,24(r1)
  8cc:  70 00 3f d8     stfd    f1,112(r31)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyEVU1v4zYQ_TX0ZWCBImV9HHRYK5tFgaIBgi16XFDkyGZLkQJJZZP99QVpxU72ozUEyRLnzTzOmxmKEPTJIvbkcCSHu51Y49n5Pi4ofHB2H4LcjU699A8WhDEwGGFP8IQ-aGcDiCmi3z6WNWEDGCNh1kG6edEGAwgIel4MwkDYkbAjRAwRFu9OXsz5RdsTaBvxhB6EP60z2ghLImZPhH8g9I7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