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

    <tr>
        <th>Summary</th>
        <td>
            Expect intrinsics is silently dropped
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            llvm:optimizations
      </td>
    </tr>

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

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

<pre>
    After upgrading some legacy code, I'm seeing that `llvm.expect` intrinsic is silently dropped. This seems to be an outcome of fixing https://github.com/llvm/llvm-project/issues/48680 fix. What happens is that the pass is unable to understand the more complex patterns in unoptimized code.

Here is the typical example (unoptimized code from the frontend):
```
...
  %8 = or i4 0, %k.479.476
  %eq12 = icmp eq i4 %8, -8
  %and13 = and i1 %and, %eq12
  %or14 = or i1 %or9, %and13
  store i1 %or14, i1* %b_0, align 1
  %9 = load i1, i1* %b_0, align 1
  %10 = call i1 @llvm.expect.i1(i1 %9, i1 false)
  store i1 %10, i1* %tmp, align 1
  %11 = load i1, i1* %tmp, align 1
  br i1 %11, label %.if.true.0, label %.if.false.1
```

This pattern is not understood by `LowerExpect` pass and therefore the intrinsic is silently dropped. Before https://github.com/llvm/llvm-project/commit/661cc71a1c50081389d73b2baae02f51df670ba1 we got `SROA` run before `LowerExpect` and therefore the pass saw fully supported:
```
  %8 = or i4 0, %k.479.476
  %eq12 = icmp eq i4 %8, -8
  %and13 = and i1 %and, %eq12
  %or14 = or i1 %or9, %and13
  %9 = call i1 @llvm.expect.i1(i1 %or14, i1 false)
  br i1 %9, label %.if.true.0, label %.if.false.1
```

Tagging @rotateright 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzVVdtu1DAQ_Zrsy6iR7Vw2ecjDQkEgISEBEo_IiSeJwYlT26Fdvh7bm7YLbcVFvCBlk3hy5szFZ7ytFsfm0Ds0sC6D4ULOA1g9ISgceHeETgtM2HN4nbD9BBYxANzIHSQlUerrlOLNgp3zK5CzM3K2sgNpwUqFs1NHEEYvC4oUPozBjDhZcBpaBD6DXl0XoukeenkTuEfnFptkh4S99Ncg3bi2qcf4RQi3PS4Woz-HsOyltHZF61_yqqxIoEnhY0hw5D7ubEMyMWE3IizcRsM681ZhyGOdBRrr-CwiYNIGfdHTovDGo53vTKCYPU4vTk7yG4rYlDQhlwk5nO6v0HvFOJ7zuMiOK8AbHlggYdXPvtAbPUWwf5kdziJhdaj5RFmS7YrLNN1CgacqKkiyS9AGZA4kbIy3fUnzfe1_5RkOryiLUNlNC-BVwAf34HJRnQF94TSLyNACSTfbRh1ozsDa0PwuAXqy1Bs0Et1irQt9vIXQPGAkTdghGNpPMXOu5DADPaOvI7fSXETw77hQEn18w1UMl5-LMg3-1SmL-sQHPVcWQ7sfyZSSH4K6aXkiKH0y0cd92tt20YhWvEUVlqnsU2dWTMkDc8wzpY9K4nSP87RJNIhv1u5WzVoLaI9hRN_oazQv7kY06n_TusE-lB5k-IvJfXZC_vFo-m-TDC9lSbtuTzntCkIqmlW12GctazlHwvqCir7ck5ZTuEYYdDxb3r97G8oGs87-rIjxH5bzsJJYoOXX0K_Kl2DXZdHGoXhquv6nobqbkF-r_X7mHgj-Tov1P5QiH4ZwePuEjHbcK1IOo4OdaDJRZzXfOekUNqeNu1ebfUxuu9Wo5u__BYqSsno3Nr3XVE9zjkVdtTRHxqu28t9oWdCcdeUulmibpHiWMBZJs8N2THMn9ezJWFJc7mTDCGOkZITmeUlImlU9xULkXLS85V3pi8aJS5XGvdBm2JkmZteugw1bJK2z9x-9QP3ZgBgje36-ulGbhlu1i0U0sYLvlOpAww">