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

    <tr>
        <th>Summary</th>
        <td>
            [InstCombine] Infer exact for lshr by cttz
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            llvm:instcombine,
            missed-optimization
      </td>
    </tr>

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

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

<pre>
    From https://github.com/rust-lang/rust/issues/138497:

```llvm
define i8 @src(i8 %x) {
  %cttz = call i8 @llvm.cttz.i8(i8 %x, i1 false)
  %lshr = lshr i8 %x, %cttz
  ret i8 %lshr
}

define i8 @tgt(i8 %x) {
  %cttz = call i8 @llvm.cttz.i8(i8 %x, i1 false)
  %lshr = lshr exact i8 %x, %cttz
 ret i8 %lshr
}
```
https://alive2.llvm.org/ce/z/KFemjy

This then allows folding `icmp eq %lshr, 0`.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy8k81unDAQx59muFi7MsPHwoHDZldIUa99AWMPMKnBW2zSJE9fmd1Nk0rpsZIlBs3Xz_7PKO95mIkaKB6gOCdqDaNbmpl_sE46Z16bdnGTGEO4eMiOgC1gO3AY126v3QTYLqsPO6vm4WYDtuz9Sh6wTbMqrw8xT26nlNdj7fME8mio55kEVwJy6RcNWEUbixfAWsDhAeRRxH8dwpuA7Cy0svYWH2vso2PP1cfEk-BU9Mp6AqzvBawfl63AZnyIvRXf4hYKN1eMiryH8xX8E2gYwv8CpRelwxe4X9He3xjk8bNqyvIz4X7DcUuUSxNg-wbYfmtpenq93vX7yF6EkWahrHW_vOidNTwPAkrJeroI-vneFE8ittonpslMndUqoSY95CgzWeZpMjZVVpmiJ6XSviproylF1H0lTYfG1Fom3KDEQmZpIWvMZbqXSpm-U4WqyrLCkiCXNCm279zJNl1NmqV5nidWdWT9Nr2I21hlR5590G7qeCZABDwB4sTek9m5S-CJ31RgN0dfcU6WJqbtunXwUSz2wf_pFTjYbTceZx9Ot5rFWTzOPd3l6d1yVat7FVGcZF1s84-F2Sivn91lcU-k_9qZ7WLPDf4OAAD__919E8A">