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

    <tr>
        <th>Summary</th>
        <td>
            [correlated-propagation] miscompile of sext into zext
        </td>
    </tr>

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

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

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

<pre>
    The following IR is miscompiled by the CorrelatedValuePropagation pass:
```llvm
define i64 @src(i32 %a) {
 %is_a_nonnegative = icmp sgt i32 %a, 1
  %narrow = select i1 %is_a_nonnegative, i32 %a, i32 0
  %max = sext i32 %narrow to i64
  ret i64 %max
}
```
After running the IR through opt with `-passes="correlated-propagation"`, the sext instruction is replaced with zext:
```llvm
define i64 @tgt(i32 %a) {
  %is_a_nonnegative = icmp sgt i32 %a, 1
  %narrow = select i1 %is_a_nonnegative, i32 %a, i32 0
 %max = zext i32 %narrow to i64
  ret i64 %max
}
```
Unfortunately, passing in undef can cause a value mismatch. An example of this is provided here: https://alive2.llvm.org/ce/z/NGqk4Y
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEVE1r3DAQ_TXyZcgiyx-7PviwyeKSSymhLfQUZHlsq5UlVx-7m_z6InubbEsDPRQKBtujmTcz742GOycHjViT4pYUh4QHPxpbo5VCyRCS1nRP9ccRoTdKmZPUA9w_gHQwSSfMNEuFHbRP4EeEO2MtKu6x-8xVwA_WzHzgXhoNM3eOZHtCD4TuSUnXR6njtJo67KVGkGUOJKfOCsJ2MmNAWMEJq4Bsb1fHaJHukT9qozVG9CMCyQ4gxTSDGzy8ht1BegmKBs2tNafF16FC4UGmf0KLcdcY8Zte4Uz8fAE5vyS7YHsTO_jpa9GvDS0xl9a3h984WH_3vUcLNmgdGY5k3j-AH60Jwwhm9nCSfgRS0pvIJDqSHQhj4oXwm_mVbMJYxGV3C85apnbeBrFIIR1YnBUX2K2oz3j2f6-NH_yb2vxfca60ef6X2nzSvbE-aO5RPcWkUYIok9QQdIc9CK5B8OAQOBzj6MfbMXEvxg3sNeCZT7NCMD34UbqowGzNUXbYwYgWSbaH0ft5uSGsIazhSh6RbaIGG2MHwhqBhDXPhDXv333_ln9JujrrqqziCdZpuct31XZbbpOxLtIu76qqzESeFrzKqlSkNC0p0jbvaVEmsmaUZbRgOc1oxbabbEv7boeixSxNEVOSU5y4VC_ZE-lcwLpkFU0TxVtUbtkWjGk8wXIYR644JLaOMTdtGBzJqZLOu1cUL71a1swbU1scrnZK5Ooyud4scibBqvpXlgbpx9BuhJkIa5Z5XV8R9isKT1izVOcIa5bqfwQAAP__WaKCRQ">