<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/55722>55722</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
InstCombine swaps inbounds geps originating OOB pointer
</td>
</tr>
<tr>
<th>Labels</th>
<td>
miscompilation,
llvm:instcombine
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
nikic
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
nunoplopes
</td>
</tr>
</table>
<pre>
InstCombine transforms this:
```llvm
%struct.A = type { [123 x i8], i32 }
define ptr @struct2(ptr %p) {
%1 = getelementptr inbounds %struct.A, ptr %p, i64 0, i32 1
%2 = getelementptr inbounds i8, ptr %1, i64 -128
ret ptr %2
}
```
into:
```llvm
define nonnull ptr @struct2(ptr readnone %p) {
%1 = getelementptr inbounds %struct.A, ptr %p, i64 -1, i32 1
ret ptr %1
}
```
The transformation seems to have been introduced in LLVM 14.
https://alive2.llvm.org/ce/z/8KGF2j
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy1U02PmzAQ_TXmYgXhIbDkwCHZaKuqW-2l6t3ABLw1NrJN2u2v7_CRTVZbrXqpZPwxY9689xgq27yUn40P97avlEEenDT-ZF3veeiUZ-meJUeW7FmeLEPrc7-GIPPBjXWI95ylRx5eBuTs7sBZdhCQ8l9cFSw7MrjnKgXKHNf35rnB01RvCI6zbbIAAYNiDkA2MNhNYMtlPoXEXKXFgBp7NGG6qUxlR9N4fkNmKnhFoeL5licXFuIGED4CJO5XHHHB2QgoLggOwyUPq7JXiRe3bhUrE-xHfq6OGGvMqPXfnXEoG7qA_8GijXjn0Y1C8S8Kv3U3DSSDsoZ7xKmVLO_kGXmFaIhQcLYZa2xoyx8fv3_lYhsvCF0Iw9x08EBDanVGiCeLYutaitRI0296ii-fHuA5asq02aU7GQUVNL7pZP9TDv6qvkU6WadaZYiZafnT04EPlsigi0any7elWxW6sYpr29Nh_kbLshmcfcY60FF5P6KnTZbdAURdiQLxrs5FU2eFbCTKXZLlhUAJFSZVnkZaVqh9Sf8HA-iVJ_RB6dkoCkz20zIXS6lbfKgXKVMuO0aqhAQgySAXRZokIhaEX--yQqQnURTYULdgL5V-NSxy5cy5GltPSa188Nek9F61BnHlY9QPVa-l5Bg660ozGjtoO6CPZrHlrPQPGWRBKA">