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

    <tr>
        <th>Summary</th>
        <td>
            Missed optimization for one-hot encoding
        </td>
    </tr>

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

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

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

<pre>
    Alive2: https://alive2.llvm.org/ce/z/EeCsH6
```
define i32 @src(i32 noundef %x) {
  %cmp3 = icmp eq i32 %x, 3
  %bit3 = select i1 %cmp3, i32 8, i32 0
  %cmp2 = icmp eq i32 %x, 2
  %bit2 = select i1 %cmp2, i32 4, i32 0
  %or23 = or disjoint i32 %bit3, %bit2
  %cmp1 = icmp eq i32 %x, 1
  %bit1 = select i1 %cmp1, i32 2, i32 0
  %or123 = or disjoint i32 %or23, %bit1
  %cmp0 = icmp eq i32 %x, 0
  %bit0 = zext i1 %cmp0 to i32
  %or0123 = or disjoint i32 %or123, %bit0
  ret i32 %or0123
}

define i32 @tgt(i32 %x) {
  %cmp = icmp ult i32 %x, 4
  %shl = shl i32 1, %x
  %val = select i1 %cmp, i32 %shl, i32 0
 ret i32 %val
}
```

I found this pattern in some verilator-generated code.

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx8lN-O4iAUxp-G3hANnDr9c9ELZ9xm92IfooVTy4SCC-g6Pv2Gts60E93EKCXf9_E7cnoa79XRIFbk5ZUAyCCut4-_BIC8HJLmHHrrqnkzaa38qPZaXRBIuqd9CCdP0j2BmkDdjPtbrS_D1rojgVoggfpGoP6Bb_5nRtiBsD3J2PwZHyV2yiBVKVCyY94JAkV8MPZsJHaUwMuVQElJ_joZaNwSwymlJD1QJYYTxT-Tf5S-0XQhbFWYhB41ikAVv9ujMrqK-4Kt8-FpPqzz4WE-3GN3j_KtgwnLOiqVf7fKhPsZETl65vQ1FX9KxddU_CEVv8PAYyr-HCsif2HxNRZ7isXWWJPwhtcFFKPBRs-KhP0XhS9ZPo9wuJDEgLnj8sO8eNBx4RjmjnvaaV-1nXVYFbdbCH2vp7-816OGz4DXhebS6IfXcr-MKeb71SzKujT6e03r12n6_kW7-PrQ0CtPT00I6AxVhno7IL2gU7oJ1m2OaNA1ASUVVuJ28iaySmWZlk2CFc95meVZAZD0lQTosq7IctGBYF2xa-KyzLK84AJbmagKGOxYBiXPGAPYdsgxL_MMuyItZdaSHcOhUfpzRiTK-zNWZc6zItFNi9rPYygqSLpXxgdhh1YZjBMJ3gjAoLxHubGnoAZ1a4KyZp5Wroq2TXs-erJjWvngv44KKmisfo9mujTTzjpqDW56GygaYaUyx-TsdLWeb0cV-nO7FXYgUI9808_m5Ow7ikCgHsvxBOqpoksF_wIAAP__-79_bA">