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

    <tr>
        <th>Summary</th>
        <td>
            [x86_64] llc -O1 mishandles zeroext function argument attribute
        </td>
    </tr>

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

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

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

<pre>
    [Demo on Compiler Explorer](https://godbolt.org/z/1zcYhPzdv)
The following C code compiles to the (reduced) IR below.
```c
#include <stdint.h>
int32_t func(uint8_t  p_3) { 
    return p_3;
}
```
Reduced IR:
```llvm
define i32 @func(i8 zeroext %0) {
  %2 = alloca i8, align 1
  store i8 %0, ptr %2, align 1
  %3 = load i8, ptr %2, align 1
  %4 = zext i8 %3 to i32
  ret i32 %4
}
```
llc -O0 properly handles zeroext (and the zext instruction):
```asm
func: # @func
        mov     al, dil
        mov     byte ptr [rsp - 1], al
        movzx   eax, byte ptr [rsp - 1]
 ret
```
Yet llc -O1 seems to only do the zero-extension half-way:
```asm
func:                                   # @func
 mov     eax, edi
        mov     byte ptr [rsp - 1], al
 ret
```
Interestingly, this issue goes away if `zeroext` is removed.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVE1v5CgQ_TX4UuoWBn_1wYeke1rKaVfRXuYUYVO22cVgAU5__PoVtpPRJpnZ1SJLCFfV49WrooT3qjeINckfSX5KxBwG62or_nJt0lh5i4YTjhasgaMdJ6XRwbfrpK1DR_ITYdUQwuQJfyDsTNi5t7KxOuyt6wk73wk7p_f2-_D7Xb4SdiD0ROjDHwNCZ7W2F2V6OEJrJUK7onsIFsKAQFjlUM4tSsIO8PQMDWp72a8IpKDr125nxpVp9SwRCD_6IJUJ-4Hwb6tZmcDZS4BuNi1h1axMqF4CwPTCIzgpH2F1BABwGGZnFht_3ODL04d71-PzShCenmP-__TQ-nVcf0nslEFQnAHJ6MZBVXBHZ_EagLCcbjTeWBCWMyD8BEJr2wpQFWFHEFr1BtI3Jx-sQ1DVBnCEKbgl8gtfwnK-AGor5Ab3a_dscb9HgusVPFZGcfbm4zCsObE8-7VMWrew-43C5OyETt9gEEbGUv9QoBJGLmVfLzQ-uLkNyprYNJ-0FX6TdhGTPwBh_F3b90LGNdrXZRc6ZimV_trc3AKueuSPzk-wg3Rp7ijMp4j7FQBQXKP5J4FriMPwpR7fMcCqSQoecVx63hp9A2k3EZzd4TWg8coaGITudhdx-w9C_Pv6LNWbCFtKKNX_FulnGT-ZgA59UKbXtxgRBuVBeT8j9BY9iIu4geqAFHRrClJQUB4cjvYV5T6RNZcHfhAJ1mlxqMqqzNMqGeq8ygtetUxmKT1w2hSFKEuKbSPbTHZtnqiaUcZTylOWsjyt9p1gtDykJc-ajnUdJRnFUSi9j082Dq5kIVaXtCpookWD2i8DkjGDl5U1YSzOS1fHmF0z955kVCsf_A-UoIJeJuu1Kl6KjOSn96qPyn98A7EgseFBuH4e0QQQITjVzAGT2en6w5hVYZibfWtHws7LqFm33eTsn9gGws4LT0_Yecnj7wAAAP__t9ywRg">