<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=http://email.email.llvm.org/c/eJylVMtu2zAQ_Br5QsSQ9fDjoEMSo0WLnpr-ACVS1iYUKZCUVffrO6RlOwmKFEUBwaLo3ZnZ2SVrI07VZzpKzbhmxnfSTuQk85aOxJU6MSG5YA2WSfbIuBCkDzF0kJZrwepRCyXZ1FHTMaORYJHgWC97Y0_MdWZUgmnj2WAlaDwjn2Qbh7DeHLlaMvZFM_Ay-ZP3A6BqqcwUyCbJOn6UjIPeBQppZYwMamQIDFp6bl-kiKza6LAbkhwT1LZI0B6SfAfFyNev08m9zg3SoSXJtnvpBvJnppY3PmT7a0xIQ37cjHVoKQUwWmOvJSXZLkn3SXp__v3RBTI3opJhkNw65g1kQsfokFmfItXET6HippPNS0R75zBpj-_Gk9FQ4GMVzEGog-ynQTbUUtg7RetCrUAT5LBlpps9KLAx1srGB5Vnl4WJDYKaW5x54xUEk4adce9qRXTn3Hm4EiAufCgLRNSj5w3G6Z0hSVagOs_uSDvfmL4mEN49sSR_RFrp5qh1Oj_xU8hGcQzA0RDAi3TUL9pMGjRAv-nWZtQTwbaJlLLSj1a_phayDWQXkIMxYkZINg_nEHa29o88lwgAx4AZerP_gKPm_0TBkvIBLmRCwiK8r7v7v5G_9esye-hMPR4wXg5TNQZjwmyQxhnxdOA-nKHO-8ElORrzCc-BfDfWSzQGH19HRfwb1wesn8Ma7zjMDot8m2Xr5UJUudjlO77go--MrdB13ku3GK2qPoBW6nh53Q3WPMeZvIGXebZJF11VbnldpJtslabNuk1XRbEqyg3fbcqiqNNmu1AcV4ar4BvsiqD5Pbyjnn7xeFyCi-V-8f9iqMrSLEtXq-1qkxd5tmylqItmy8uyWPNitUUzZc9JLQPO0tjDwlYREi1w-FOR8-72J3eODrhAZu2zb7NcT17J6vvlsL27DubbNHRvvnaYaW-X9SIqr6Ls3w-r7DU>53270</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Readonly operand bundle preventing removal of dead call
        </td>
    </tr>

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

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

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

<pre>
    Given an otherwise trivially dead call, adding an operand bundle which only reads memory should not prevent it's removal.  In the example below, we have a case where the callee being marked readnone behaves differently than when the callee is marked readonly.  (Despite the fact that readonly is all that's needed for removal.)

The issue appears to be caused by the way we check for operand bundle interactions at call sites.  Specifically, when we disallow readnone (correct), we do not use readnone on the callee to infer the readonly fact which is not disallowed (imprecise)

$ opt -instcombine -S < %s
```
declare void @unknown() readnone nounwind willreturn

define void @good() {
  call void @unknown()
  ret void
}

define void @bad() {
  call void @unknown() [ "deopt"() ]
  ret void
}
```

This bug was found when investigating https://github.com/JuliaLang/julia/issues/38226.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVVNtunDAQ_Rr2xcqK5bJLHnhIsmrVqk9tf8BgA5MYG9lm6fbre-y9JVGVqhICe5iZc-bM2I0Rx_ozHaRmXDPjB2kXcpJ5SwfiSh2ZkFywFsske2JcCNJ9dJ2k5VqwZtZCSbYM1A7MaARYBDg2ytHYI3ODmZVg2ng2WQkYz8gn2c7BbTQHrtaMfdEMuEz-4uOEVI1UZglgi2QDP0jGAe8ChLQyegY2MjgGLiO3L1JEVG10sIYgxwR1HQK0ByU_gDHi9etwcq9jA3VwSbJqL91E_oTU8daHaH_1CWGIj8ZYh5ZSIEdn7LWkJLtP0n2SPpzeP4cA5mZUMk2SW8e8AU3wmB0im2OEWvgxVNwOsn2J2d4pTNpj33oyGgx8rII5EHWg_WOSLXUUbMcoXagV2QQ5mMxykwcFtsZa2frA8qSyMLFBYHPzM2-0AmHSkDParlJEdU6dhyohxQUPZQGIRvS8xTi9EyTJClTn2R1p51szNgTAux8syZ8QVrqz1zY9P3ErZKs4BuBgCMmLdNYv2iwaMMh-463NrBeCbAspZaWfrX4NLWQXwC5JemPEOUOyezy5sJO0f8W5eCBxdDin3u0_wGj4f0GwpHyECpmQkAjfq3X_L_C3el1mD51p5h7j5TBVcxAmzAZpnBFPPffhDA3eTy7J0ZhPeHryw9ys0Rhsvs6K-Deue6yfwxrfOMwOi7zKsu16Jepc3Of3fOXJK1l_v8zHuwk-XwAB8HxSmOlu98tqtqr-gIlSh8vnbrLmOY7wjUuZZ7t0NdRplRdZvisr3m7LKm3abZqVleC7bdNVoihWiuOGcTVkhroxaf4AqWmk3zyeriB6uV9RnaVZlm421WaXF3m27qRoirbiZVlsebGp0Dk5clLrkGRtbL-ydWQHvR1-KnLe3X5y56jHbXFGhhp8lBcwPvvB2PpsXMWq6ljSH5dx1zo">