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

    <tr>
        <th>Summary</th>
        <td>
            [DebugInfo][SpeculativeExecution] Hoisting an in-branch instruction without dropping its debug location
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            debuginfo,
            new issue,
            llvm:transforms
      </td>
    </tr>

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

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

<pre>
    [**SpeculativeExecution-L330**](https://github.com/llvm/llvm-project/blob/9b8c2fae38bcff0b16d996ee002ff1e989fa23ea/llvm/lib/Transforms/Scalar/SpeculativeExecution.cpp#L330)

In function `considerHoistingFromTo`, instructions in one of the `else` or `then` branch will be hoisted out of the branch, but no debug location dropping is performed. (`considerHoistingFromTo` is called in function [`runOnBasicBlock`](https://github.com/llvm/llvm-project/blob/9b8c2fae38bcff0b16d996ee002ff1e989fa23ea/llvm/lib/Transforms/Scalar/SpeculativeExecution.cpp#L169))

```cpp
if (!NotHoisted.count(&*Current)) {
 Current->moveBefore(ToBlock.getTerminator());
}
```

godbolt: https://godbolt.org/z/E9r3bTnYb (the hoisted add instruction)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUVE1v5DYM_TWci5CBTMVfBx9mMjF2gaI97Fx6lCXaVquRDElO2v76QnbSTINFgR4XMGyLIqlH8j3JGM3kiDooz1BeDnJNsw_dafFqJhcPg9d_bnt4Ajx9W0itVibzQs9_kFqT8e7hJyH4vg3lBbCZU1oiiBNgD9hPJs3rcFT-Bthb-_L-eViC_41UAuwH6wfAvh0ahaMk0QxqHPlQVLptKyLOcRwLapt2lChI3uUxOe4apIujD7cI2H9T0sqQf74D9aiWBVDsgFvgF-Cn_f3VsXF1KjsxqLjyLhpN4Ys3MRk39cHfrh4qDvjEjIsprJtvZMYx74j5kaWZcijZSFBx5kNepZlcXg1BOjWzV2MtG4jNOS9p5tf0Hrp75PzDmpjzTNOwTsx6JTdUOvhlMW5iJrKFQq6X9JEBNv-FN3sraS3pjPSjxPIMFQ-r-8WdZTTqbL36PZf3gwywqNo8wH_PMOPfnuy0Wcy49QeLn336srf8qPzq0matAE9PawiU1zkZg_q8B7I3-wOI55t_oTONPhBgc_Vbq44TpSuFm3Ey-bBl29CIt3ioL58w3QOdvB68TSBO7FOr942jDxNg_xdg_9wGMVzdr0MuJNPknTlS63siArYH3QndilYeqCvqom2aStT8MHeiFiVqVTclb1Dpgj9q3pJqhNSqqbE6mA45PvKaI8cCS37UVI9FoWuBw2OrZAOPnG7S2GMeW0Z3MDGu1LW1qMuDlQPZuF8SuLHWuNEDIuATIDp6ZZv7P5Zt-OKU7saO-e4J3carYZ0iPHJrYoofJyaT7HZLXfIJX_MJ5QXK8_doAuWFvUuBSceMe3gT4F3L2KtJcxbgh7JS_KS6wxps97_lsFWbubz356XDvwMAAP__6sK5Aw">