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

    <tr>
        <th>Summary</th>
        <td>
            LLVM fails to optimize out an arithmetic right shift of an I64 by 63 followed by a fshl of an I64 by 1
        </td>
    </tr>

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

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

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

<pre>
    LLVM fails to optimize out the `@llvm.fshl.i64(i64 %shifted_hi, i64 %1, i64 1)` below (as all of the bits of `%shifted_hi` are known to be equal to the MSB of `%1` in the code below):
```
define { i64, i64 } @src(i64 %0, i64 %1) local_unnamed_addr #0 {
  %shifted_hi = ashr i64 %1, 63
  ; shifted_hi = ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
  ; %1 = sxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 %shifted_lo = tail call i64 @llvm.fshl.i64(i64 %shifted_hi, i64 %1, i64 1)
  ; %shifted_lo = ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
 %result0 = insertvalue { i64, i64 } poison, i64 %shifted_lo, 0
  %result1 = insertvalue { i64, i64 } %result0, i64 %shifted_hi, 1
  ret { i64, i64 } %result1
}

define { i64, i64 } @tgt(i64 %0, i64 %1) local_unnamed_addr #0 {
  %shr_result = ashr i64 %1, 63
  ; shifted_hi = ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
  ; %1 = sxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 %result0 = insertvalue { i64, i64 } poison, i64 %shr_result, 0
  %result1 = insertvalue { i64, i64 } %result0, i64 %shr_result, 1
  ret { i64, i64 } %result1
}


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

The above snippet run through alive-tv and opt can be found at https://alive2.llvm.org/ce/z/dew45A.

`%shifted_lo = tail call i64 @llvm.fshl.i64(i64 %shifted_hi, i64 %1, i64 1)` above can be optimized down to `%shifted_hi` in the case where `%shifted_hi` is equal to the result of `ashr i64 %1, 63` as all of the bits of `%shifted_hi` are equal to the MSB of `%1`.

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcVk2PqzYU_TXO5moiMN8LFjONIlV6b9Wq25HBl-D3jE39ETrv11cGMglP0bRVZlUUEQOXc--5PviYWStOCrEm2QvJDjvmXa9N_U33apTMObtrNH-rv3z54yt0TEgLToMenRjEDwTtHbgegeQRSSMpz8O-s73cizwltBR5CoRmthedQ_7aC0J_gfVmfBnHhFYkj6BBqScgtGQWmJSguxm5Ec6GcciwgcojYAbhu9KTCjU1CPinZzKMw4tff3u5vheHcKHmB63muGQLmZNnEh1I9Bzilt98ybETCoEULzBzWesuDkDSyJr2yi7akqpA6pbJV68UG5C_Ms4NEJpEAWvBhm1TgCQHYLY3m9bkyXtw8gI_RdsHj1vokHAB_euxYwW94Sb1DOyYkNCGOZ0JPqKTbd0_5fmkrhCaGbReumhGFcqicWcm_V05jFpYrW4KvhYVbkY3U76gxv8G9VrDHeSlP_EF2aD7EGINJMVhHfyzwN3JfYLAzetSwP9P4I_p49KXz9fHLfKD-ljOzDkjGu_QrlOcHGaswVs3Gn0yaC0o3RlEUNpg640NI_umWlDaq0koDpOQ0qDzRsGAgzZvhJZKKwxi8pNjjQwkD_dSxu8pVVCdbFj7_Zpwm8aO2HrJFryPcl6pbhf95fx7j8AafUawSowjOjA-OIfR_tQDk-KMT-4MTPHgg9AyFbyn015xYA5650YbbIUeCT3O4XQ_r3janAg9tkjo8QehR45Tmj3vN03fmNznL5_BM2dma9EXH-fAVxe9Z7MX32QWYerR4P0ou_Xf9dtfLPje1x-K-U9W_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