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

    <tr>
        <th>Summary</th>
        <td>
            instcombine removes a select, making code more poisonous
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            miscompilation,
            llvm:instcombine
      </td>
    </tr>

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

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

<pre>
    https://alive2.llvm.org/ce/z/c__jy8

this function:
```llvm
define i32 @f(i32 %0) {
  %2 = sub nuw i32 -2, %0
  %3 = tail call i32 @llvm.ctlz.i32(i32 %2, i1 false)
  %4 = sub i32 32, %3
  %5 = shl i32 1, %4
  %6 = icmp ult i32 %0, -2
  %7 = select i1 %6, i32 %5, i32 1
  ret i32 %7
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.ctlz.i32(i32, i1 immarg) #0

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
```

is getting rewritten to not have the select, but the select was blocking a poison value. the bad thing happens when -1 is passed as an argument.

```llvm
define i32 @f(i32 %0) {
  %2 = sub nuw i32 -2, %0
  %3 = tail call range(i32 0, 33) i32 @llvm.ctlz.i32(i32 %2, i1 false)
  %4 = sub nsw i32 0, %3
  %5 = and i32 %4, 31
  %6 = shl nuw i32 1, %5
  ret i32 %6
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.ctlz.i32(i32, i1 immarg) #0

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
```

cc @nunoplopes 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsVU2P4ygQ_TX4UuoIgx3HBx-6p5W_MQJcsZnBYPGRqOfXr8BJx_t52Zb2slIUI3j16lUVT4gQ9GQRB9K-kfa9EinOzg8eJ5x9Jd34McwxroHwV8LOhJ2F0VdkB2Ouy8H5ibCzQsLOv_Li-_cfHydC3wl93f7jrANcklVRO5sptrMj3X6ZZNsa8aItguYMSEMvhJ3KkrWUsB5I97bBIG8xIPwdQpJg062EvDDCvm3oJ4wXWBTagBLGPLiLcBXNr4Pm7JmnMOgaLsIEJKzfETWf-TKWP3LxHaTdIPOWpb4jmh3iWBBaLSskE-FZ3bes_onrNiY0qGLWk0OLtC2gfazrR4zHT7bu3t7ufT8Dwt_gfB8BvMbo8yzButwUKdRPsO7iEcG68GEVWJfsTdsRwooqGRGFNAg3bYzHmLyFBRfnPwg7WWefnRpRGeHxH7p8b7BeFpGvTQ-EcboXKmL0WqaIoRyVRpDu7QulwrM1jyu4F6ADTBijthN4vHkdI1qIDqyLMIsrQpzxPppcjExxtwM3EUAap37meAGr08FZuAqT8FBwUowQ53w6i3VFG-A2o4WXGnSAVYSAI4gAwoLwU1rQxsPv5vifuMYLO-GduNxWzjP3F5jJhk0G_Vs_CTs-rnZTUtd_MlS23KOeh-3av7DG8X9r_CtrKJWl22TdatyKAapx4GPPe1HhUHd1y2lPeVfNw6jEKBrKTh2VXDYn2fIRWy5pXTNKL6rSA6OsoW1NKWt42x34qKTq1eV4qTvJekkaiovQ5vONqXQICYe-PvZ1ZYREE8pzxdiig3LLqo0oDwzLnSSMFYfwV21DVG6ROlfI8uvmh3z0ItMU8iR0iOGZJepocNgFgcfFXTGA2Ll-EcXgyo0Ii_N4N7pLoUre_OGxnHSckzwotxB2Lqq2z8vq3Y9CeC61BcLOpbzfAgAA__9Kxjdg">